mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 11:25:08 -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);
|
||||
});
|
||||
});
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user