mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
clean up multiple test 'act()' warnings
This commit is contained in:
parent
9ab9c6961b
commit
569b5bc533
@ -12,6 +12,7 @@ describe('CheckboxListItem', () => {
|
||||
label="Buzz"
|
||||
isSelected={false}
|
||||
onSelect={() => {}}
|
||||
onDeselect={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
|
@ -72,8 +72,8 @@ function OptionsList({
|
||||
|
||||
const Item = shape({
|
||||
id: oneOfType([number, string]).isRequired,
|
||||
url: string.isRequired,
|
||||
name: string.isRequired,
|
||||
url: string,
|
||||
});
|
||||
OptionsList.propTypes = {
|
||||
value: arrayOf(Item).isRequired,
|
||||
|
@ -98,17 +98,19 @@ describe('<ProjectAdd />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...projectData,
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...projectData,
|
||||
},
|
||||
},
|
||||
},
|
||||
() => resolve()
|
||||
);
|
||||
() => resolve()
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
await changeState;
|
||||
await act(async () => {
|
||||
wrapper.find('form').simulate('submit');
|
||||
});
|
||||
@ -146,7 +148,9 @@ describe('<ProjectAdd />', () => {
|
||||
context: { router: { history } },
|
||||
}).find('ProjectAdd CardHeader');
|
||||
});
|
||||
wrapper.find('CardCloseButton').simulate('click');
|
||||
await act(async () => {
|
||||
wrapper.find('CardCloseButton').simulate('click');
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/projects');
|
||||
});
|
||||
|
||||
@ -158,7 +162,9 @@ describe('<ProjectAdd />', () => {
|
||||
});
|
||||
});
|
||||
await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||
wrapper.find('ProjectAdd button[aria-label="Cancel"]').simulate('click');
|
||||
await act(async () => {
|
||||
wrapper.find('ProjectAdd button[aria-label="Cancel"]').simulate('click');
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/projects');
|
||||
});
|
||||
});
|
||||
|
@ -131,17 +131,19 @@ describe('<ProjectForm />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...mockData,
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...mockData,
|
||||
},
|
||||
},
|
||||
},
|
||||
() => resolve()
|
||||
);
|
||||
() => resolve()
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
await changeState;
|
||||
wrapper.update();
|
||||
expect(wrapper.find('FormGroup[label="SCM URL"]').length).toBe(1);
|
||||
expect(
|
||||
@ -191,18 +193,20 @@ describe('<ProjectForm />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...mockData,
|
||||
scm_type: 'insights',
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...mockData,
|
||||
scm_type: 'insights',
|
||||
},
|
||||
},
|
||||
},
|
||||
() => resolve()
|
||||
);
|
||||
() => resolve()
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
await changeState;
|
||||
wrapper.update();
|
||||
expect(wrapper.find('FormGroup[label="Insights Credential"]').length).toBe(
|
||||
1
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||
import TeamAdd from './TeamAdd';
|
||||
@ -7,32 +8,38 @@ import { TeamsAPI } from '@api';
|
||||
jest.mock('@api');
|
||||
|
||||
describe('<TeamAdd />', () => {
|
||||
test('handleSubmit should post to api', () => {
|
||||
test('handleSubmit should post to api', async () => {
|
||||
const wrapper = mountWithContexts(<TeamAdd />);
|
||||
const updatedTeamData = {
|
||||
name: 'new name',
|
||||
description: 'new description',
|
||||
organization: 1,
|
||||
};
|
||||
wrapper.find('TeamForm').prop('handleSubmit')(updatedTeamData);
|
||||
await act(async () => {
|
||||
wrapper.find('TeamForm').invoke('handleSubmit')(updatedTeamData);
|
||||
});
|
||||
expect(TeamsAPI.create).toHaveBeenCalledWith(updatedTeamData);
|
||||
});
|
||||
|
||||
test('should navigate to teams list when cancel is clicked', () => {
|
||||
test('should navigate to teams list when cancel is clicked', async () => {
|
||||
const history = createMemoryHistory({});
|
||||
const wrapper = mountWithContexts(<TeamAdd />, {
|
||||
context: { router: { history } },
|
||||
});
|
||||
wrapper.find('button[aria-label="Cancel"]').prop('onClick')();
|
||||
await act(async () => {
|
||||
wrapper.find('button[aria-label="Cancel"]').invoke('onClick')();
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/teams');
|
||||
});
|
||||
|
||||
test('should navigate to teams list when close (x) is clicked', () => {
|
||||
test('should navigate to teams list when close (x) is clicked', async () => {
|
||||
const history = createMemoryHistory({});
|
||||
const wrapper = mountWithContexts(<TeamAdd />, {
|
||||
context: { router: { history } },
|
||||
});
|
||||
wrapper.find('button[aria-label="Close"]').prop('onClick')();
|
||||
await act(async () => {
|
||||
wrapper.find('button[aria-label="Close"]').invoke('onClick')();
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/teams');
|
||||
});
|
||||
|
||||
@ -55,11 +62,16 @@ describe('<TeamAdd />', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
const wrapper = mountWithContexts(<TeamAdd />, {
|
||||
context: { router: { history } },
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(<TeamAdd />, {
|
||||
context: { router: { history } },
|
||||
});
|
||||
});
|
||||
await waitForElement(wrapper, 'button[aria-label="Save"]');
|
||||
await wrapper.find('TeamForm').prop('handleSubmit')(teamData);
|
||||
await act(async () => {
|
||||
await wrapper.find('TeamForm').invoke('handleSubmit')(teamData);
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/teams/5');
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { TeamsAPI } from '@api';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
@ -19,25 +20,29 @@ describe('<TeamEdit />', () => {
|
||||
},
|
||||
};
|
||||
|
||||
test('handleSubmit should call api update', () => {
|
||||
test('handleSubmit should call api update', async () => {
|
||||
const wrapper = mountWithContexts(<TeamEdit team={mockData} />);
|
||||
|
||||
const updatedTeamData = {
|
||||
name: 'new name',
|
||||
description: 'new description',
|
||||
};
|
||||
wrapper.find('TeamForm').prop('handleSubmit')(updatedTeamData);
|
||||
await act(async () => {
|
||||
wrapper.find('TeamForm').invoke('handleSubmit')(updatedTeamData);
|
||||
});
|
||||
|
||||
expect(TeamsAPI.update).toHaveBeenCalledWith(1, updatedTeamData);
|
||||
});
|
||||
|
||||
test('should navigate to team detail when cancel is clicked', () => {
|
||||
test('should navigate to team detail when cancel is clicked', async () => {
|
||||
const history = createMemoryHistory({});
|
||||
const wrapper = mountWithContexts(<TeamEdit team={mockData} />, {
|
||||
context: { router: { history } },
|
||||
});
|
||||
|
||||
wrapper.find('button[aria-label="Cancel"]').prop('onClick')();
|
||||
await act(async () => {
|
||||
wrapper.find('button[aria-label="Cancel"]').invoke('onClick')();
|
||||
});
|
||||
|
||||
expect(history.location.pathname).toEqual('/teams/1/details');
|
||||
});
|
||||
|
@ -101,19 +101,21 @@ describe('<JobTemplateAdd />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...jobTemplateData,
|
||||
labels: [],
|
||||
instanceGroups: [],
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
values: {
|
||||
...jobTemplateData,
|
||||
labels: [],
|
||||
instanceGroups: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
() => resolve()
|
||||
);
|
||||
() => resolve()
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
await changeState;
|
||||
wrapper.find('form').simulate('submit');
|
||||
await sleep(1);
|
||||
expect(JobTemplatesAPI.create).toHaveBeenCalledWith(jobTemplateData);
|
||||
|
@ -79,6 +79,7 @@ class JobTemplateForm extends Component {
|
||||
};
|
||||
this.handleProjectValidation = this.handleProjectValidation.bind(this);
|
||||
this.loadRelatedInstanceGroups = this.loadRelatedInstanceGroups.bind(this);
|
||||
this.setContentError = this.setContentError.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -119,6 +120,10 @@ class JobTemplateForm extends Component {
|
||||
};
|
||||
}
|
||||
|
||||
setContentError(contentError) {
|
||||
this.setState({ contentError });
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
contentError,
|
||||
@ -285,7 +290,7 @@ class JobTemplateForm extends Component {
|
||||
form={form}
|
||||
field={field}
|
||||
onBlur={() => form.setFieldTouched('playbook')}
|
||||
onError={err => this.setState({ contentError: err })}
|
||||
onError={this.setContentError}
|
||||
/>
|
||||
</FormGroup>
|
||||
);
|
||||
@ -305,7 +310,7 @@ class JobTemplateForm extends Component {
|
||||
<LabelSelect
|
||||
value={field.value}
|
||||
onChange={labels => setFieldValue('labels', labels)}
|
||||
onError={err => this.setState({ contentError: err })}
|
||||
onError={this.setContentError}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
@ -321,7 +326,7 @@ class JobTemplateForm extends Component {
|
||||
onChange={newCredentials =>
|
||||
setFieldValue('credentials', newCredentials)
|
||||
}
|
||||
onError={err => this.setState({ contentError: err })}
|
||||
onError={this.setContentError}
|
||||
tooltip={i18n._(
|
||||
t`Select credentials that allow Tower to access the nodes this job will be ran against. You can only select one credential of each type. For machine credentials (SSH), checking "Prompt on launch" without selecting credentials will require you to select a machine credential at run time. If you select credentials and check "Prompt on launch", the selected credential(s) become the defaults that can be updated at run time.`
|
||||
)}
|
||||
|
@ -214,7 +214,7 @@ describe('UsersList with full permissions', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('api is called to delete users for each selected user.', () => {
|
||||
test('api is called to delete users for each selected user.', async () => {
|
||||
UsersAPI.destroy = jest.fn();
|
||||
wrapper.find('UsersList').setState({
|
||||
users: mockUsers,
|
||||
@ -223,7 +223,7 @@ describe('UsersList with full permissions', () => {
|
||||
isModalOpen: true,
|
||||
selected: mockUsers,
|
||||
});
|
||||
wrapper.find('ToolbarDeleteButton').prop('onDelete')();
|
||||
await wrapper.find('ToolbarDeleteButton').prop('onDelete')();
|
||||
expect(UsersAPI.destroy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user