Fixes failing tests

This commit is contained in:
Alex Corey
2019-11-12 10:16:25 -05:00
parent 95cdddd670
commit e3ee3c5a00
3 changed files with 28 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ describe('<ProjectForm />', () => {
id: 100, id: 100,
credential_type_id: 4, credential_type_id: 4,
kind: 'scm', kind: 'scm',
name: 'alpha', name: 'Foo',
}, },
}, },
}; };

View File

@@ -200,7 +200,9 @@ describe('<JobTemplateEdit />', () => {
data: { ...updatedTemplateData }, data: { ...updatedTemplateData },
}); });
const formik = wrapper.find('Formik').instance(); const formik = wrapper.find('Formik').instance();
const changeState = new Promise(resolve => { const changeState = await act(
() =>
new Promise(resolve => {
const values = { const values = {
...mockJobTemplate, ...mockJobTemplate,
...updatedTemplateData, ...updatedTemplateData,
@@ -208,9 +210,12 @@ describe('<JobTemplateEdit />', () => {
instanceGroups: [], instanceGroups: [],
}; };
formik.setState({ values }, () => resolve()); formik.setState({ values }, () => resolve());
}); })
);
await changeState; await changeState;
await act(async () => {
wrapper.find('button[aria-label="Save"]').simulate('click'); wrapper.find('button[aria-label="Save"]').simulate('click');
});
await sleep(0); await sleep(0);
expect(JobTemplatesAPI.update).toHaveBeenCalledWith(1, { expect(JobTemplatesAPI.update).toHaveBeenCalledWith(1, {
@@ -236,7 +241,9 @@ describe('<JobTemplateEdit />', () => {
'button[aria-label="Cancel"]', 'button[aria-label="Cancel"]',
e => e.length === 1 e => e.length === 1
); );
await act(async () => {
cancelButton.prop('onClick')(); cancelButton.prop('onClick')();
});
expect(history.location.pathname).toEqual( expect(history.location.pathname).toEqual(
'/templates/job_template/1/details' '/templates/job_template/1/details'
); );

View File

@@ -157,10 +157,12 @@ describe('<JobTemplateForm />', () => {
target: { value: 'new baz type', name: 'playbook' }, target: { value: 'new baz type', name: 'playbook' },
}); });
expect(form.state('values').playbook).toEqual('new baz type'); expect(form.state('values').playbook).toEqual('new baz type');
await act(async () => {
wrapper wrapper
.find('CredentialChip') .find('CredentialChip')
.at(0) .at(0)
.prop('onClick')(); .prop('onClick')();
});
expect(form.state('values').credentials).toEqual([ expect(form.state('values').credentials).toEqual([
{ id: 2, kind: 'ssh', name: 'Bar' }, { id: 2, kind: 'ssh', name: 'Bar' },
]); ]);
@@ -180,7 +182,9 @@ describe('<JobTemplateForm />', () => {
}); });
await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
expect(handleSubmit).not.toHaveBeenCalled(); expect(handleSubmit).not.toHaveBeenCalled();
await act(async () => {
wrapper.find('button[aria-label="Save"]').simulate('click'); wrapper.find('button[aria-label="Save"]').simulate('click');
});
await sleep(1); await sleep(1);
expect(handleSubmit).toBeCalled(); expect(handleSubmit).toBeCalled();
}); });