diff --git a/test/webui/components/search.spec.js b/test/webui/components/search.spec.js new file mode 100644 index 000000000..7b294e3d9 --- /dev/null +++ b/test/webui/components/search.spec.js @@ -0,0 +1,44 @@ +/** + * Search component + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import Search from '../../../src/webui/src/components/Search/index'; + +console.error = jest.fn(); + +describe(' component', () => { + it('should give error for the required fields', () => { + const wrapper = shallow(); + expect(console.error).toBeCalled(); + expect(wrapper + .find('input') + .prop('placeholder')).toEqual('Type to search...'); + }); + + it('should have element with correct properties', () => { + const props = { + handleSearchInput: () => {}, + placeHolder: 'Test placeholder' + }; + const wrapper = shallow(); + expect(wrapper.find('input')).toHaveLength(1); + expect(wrapper.find('input').prop('placeholder')).toEqual( + 'Test placeholder' + ); + expect(typeof wrapper + .find('input') + .prop('onChange')).toBe('function'); + }); + + it('should call the handleSearchInput function', () => { + const props = { + handleSearchInput: jest.fn(), + placeHolder: 'Test placeholder' + }; + const wrapper = shallow(); + wrapper.find('input').simulate('change'); + expect(props.handleSearchInput).toBeCalled(); + }); +}); \ No newline at end of file