mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 13:36:02 -03:30
Implement React Context API
- Move API GET request to /v2/config out to the top level of our App. - Store /v2/config response data in sessionStorage. - Use Context API to pass down relevant data to Organizations component. - Wrap our AnsibleSelect component as a context consumer and pass in the list of Ansible Environments of the logged in user. - Clear sessionStorage object when user logs out. - Update unit tests.
This commit is contained in:
@@ -2,16 +2,29 @@ import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import AnsibleSelect from '../../src/components/AnsibleSelect';
|
||||
|
||||
const mockData = ['foo', 'bar'];
|
||||
const label = "test select"
|
||||
const mockData = ["/venv/baz/", "/venv/ansible/"];
|
||||
describe('<AnsibleSelect />', () => {
|
||||
test('initially renders succesfully', async() => {
|
||||
const wrapper = mount(<AnsibleSelect selected="foo" data={mockData} selectChange={() => {}} />);
|
||||
wrapper.setState({ isHidden: false });
|
||||
test('initially renders succesfully', async () => {
|
||||
mount(
|
||||
<AnsibleSelect
|
||||
selected="foo"
|
||||
selectChange={() => { }}
|
||||
labelName={label}
|
||||
data={mockData}
|
||||
/>
|
||||
);
|
||||
});
|
||||
test('calls "onSelectChange" on dropdown select change', () => {
|
||||
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
|
||||
const wrapper = mount(<AnsibleSelect selected="foo" data={mockData} selectChange={() => {}} />);
|
||||
wrapper.setState({ isHidden: false });
|
||||
const wrapper = mount(
|
||||
<AnsibleSelect
|
||||
selected="foo"
|
||||
selectChange={() => { }}
|
||||
labelName={label}
|
||||
data={mockData}
|
||||
/>
|
||||
);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
wrapper.find('select').simulate('change');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import OrganizationAdd from '../../../../src/pages/Organizations/views/Organization.add';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
let OrganizationAdd;
|
||||
const getAppWithConfigContext = (context = {
|
||||
custom_virtualenvs: ['foo', 'bar']
|
||||
}) => {
|
||||
|
||||
// Mock the ConfigContext module being used in our OrganizationAdd component
|
||||
jest.doMock('../../../../src/context', () => {
|
||||
return {
|
||||
ConfigContext: {
|
||||
Consumer: (props) => props.children(context)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Return the updated OrganizationAdd module with mocked context
|
||||
return require('../../../../src/pages/Organizations/views/Organization.add').default;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
OrganizationAdd = getAppWithConfigContext();
|
||||
})
|
||||
|
||||
describe('<OrganizationAdd />', () => {
|
||||
test('initially renders succesfully', () => {
|
||||
mount(
|
||||
|
||||
Reference in New Issue
Block a user