mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
fix tests
This commit is contained in:
@@ -26,7 +26,9 @@ describe('<Lookup />', () => {
|
|||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
);
|
);
|
||||||
expect(spy).not.toHaveBeenCalled();
|
expect(spy).not.toHaveBeenCalled();
|
||||||
wrapper.find('#search').simulate('click');
|
debugger;
|
||||||
|
const searchItem = wrapper.find('.pf-c-input-group__text#search');
|
||||||
|
searchItem.first().simulate('click');
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('calls "onChecked" when a user changes a checkbox', () => {
|
test('calls "onChecked" when a user changes a checkbox', () => {
|
||||||
@@ -40,7 +42,9 @@ describe('<Lookup />', () => {
|
|||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
);
|
);
|
||||||
wrapper.find('#search').simulate('click');
|
debugger;
|
||||||
|
const searchItem = wrapper.find('.pf-c-input-group__text#search');
|
||||||
|
searchItem.first().simulate('click');
|
||||||
wrapper.find('input[type="checkbox"]').simulate('change');
|
wrapper.find('input[type="checkbox"]').simulate('change');
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -56,7 +60,8 @@ describe('<Lookup />', () => {
|
|||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
);
|
);
|
||||||
wrapper.find('.awx-c-icon--remove').simulate('click');
|
const removeIcon = wrapper.find('.awx-c-icon--remove').first();
|
||||||
|
removeIcon.simulate('click');
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('"wrapTags" method properly handles data', () => {
|
test('"wrapTags" method properly handles data', () => {
|
||||||
|
|||||||
@@ -57,28 +57,19 @@ describe('<OrganizationAdd />', () => {
|
|||||||
wrapper.find('button.at-C-CancelButton').prop('onClick')();
|
wrapper.find('button.at-C-CancelButton').prop('onClick')();
|
||||||
expect(spy).toBeCalled();
|
expect(spy).toBeCalled();
|
||||||
});
|
});
|
||||||
test('API response data is formatted properly', () => {
|
|
||||||
const mockData = { data: { results: [{ name: 'test instance', id: 1 }] } };
|
|
||||||
const promise = Promise.resolve(mockData);
|
|
||||||
|
|
||||||
return promise.then(({ data }) => {
|
|
||||||
const expected = [{ id: 1, name: 'test instance', isChecked: false }];
|
|
||||||
const results = OrganizationAdd.WrappedComponent.prototype.format(data);
|
|
||||||
expect(results).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('API response is formatted properly', (done) => {
|
test('API response is formatted properly', (done) => {
|
||||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'format');
|
const mockedResp = { data: { results: [{ name: 'test instance', id: 1 }] } };
|
||||||
const mockedResp = { data: { id: 1, name: 'foo bar' } };
|
|
||||||
const api = { getInstanceGroups: jest.fn().mockResolvedValue(mockedResp) };
|
const api = { getInstanceGroups: jest.fn().mockResolvedValue(mockedResp) };
|
||||||
mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<OrganizationAdd api={api} />
|
<OrganizationAdd api={api} />
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
expect(spy).toHaveBeenCalled();
|
const orgAddElem = wrapper.find('OrganizationAdd');
|
||||||
|
expect([{ id: 1, isChecked: false, name: 'test instance' }]).toEqual(orgAddElem.state().results);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,16 +23,17 @@ import Lookup from '../../../components/Lookup';
|
|||||||
import AnsibleSelect from '../../../components/AnsibleSelect';
|
import AnsibleSelect from '../../../components/AnsibleSelect';
|
||||||
|
|
||||||
const { light } = PageSectionVariants;
|
const { light } = PageSectionVariants;
|
||||||
class OrganizationAdd extends React.Component {
|
|
||||||
static format (data) {
|
|
||||||
const results = data.results.map((result) => ({
|
|
||||||
id: result.id,
|
|
||||||
name: result.name,
|
|
||||||
isChecked: false
|
|
||||||
}));
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const format = (data) => {
|
||||||
|
const results = data.results.map((result) => ({
|
||||||
|
id: result.id,
|
||||||
|
name: result.name,
|
||||||
|
isChecked: false
|
||||||
|
}));
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
class OrganizationAdd extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -43,7 +44,6 @@ class OrganizationAdd extends React.Component {
|
|||||||
this.resetForm = this.resetForm.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@@ -59,7 +59,7 @@ class OrganizationAdd extends React.Component {
|
|||||||
const { api } = this.props;
|
const { api } = this.props;
|
||||||
try {
|
try {
|
||||||
const { data } = await api.getInstanceGroups();
|
const { data } = await api.getInstanceGroups();
|
||||||
const results = this.format(data);
|
const results = format(data);
|
||||||
this.setState({ results });
|
this.setState({ results });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ getInstanceGroupsError: error });
|
this.setState({ getInstanceGroupsError: error });
|
||||||
|
|||||||
Reference in New Issue
Block a user