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,
credential_type_id: 4,
kind: 'scm',
name: 'alpha',
name: 'Foo',
},
},
};

View File

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

View File

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