From 50884dfd7ef724b1cf9116209e00f75dad540fe6 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Wed, 29 Nov 2017 15:29:55 +0530 Subject: [PATCH] webui: component test case Fix: placeholder test for component minor fix --- test/webui/components/search.spec.js | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/webui/components/search.spec.js 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