mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
update organization add test to use mountWithContexts
This commit is contained in:
parent
ce49cb9ba4
commit
a6f79c646d
@ -1,12 +1,8 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
|
||||
import { ConfigProvider } from '../../../../src/contexts/Config';
|
||||
import { NetworkProvider } from '../../../../src/contexts/Network';
|
||||
import { mountWithContexts } from '../../../enzymeHelpers';
|
||||
|
||||
import { _OrganizationAdd } from '../../../../src/pages/Organizations/screens/OrganizationAdd';
|
||||
import OrganizationAdd from '../../../../src/pages/Organizations/screens/OrganizationAdd';
|
||||
|
||||
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
@ -29,25 +25,15 @@ describe('<OrganizationAdd />', () => {
|
||||
});
|
||||
|
||||
test('handleSubmit should post to api', () => {
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider>
|
||||
<_OrganizationAdd api={api} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { network: networkProviderValue }
|
||||
});
|
||||
const updatedOrgData = {
|
||||
name: 'new name',
|
||||
description: 'new description',
|
||||
custom_virtualenv: 'Buzz',
|
||||
};
|
||||
wrapper.find('OrganizationForm').prop('handleSubmit')(updatedOrgData, [], []);
|
||||
|
||||
expect(api.createOrganization).toHaveBeenCalledWith(updatedOrgData);
|
||||
});
|
||||
|
||||
@ -55,21 +41,11 @@ describe('<OrganizationAdd />', () => {
|
||||
const history = {
|
||||
push: jest.fn(),
|
||||
};
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider>
|
||||
<_OrganizationAdd api={api} history={history} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { router: { history } }
|
||||
});
|
||||
expect(history.push).not.toHaveBeenCalled();
|
||||
wrapper.find('button[aria-label="Cancel"]').prop('onClick')();
|
||||
|
||||
expect(history.push).toHaveBeenCalledWith('/organizations');
|
||||
});
|
||||
|
||||
@ -77,21 +53,11 @@ describe('<OrganizationAdd />', () => {
|
||||
const history = {
|
||||
push: jest.fn(),
|
||||
};
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider>
|
||||
<_OrganizationAdd api={api} history={history} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { router: { history } }
|
||||
});
|
||||
expect(history.push).not.toHaveBeenCalled();
|
||||
wrapper.find('button[aria-label="Close"]').prop('onClick')();
|
||||
|
||||
expect(history.push).toHaveBeenCalledWith('/organizations');
|
||||
});
|
||||
|
||||
@ -113,37 +79,18 @@ describe('<OrganizationAdd />', () => {
|
||||
...orgData,
|
||||
}
|
||||
});
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider>
|
||||
<_OrganizationAdd api={api} history={history} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { router: { history }, network: networkProviderValue }
|
||||
});
|
||||
wrapper.find('OrganizationForm').prop('handleSubmit')(orgData, [], []);
|
||||
await sleep(0);
|
||||
|
||||
expect(history.push).toHaveBeenCalledWith('/organizations/5');
|
||||
});
|
||||
|
||||
test('handleSubmit should post instance groups', async () => {
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider>
|
||||
<_OrganizationAdd api={api} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { network: networkProviderValue }
|
||||
});
|
||||
const orgData = {
|
||||
name: 'new name',
|
||||
description: 'new description',
|
||||
@ -160,7 +107,6 @@ describe('<OrganizationAdd />', () => {
|
||||
});
|
||||
wrapper.find('OrganizationForm').prop('handleSubmit')(orgData, [3], []);
|
||||
await sleep(0);
|
||||
|
||||
expect(api.associateInstanceGroup)
|
||||
.toHaveBeenCalledWith('/api/v2/organizations/5/instance_groups', 3);
|
||||
});
|
||||
@ -169,17 +115,9 @@ describe('<OrganizationAdd />', () => {
|
||||
const config = {
|
||||
custom_virtualenvs: ['foo', 'bar'],
|
||||
};
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider value={config}>
|
||||
<_OrganizationAdd api={api} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).find('OrganizationAdd').find('AnsibleSelect');
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { network: networkProviderValue, config }
|
||||
}).find('AnsibleSelect');
|
||||
expect(wrapper.find('FormSelect')).toHaveLength(1);
|
||||
expect(wrapper.find('FormSelectOption')).toHaveLength(2);
|
||||
});
|
||||
@ -188,17 +126,9 @@ describe('<OrganizationAdd />', () => {
|
||||
const config = {
|
||||
custom_virtualenvs: [],
|
||||
};
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<NetworkProvider value={networkProviderValue}>
|
||||
<ConfigProvider value={config}>
|
||||
<_OrganizationAdd api={api} />
|
||||
</ConfigProvider>
|
||||
</NetworkProvider>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).find('OrganizationAdd').find('AnsibleSelect');
|
||||
const wrapper = mountWithContexts(<OrganizationAdd />, {
|
||||
context: { network: networkProviderValue, config }
|
||||
}).find('AnsibleSelect');
|
||||
expect(wrapper.find('FormSelect')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user