mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Bump up unit test coverage for OrganizationAdd component.
This commit is contained in:
@@ -67,9 +67,25 @@ describe('<OrganizationAdd />', () => {
|
|||||||
expect(results).toEqual(expected);
|
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) => {
|
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 mockedResp = {data: {id: 1, related: {instance_groups: '/bar'}}};
|
||||||
const api = { createOrganization: jest.fn().mockResolvedValue(mockedResp), createInstanceGroups: jest.fn().mockResolvedValue('done') };
|
const api = { createOrganization: jest.fn().mockResolvedValue(mockedResp), createInstanceGroups: jest.fn().mockResolvedValue('done') };
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
@@ -80,7 +96,8 @@ describe('<OrganizationAdd />', () => {
|
|||||||
wrapper.find('input#add-org-form-name').simulate('change', { target: { value: 'foo' } });
|
wrapper.find('input#add-org-form-name').simulate('change', { target: { value: 'foo' } });
|
||||||
wrapper.find('button.at-C-SubmitButton').prop('onClick')();
|
wrapper.find('button.at-C-SubmitButton').prop('onClick')();
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(onSuccess).toHaveBeenCalled();
|
||||||
|
expect(resetForm).toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class OrganizationAdd extends React.Component {
|
|||||||
this.onSelectChange = this.onSelectChange.bind(this);
|
this.onSelectChange = this.onSelectChange.bind(this);
|
||||||
this.onLookupChange = this.onLookupChange.bind(this);
|
this.onLookupChange = this.onLookupChange.bind(this);
|
||||||
this.onSubmit = this.onSubmit.bind(this);
|
this.onSubmit = this.onSubmit.bind(this);
|
||||||
|
this.resetForm = this.resetForm.bind(this);
|
||||||
this.onSuccess = this.onSuccess.bind(this);
|
this.onSuccess = this.onSuccess.bind(this);
|
||||||
this.onCancel = this.onCancel.bind(this);
|
this.onCancel = this.onCancel.bind(this);
|
||||||
this.format = this.format.bind(this);
|
this.format = this.format.bind(this);
|
||||||
@@ -83,11 +84,11 @@ class OrganizationAdd extends React.Component {
|
|||||||
selected.forEach( async (select) => {
|
selected.forEach( async (select) => {
|
||||||
await api.createInstanceGroups(url, select.id);
|
await api.createInstanceGroups(url, select.id);
|
||||||
});
|
});
|
||||||
this.resetForm();
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ createInstanceGroupsError: err })
|
this.setState({ createInstanceGroupsError: err })
|
||||||
} finally {
|
} finally {
|
||||||
|
this.resetForm();
|
||||||
this.onSuccess(response.id);
|
this.onSuccess(response.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user