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,6 +98,7 @@ describe('<ProjectAdd />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
@ -109,6 +110,7 @@ describe('<ProjectAdd />', () => {
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
await act(async () => {
|
||||
wrapper.find('form').simulate('submit');
|
||||
});
|
||||
@ -146,7 +148,9 @@ describe('<ProjectAdd />', () => {
|
||||
context: { router: { history } },
|
||||
}).find('ProjectAdd CardHeader');
|
||||
});
|
||||
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);
|
||||
await act(async () => {
|
||||
wrapper.find('ProjectAdd button[aria-label="Cancel"]').simulate('click');
|
||||
});
|
||||
expect(history.location.pathname).toEqual('/projects');
|
||||
});
|
||||
});
|
||||
|
@ -131,6 +131,7 @@ describe('<ProjectForm />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
@ -142,6 +143,7 @@ describe('<ProjectForm />', () => {
|
||||
);
|
||||
});
|
||||
await changeState;
|
||||
});
|
||||
wrapper.update();
|
||||
expect(wrapper.find('FormGroup[label="SCM URL"]').length).toBe(1);
|
||||
expect(
|
||||
@ -191,6 +193,7 @@ describe('<ProjectForm />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
@ -203,6 +206,7 @@ describe('<ProjectForm />', () => {
|
||||
);
|
||||
});
|
||||
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 />, {
|
||||
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,6 +101,7 @@ describe('<JobTemplateAdd />', () => {
|
||||
});
|
||||
await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||
const formik = wrapper.find('Formik').instance();
|
||||
await act(async () => {
|
||||
const changeState = new Promise(resolve => {
|
||||
formik.setState(
|
||||
{
|
||||
@ -114,6 +115,7 @@ describe('<JobTemplateAdd />', () => {
|
||||
);
|
||||
});
|
||||
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