From a70a0fa622dc3d29b4631c809f11d6096f878bca Mon Sep 17 00:00:00 2001 From: kialam Date: Wed, 16 Jan 2019 13:15:51 -0500 Subject: [PATCH] Bump Lookup component test coverage up. --- __tests__/components/Lookup.test.jsx | 57 +++++++++++++++++--- src/components/ListItem/CheckboxListItem.jsx | 2 +- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/__tests__/components/Lookup.test.jsx b/__tests__/components/Lookup.test.jsx index 5d4093ff54..8175b619e4 100644 --- a/__tests__/components/Lookup.test.jsx +++ b/__tests__/components/Lookup.test.jsx @@ -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('', () => { test('initially renders succesfully', () => { @@ -19,15 +18,61 @@ describe('', () => { const spy = jest.spyOn(Lookup.prototype, 'onLookup'); const wrapper = mount( - { }} - data={mockData} - /> + { }} + data={mockData} + /> ); 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( + + { }} + data={mockData} + /> + + ); + 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( + + { }} + data={mockData} + /> + + ); + 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( + + { }} + data={mockData} + /> + + ); + expect(spy).toHaveBeenCalled(); + const pill = wrapper.find('span.awx-c-tag--pill'); + expect(pill).toHaveLength(0); + }); }); diff --git a/src/components/ListItem/CheckboxListItem.jsx b/src/components/ListItem/CheckboxListItem.jsx index 5970690429..d27722af19 100644 --- a/src/components/ListItem/CheckboxListItem.jsx +++ b/src/components/ListItem/CheckboxListItem.jsx @@ -26,7 +26,7 @@ export default ({
-