mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 12:41:19 -03:30
Bump up unit test coverage for OrganizationAdd component.
This commit is contained in:
parent
fc32cf026f
commit
7230b4bf8d
@ -67,9 +67,25 @@ describe('<OrganizationAdd />', () => {
|
||||
expect(results).toEqual(expected);
|
||||
});
|
||||
});
|
||||
test('API response is formatted properly', (done) => {
|
||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'format');
|
||||
const mockedResp = {data: {id: 1, name: 'foo bar'} };
|
||||
const api = { getInstanceGroups: jest.fn().mockResolvedValue(mockedResp) };
|
||||
mount(
|
||||
<MemoryRouter>
|
||||
<OrganizationAdd api={api} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
setImmediate(() => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Successful form submission triggers redirect', (done) => {
|
||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSuccess');
|
||||
const onSuccess = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSuccess');
|
||||
const resetForm = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'resetForm');
|
||||
const mockedResp = {data: {id: 1, related: {instance_groups: '/bar'}}};
|
||||
const api = { createOrganization: jest.fn().mockResolvedValue(mockedResp), createInstanceGroups: jest.fn().mockResolvedValue('done') };
|
||||
const wrapper = mount(
|
||||
@ -80,7 +96,8 @@ describe('<OrganizationAdd />', () => {
|
||||
wrapper.find('input#add-org-form-name').simulate('change', { target: { value: 'foo' } });
|
||||
wrapper.find('button.at-C-SubmitButton').prop('onClick')();
|
||||
setImmediate(() => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
expect(onSuccess).toHaveBeenCalled();
|
||||
expect(resetForm).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@ -30,6 +30,7 @@ class OrganizationAdd extends React.Component {
|
||||
this.onSelectChange = this.onSelectChange.bind(this);
|
||||
this.onLookupChange = this.onLookupChange.bind(this);
|
||||
this.onSubmit = this.onSubmit.bind(this);
|
||||
this.resetForm = this.resetForm.bind(this);
|
||||
this.onSuccess = this.onSuccess.bind(this);
|
||||
this.onCancel = this.onCancel.bind(this);
|
||||
this.format = this.format.bind(this);
|
||||
@ -83,11 +84,11 @@ class OrganizationAdd extends React.Component {
|
||||
selected.forEach( async (select) => {
|
||||
await api.createInstanceGroups(url, select.id);
|
||||
});
|
||||
this.resetForm();
|
||||
}
|
||||
} catch (err) {
|
||||
this.setState({ createInstanceGroupsError: err })
|
||||
} finally {
|
||||
this.resetForm();
|
||||
this.onSuccess(response.id);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user