mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
Merge pull request #287 from jakemcdermott/more-big-pr-fixups
misc cleanup from big prs
This commit is contained in:
commit
059fa9001a
10
src/App.jsx
10
src/App.jsx
@ -48,7 +48,7 @@ class App extends Component {
|
||||
version: null,
|
||||
isAboutModalOpen: false,
|
||||
isNavOpen,
|
||||
configError: false,
|
||||
hasConfigError: false,
|
||||
};
|
||||
|
||||
this.handleLogout = this.handleLogout.bind(this);
|
||||
@ -81,7 +81,7 @@ class App extends Component {
|
||||
}
|
||||
|
||||
handleConfigErrorClose () {
|
||||
this.setState({ configError: false });
|
||||
this.setState({ hasConfigError: false });
|
||||
}
|
||||
|
||||
async loadConfig () {
|
||||
@ -92,7 +92,7 @@ class App extends Component {
|
||||
|
||||
this.setState({ ansible_version, custom_virtualenvs, version, me });
|
||||
} catch (err) {
|
||||
this.setState({ configError: true });
|
||||
this.setState({ hasConfigError: true });
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ class App extends Component {
|
||||
isNavOpen,
|
||||
me,
|
||||
version,
|
||||
configError,
|
||||
hasConfigError,
|
||||
} = this.state;
|
||||
const {
|
||||
i18n,
|
||||
@ -170,7 +170,7 @@ class App extends Component {
|
||||
onClose={this.handleAboutClose}
|
||||
/>
|
||||
<AlertModal
|
||||
isOpen={configError}
|
||||
isOpen={hasConfigError}
|
||||
variant="danger"
|
||||
title={i18n._(t`Error!`)}
|
||||
onClose={this.handleConfigErrorClose}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import React from 'react';
|
||||
|
||||
import { mountWithContexts, waitForElement } from '../testUtils/enzymeHelpers';
|
||||
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||
import { ConfigAPI, MeAPI, RootAPI } from '@api';
|
||||
import { asyncFlush } from '../jest.setup';
|
||||
|
||||
import App from './App';
|
||||
import { ConfigAPI, MeAPI, RootAPI } from './api';
|
||||
|
||||
jest.mock('./api');
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Applications from './Applications';
|
||||
|
||||
describe('<Applications />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import AuthSettings from './AuthSettings';
|
||||
|
||||
describe('<AuthSettings />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Credentials from './Credentials';
|
||||
|
||||
describe('<Credentials />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import CredentialTypes from './CredentialTypes';
|
||||
|
||||
describe('<CredentialTypes />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Dashboard from './Dashboard';
|
||||
|
||||
describe('<Dashboard />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import InstanceGroups from './InstanceGroups';
|
||||
|
||||
describe('<InstanceGroups />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Inventories from './Inventories';
|
||||
|
||||
describe('<Inventories />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import InventoryScripts from './InventoryScripts';
|
||||
|
||||
describe('<InventoryScripts />', () => {
|
||||
|
@ -32,7 +32,7 @@ class JobList extends Component {
|
||||
this.state = {
|
||||
hasContentLoading: true,
|
||||
hasContentError: false,
|
||||
deletionError: false,
|
||||
hasDeletionError: false,
|
||||
selected: [],
|
||||
jobs: [],
|
||||
itemCount: 0,
|
||||
@ -56,7 +56,7 @@ class JobList extends Component {
|
||||
}
|
||||
|
||||
handleDeleteErrorClose () {
|
||||
this.setState({ deletionError: false });
|
||||
this.setState({ hasDeletionError: false });
|
||||
}
|
||||
|
||||
handleSelectAll (isSelected) {
|
||||
@ -76,11 +76,11 @@ class JobList extends Component {
|
||||
|
||||
async handleDelete () {
|
||||
const { selected } = this.state;
|
||||
this.setState({ hasContentLoading: true, deletionError: false });
|
||||
this.setState({ hasContentLoading: true, hasDeletionError: false });
|
||||
try {
|
||||
await Promise.all(selected.map(({ id }) => UnifiedJobsAPI.destroy(id)));
|
||||
} catch (err) {
|
||||
this.setState({ deletionError: true });
|
||||
this.setState({ hasDeletionError: true });
|
||||
} finally {
|
||||
await this.loadJobs();
|
||||
}
|
||||
@ -109,7 +109,7 @@ class JobList extends Component {
|
||||
const {
|
||||
hasContentError,
|
||||
hasContentLoading,
|
||||
deletionError,
|
||||
hasDeletionError,
|
||||
jobs,
|
||||
itemCount,
|
||||
selected,
|
||||
@ -166,7 +166,7 @@ class JobList extends Component {
|
||||
/>
|
||||
</Card>
|
||||
<AlertModal
|
||||
isOpen={deletionError}
|
||||
isOpen={hasDeletionError}
|
||||
variant="danger"
|
||||
title={i18n._(t`Error!`)}
|
||||
onClose={this.handleDeleteErrorClose}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import JobsSettings from './JobsSettings';
|
||||
|
||||
describe('<JobsSettings />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import License from './License';
|
||||
|
||||
describe('<License />', () => {
|
||||
|
@ -25,8 +25,8 @@ class AWXLogin extends Component {
|
||||
this.state = {
|
||||
username: '',
|
||||
password: '',
|
||||
authenticationError: false,
|
||||
validationError: false,
|
||||
hasAuthError: false,
|
||||
hasValidationError: false,
|
||||
isAuthenticating: false,
|
||||
isLoading: true,
|
||||
logo: null,
|
||||
@ -66,16 +66,16 @@ class AWXLogin extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ authenticationError: false, isAuthenticating: true });
|
||||
this.setState({ hasAuthError: false, isAuthenticating: true });
|
||||
try {
|
||||
// note: if authentication is successful, the appropriate cookie will be set automatically
|
||||
// and isAuthenticated() (the source of truth) will start returning true.
|
||||
await RootAPI.login(username, password);
|
||||
} catch (err) {
|
||||
if (err && err.response && err.response.status === 401) {
|
||||
this.setState({ validationError: true });
|
||||
this.setState({ hasValidationError: true });
|
||||
} else {
|
||||
this.setState({ authenticationError: true });
|
||||
this.setState({ hasAuthError: true });
|
||||
}
|
||||
} finally {
|
||||
this.setState({ isAuthenticating: false });
|
||||
@ -83,17 +83,17 @@ class AWXLogin extends Component {
|
||||
}
|
||||
|
||||
handleChangeUsername (value) {
|
||||
this.setState({ username: value, validationError: false });
|
||||
this.setState({ username: value, hasValidationError: false });
|
||||
}
|
||||
|
||||
handleChangePassword (value) {
|
||||
this.setState({ password: value, validationError: false });
|
||||
this.setState({ password: value, hasValidationError: false });
|
||||
}
|
||||
|
||||
render () {
|
||||
const {
|
||||
authenticationError,
|
||||
validationError,
|
||||
hasAuthError,
|
||||
hasValidationError,
|
||||
username,
|
||||
password,
|
||||
isLoading,
|
||||
@ -115,7 +115,7 @@ class AWXLogin extends Component {
|
||||
}
|
||||
|
||||
let helperText;
|
||||
if (validationError) {
|
||||
if (hasValidationError) {
|
||||
helperText = i18n._(t`Invalid username or password. Please try again.`);
|
||||
} else {
|
||||
helperText = i18n._(t`There was a problem signing in. Please try again.`);
|
||||
@ -129,15 +129,15 @@ class AWXLogin extends Component {
|
||||
textContent={loginInfo}
|
||||
>
|
||||
<LoginForm
|
||||
className={(authenticationError || validationError) ? 'pf-m-error' : ''}
|
||||
className={(hasAuthError || hasValidationError) ? 'pf-m-error' : ''}
|
||||
usernameLabel={i18n._(t`Username`)}
|
||||
passwordLabel={i18n._(t`Password`)}
|
||||
showHelperText={(authenticationError || validationError)}
|
||||
showHelperText={(hasAuthError || hasValidationError)}
|
||||
helperText={helperText}
|
||||
usernameValue={username}
|
||||
passwordValue={password}
|
||||
isValidUsername={!validationError}
|
||||
isValidPassword={!validationError}
|
||||
isValidUsername={!hasValidationError}
|
||||
isValidPassword={!hasValidationError}
|
||||
onChangeUsername={this.handleChangeUsername}
|
||||
onChangePassword={this.handleChangePassword}
|
||||
onLoginButtonClick={this.handleLoginButtonClick}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts, waitForElement } from '../../../testUtils/enzymeHelpers';
|
||||
import AWXLogin from './Login';
|
||||
import { RootAPI } from '../../api';
|
||||
|
||||
jest.mock('../../api');
|
||||
import { RootAPI } from '@api';
|
||||
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import AWXLogin from './Login';
|
||||
|
||||
jest.mock('@api');
|
||||
|
||||
describe('<Login />', () => {
|
||||
async function findChildren (wrapper) {
|
||||
@ -60,7 +62,7 @@ describe('<Login />', () => {
|
||||
} = await findChildren(loginWrapper);
|
||||
expect(usernameInput.props().value).toBe('');
|
||||
expect(passwordInput.props().value).toBe('');
|
||||
expect(awxLogin.state('validationError')).toBe(false);
|
||||
expect(awxLogin.state('hasValidationError')).toBe(false);
|
||||
expect(submitButton.props().isDisabled).toBe(false);
|
||||
done();
|
||||
});
|
||||
@ -126,14 +128,14 @@ describe('<Login />', () => {
|
||||
submitButton.simulate('click');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'invalid');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'invalid');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === true);
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === true);
|
||||
await waitForElement(loginWrapper, formError, (el) => el.length === 1);
|
||||
|
||||
usernameInput.props().onChange({ currentTarget: { value: 'dsarif' } });
|
||||
passwordInput.props().onChange({ currentTarget: { value: 'freneticpny' } });
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'dsarif');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'freneticpny');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === false);
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === false);
|
||||
await waitForElement(loginWrapper, formError, (el) => el.length === 0);
|
||||
|
||||
done();
|
||||
@ -151,16 +153,16 @@ describe('<Login />', () => {
|
||||
|
||||
RootAPI.login.mockRejectedValueOnce({ response: { status: 500 } });
|
||||
submitButton.simulate('click');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true);
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
|
||||
|
||||
usernameInput.props().onChange({ currentTarget: { value: 'sgrimes' } });
|
||||
passwordInput.props().onChange({ currentTarget: { value: 'ovid' } });
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'sgrimes');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'ovid');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true);
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
|
||||
|
||||
submitButton.simulate('click');
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === false);
|
||||
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === false);
|
||||
done();
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import ManagementJobs from './ManagementJobs';
|
||||
|
||||
describe('<ManagementJobs />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import NotificationTemplates from './NotificationTemplates';
|
||||
|
||||
describe('<NotificationTemplates />', () => {
|
||||
|
@ -10,8 +10,6 @@ jest.mock('@api');
|
||||
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
describe('<OrganizationEdit />', () => {
|
||||
let api;
|
||||
|
||||
const mockData = {
|
||||
name: 'Foo',
|
||||
description: 'Bar',
|
||||
@ -22,23 +20,8 @@ describe('<OrganizationEdit />', () => {
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
api = {
|
||||
getInstanceGroups: jest.fn(),
|
||||
updateOrganizationDetails: jest.fn(),
|
||||
associateInstanceGroup: jest.fn(),
|
||||
disassociate: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
test('handleSubmit should call api update', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<OrganizationEdit
|
||||
organization={mockData}
|
||||
/>, { context: { network: {
|
||||
api,
|
||||
} } }
|
||||
);
|
||||
const wrapper = mountWithContexts(<OrganizationEdit organization={mockData} />);
|
||||
|
||||
const updatedOrgData = {
|
||||
name: 'new name',
|
||||
@ -51,13 +34,7 @@ describe('<OrganizationEdit />', () => {
|
||||
});
|
||||
|
||||
test('handleSubmit associates and disassociates instance groups', async () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<OrganizationEdit
|
||||
organization={mockData}
|
||||
/>, { context: { network: {
|
||||
api,
|
||||
} } }
|
||||
);
|
||||
const wrapper = mountWithContexts(<OrganizationEdit organization={mockData} />);
|
||||
|
||||
const updatedOrgData = {
|
||||
name: 'new name',
|
||||
@ -77,14 +54,8 @@ describe('<OrganizationEdit />', () => {
|
||||
push: jest.fn(),
|
||||
};
|
||||
const wrapper = mountWithContexts(
|
||||
<OrganizationEdit
|
||||
organization={mockData}
|
||||
/>, { context: {
|
||||
network: {
|
||||
api: { api },
|
||||
},
|
||||
router: { history }
|
||||
} }
|
||||
<OrganizationEdit organization={mockData} />,
|
||||
{ context: { router: { history } } }
|
||||
);
|
||||
|
||||
expect(history.push).not.toHaveBeenCalled();
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Portal from './Portal';
|
||||
|
||||
describe('<Portal />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Projects from './Projects';
|
||||
|
||||
describe('<Projects />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Schedules from './Schedules';
|
||||
|
||||
describe('<Schedules />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import SystemSettings from './SystemSettings';
|
||||
|
||||
describe('<SystemSettings />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Teams from './Teams';
|
||||
|
||||
describe('<Teams />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import UISettings from './UISettings';
|
||||
|
||||
describe('<UISettings />', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
|
||||
import Users from './Users';
|
||||
|
||||
describe('<Users />', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user