mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 14:39:30 -02:30
Bump Lookup component test coverage up.
This commit is contained in:
@@ -3,7 +3,6 @@ import { mount } from 'enzyme';
|
|||||||
import Lookup from '../../src/components/Lookup';
|
import Lookup from '../../src/components/Lookup';
|
||||||
import { I18nProvider } from '@lingui/react';
|
import { I18nProvider } from '@lingui/react';
|
||||||
|
|
||||||
|
|
||||||
const mockData = [{ name: 'foo', id: 0, isChecked: false }];
|
const mockData = [{ name: 'foo', id: 0, isChecked: false }];
|
||||||
describe('<Lookup />', () => {
|
describe('<Lookup />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
@@ -19,15 +18,61 @@ describe('<Lookup />', () => {
|
|||||||
const spy = jest.spyOn(Lookup.prototype, 'onLookup');
|
const spy = jest.spyOn(Lookup.prototype, 'onLookup');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Lookup
|
<Lookup
|
||||||
lookup_header="Foo Bar"
|
lookup_header="Foo Bar"
|
||||||
lookupChange={() => { }}
|
lookupChange={() => { }}
|
||||||
data={mockData}
|
data={mockData}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
);
|
);
|
||||||
expect(spy).not.toHaveBeenCalled();
|
expect(spy).not.toHaveBeenCalled();
|
||||||
wrapper.find('#search').simulate('click');
|
wrapper.find('#search').simulate('click');
|
||||||
expect(spy).toHaveBeenCalled();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default ({
|
|||||||
</I18n>
|
</I18n>
|
||||||
</div>
|
</div>
|
||||||
<div className="pf-c-data-list__cell">
|
<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>
|
<b>{name}</b>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user