mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 03:17:39 -02:30
Address PR review comments.
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { shallow, mount } from 'enzyme';
|
import { shallow, mount } from 'enzyme';
|
||||||
import App from '../src/App';
|
import App from '../src/App';
|
||||||
import api from '../src/api';
|
import api from '../src/api';
|
||||||
import * as constant from '../src/endpoints';
|
import { API_LOGOUT } from '../src/endpoints';
|
||||||
|
|
||||||
import Dashboard from '../src/pages/Dashboard';
|
import Dashboard from '../src/pages/Dashboard';
|
||||||
import Login from '../src/pages/Login';
|
import Login from '../src/pages/Login';
|
||||||
@@ -66,13 +66,13 @@ describe('<App />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('api.logout called from logout button', async () => {
|
test('api.logout called from logout button', async () => {
|
||||||
api.BaseGet = jest.fn().mockImplementation(() => Promise.resolve({}));
|
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
const appWrapper = mount(<App />);
|
const appWrapper = mount(<App />);
|
||||||
const logoutButton = appWrapper.find('LogoutButton');
|
const logoutButton = appWrapper.find('LogoutButton');
|
||||||
logoutButton.props().onDevLogout();
|
logoutButton.props().onDevLogout();
|
||||||
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
||||||
expect(api.BaseGet).toHaveBeenCalledTimes(1);
|
expect(api.get).toHaveBeenCalledTimes(1);
|
||||||
expect(api.BaseGet).toHaveBeenCalledWith(constant.API_LOGOUT);
|
expect(api.get).toHaveBeenCalledWith(API_LOGOUT);
|
||||||
await asyncFlush();
|
await asyncFlush();
|
||||||
expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
||||||
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import mockAxios from 'axios';
|
import mockAxios from 'axios';
|
||||||
import APIClient from '../src/api';
|
import APIClient from '../src/api';
|
||||||
import * as constant from '../src/endpoints';
|
import * as endpoints from '../src/endpoints';
|
||||||
|
|
||||||
const CSRF_COOKIE_NAME = 'csrftoken';
|
const CSRF_COOKIE_NAME = 'csrftoken';
|
||||||
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
||||||
@@ -45,9 +45,9 @@ describe('APIClient (api.js)', () => {
|
|||||||
APIClient.setCookie = jest.fn();
|
APIClient.setCookie = jest.fn();
|
||||||
APIClient.login(un, pw, next).then(() => {
|
APIClient.login(un, pw, next).then(() => {
|
||||||
expect(mockAxios.get).toHaveBeenCalledTimes(1);
|
expect(mockAxios.get).toHaveBeenCalledTimes(1);
|
||||||
expect(mockAxios.get).toHaveBeenCalledWith(constant.API_LOGIN, { headers });
|
expect(mockAxios.get).toHaveBeenCalledWith(endpoints.API_LOGIN, { headers });
|
||||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -60,7 +60,7 @@ describe('APIClient (api.js)', () => {
|
|||||||
const data = `username=${encodeURIComponent(un)}&password=${encodeURIComponent(pw)}&next=${encodeURIComponent(next)}`;
|
const data = `username=${encodeURIComponent(un)}&password=${encodeURIComponent(pw)}&next=${encodeURIComponent(next)}`;
|
||||||
APIClient.login(un, pw, next).then(() => {
|
APIClient.login(un, pw, next).then(() => {
|
||||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -69,11 +69,11 @@ describe('APIClient (api.js)', () => {
|
|||||||
const un = 'foo';
|
const un = 'foo';
|
||||||
const pw = 'bar';
|
const pw = 'bar';
|
||||||
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
||||||
const data = `username=${un}&password=${pw}&next=${encodeURIComponent(constant.API_CONFIG)}`;
|
const data = `username=${un}&password=${pw}&next=${encodeURIComponent(endpoints.API_CONFIG)}`;
|
||||||
APIClient.setCookie = jest.fn();
|
APIClient.setCookie = jest.fn();
|
||||||
APIClient.login(un, pw).then(() => {
|
APIClient.login(un, pw).then(() => {
|
||||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onDevLogout = async () => {
|
onDevLogout = async () => {
|
||||||
await api.BaseGet(API_LOGOUT);
|
await api.get(API_LOGOUT);
|
||||||
this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' });
|
this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/api.js
10
src/api.js
@@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import * as constant from './endpoints';
|
import * as endpoints from './endpoints';
|
||||||
|
|
||||||
const CSRF_COOKIE_NAME = 'csrftoken';
|
const CSRF_COOKIE_NAME = 'csrftoken';
|
||||||
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
||||||
@@ -32,7 +32,7 @@ class APIClient {
|
|||||||
return authenticated;
|
return authenticated;
|
||||||
}
|
}
|
||||||
|
|
||||||
async login (username, password, redirect = constant.API_CONFIG) {
|
async login (username, password, redirect = endpoints.API_CONFIG) {
|
||||||
const un = encodeURIComponent(username);
|
const un = encodeURIComponent(username);
|
||||||
const pw = encodeURIComponent(password);
|
const pw = encodeURIComponent(password);
|
||||||
const next = encodeURIComponent(redirect);
|
const next = encodeURIComponent(redirect);
|
||||||
@@ -40,11 +40,11 @@ class APIClient {
|
|||||||
const data = `username=${un}&password=${pw}&next=${next}`;
|
const data = `username=${un}&password=${pw}&next=${next}`;
|
||||||
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
||||||
|
|
||||||
await this.http.get(constant.API_LOGIN, { headers });
|
await this.http.get(endpoints.API_LOGIN, { headers });
|
||||||
await this.http.post(constant.API_LOGIN, data, { headers });
|
await this.http.post(endpoints.API_LOGIN, data, { headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseGet = (endpoint) => this.http.get(endpoint);
|
get = (endpoint) => this.http.get(endpoint);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import './app.scss';
|
|||||||
const el = document.getElementById('app');
|
const el = document.getElementById('app');
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const { custom_logo, custom_login_info } = await api.BaseGet(API_ROOT);
|
const { custom_logo, custom_login_info } = await api.get(API_ROOT);
|
||||||
render(<App logo={custom_logo} loginInfo={custom_login_info} />, el);
|
render(<App logo={custom_logo} loginInfo={custom_login_info} />, el);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Organizations extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount () {
|
async componentDidMount () {
|
||||||
const { data } = await api.BaseGet(API_ORGANIZATIONS);
|
const { data } = await api.get(API_ORGANIZATIONS);
|
||||||
this.setState({ organizations: data.results });
|
this.setState({ organizations: data.results });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user