mirror of
https://github.com/ansible/awx.git
synced 2026-01-24 16:01:20 -03:30
fix tests
This commit is contained in:
parent
7de89f6486
commit
02d7006ea4
@ -26,7 +26,9 @@ describe('<Lookup />', () => {
|
||||
</I18nProvider>
|
||||
);
|
||||
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();
|
||||
});
|
||||
test('calls "onChecked" when a user changes a checkbox', () => {
|
||||
@ -40,7 +42,9 @@ describe('<Lookup />', () => {
|
||||
/>
|
||||
</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');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
@ -56,7 +60,8 @@ describe('<Lookup />', () => {
|
||||
/>
|
||||
</I18nProvider>
|
||||
);
|
||||
wrapper.find('.awx-c-icon--remove').simulate('click');
|
||||
const removeIcon = wrapper.find('.awx-c-icon--remove').first();
|
||||
removeIcon.simulate('click');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
test('"wrapTags" method properly handles data', () => {
|
||||
|
||||
@ -57,28 +57,19 @@ describe('<OrganizationAdd />', () => {
|
||||
wrapper.find('button.at-C-CancelButton').prop('onClick')();
|
||||
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) => {
|
||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'format');
|
||||
const mockedResp = { data: { id: 1, name: 'foo bar' } };
|
||||
const mockedResp = { data: { results: [{ name: 'test instance', id: 1 }] } };
|
||||
const api = { getInstanceGroups: jest.fn().mockResolvedValue(mockedResp) };
|
||||
mount(
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<OrganizationAdd api={api} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
setImmediate(() => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
const orgAddElem = wrapper.find('OrganizationAdd');
|
||||
expect([{ id: 1, isChecked: false, name: 'test instance' }]).toEqual(orgAddElem.state().results);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@ -23,16 +23,17 @@ import Lookup from '../../../components/Lookup';
|
||||
import AnsibleSelect from '../../../components/AnsibleSelect';
|
||||
|
||||
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) {
|
||||
super(props);
|
||||
|
||||
@ -43,7 +44,6 @@ class OrganizationAdd extends React.Component {
|
||||
this.resetForm = this.resetForm.bind(this);
|
||||
this.onSuccess = this.onSuccess.bind(this);
|
||||
this.onCancel = this.onCancel.bind(this);
|
||||
this.format = this.format.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
@ -59,7 +59,7 @@ class OrganizationAdd extends React.Component {
|
||||
const { api } = this.props;
|
||||
try {
|
||||
const { data } = await api.getInstanceGroups();
|
||||
const results = this.format(data);
|
||||
const results = format(data);
|
||||
this.setState({ results });
|
||||
} catch (error) {
|
||||
this.setState({ getInstanceGroupsError: error });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user