1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Bump Lookup component test coverage up.

This commit is contained in:
kialam 2019-01-16 13:15:51 -05:00
parent 7230b4bf8d
commit a70a0fa622
No known key found for this signature in database
GPG Key ID: 2D0E60E4B8C7EA0F
2 changed files with 52 additions and 7 deletions

View File

@ -3,7 +3,6 @@ import { mount } from 'enzyme';
import Lookup from '../../src/components/Lookup';
import { I18nProvider } from '@lingui/react';
const mockData = [{ name: 'foo', id: 0, isChecked: false }];
describe('<Lookup />', () => {
test('initially renders succesfully', () => {
@ -19,15 +18,61 @@ describe('<Lookup />', () => {
const spy = jest.spyOn(Lookup.prototype, 'onLookup');
const wrapper = mount(
<I18nProvider>
<Lookup
lookup_header="Foo Bar"
lookupChange={() => { }}
data={mockData}
/>
<Lookup
lookup_header="Foo Bar"
lookupChange={() => { }}
data={mockData}
/>
</I18nProvider>
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('#search').simulate('click');
expect(spy).toHaveBeenCalled();
});
test('calls "onChecked" when a user changes a checkbox', () => {
const spy = jest.spyOn(Lookup.prototype, 'onChecked');
const wrapper = mount(
<I18nProvider>
<Lookup
lookup_header="Foo Bar"
lookupChange={() => { }}
data={mockData}
/>
</I18nProvider>
);
wrapper.find('#search').simulate('click');
wrapper.find('input[type="checkbox"]').simulate('change');
expect(spy).toHaveBeenCalled();
});
test('calls "onRemove" when remove icon is clicked', () => {
const spy = jest.spyOn(Lookup.prototype, 'onRemove');
const mockData = [{ name: 'foo', id: 0, isChecked: false }, { name: 'bar', id: 1, isChecked: true }];
const wrapper = mount(
<I18nProvider>
<Lookup
lookup_header="Foo Bar"
lookupChange={() => { }}
data={mockData}
/>
</I18nProvider>
);
wrapper.find('.awx-c-icon--remove').simulate('click');
expect(spy).toHaveBeenCalled();
});
test('"wrapTags" method properly handles data', () => {
const spy = jest.spyOn(Lookup.prototype, 'wrapTags');
const mockData = [{ name: 'foo', id: 0, isChecked: false }, { name: 'bar', id: 1, isChecked: false }];
const wrapper = mount(
<I18nProvider>
<Lookup
lookup_header="Foo Bar"
lookupChange={() => { }}
data={mockData}
/>
</I18nProvider>
);
expect(spy).toHaveBeenCalled();
const pill = wrapper.find('span.awx-c-tag--pill');
expect(pill).toHaveLength(0);
});
});

View File

@ -26,7 +26,7 @@ export default ({
</I18n>
</div>
<div className="pf-c-data-list__cell">
<label htmlFor={`selectd-${itemId}`} id="check-action-item1">
<label htmlFor={`selectd-${itemId}`} className="check-action-item">
<b>{name}</b>
</label>
</div>