2017-11-29 04:59:55 -05:00
|
|
|
/**
|
|
|
|
* Search component
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2018-06-17 06:34:59 -05:00
|
|
|
import Search from '../../../../src/webui/src/components/Search/index';
|
2017-11-29 04:59:55 -05:00
|
|
|
console.error = jest.fn();
|
|
|
|
|
|
|
|
describe('<Search /> component', () => {
|
|
|
|
it('should give error for the required fields', () => {
|
|
|
|
const wrapper = shallow(<Search />);
|
|
|
|
expect(console.error).toBeCalled();
|
2017-12-02 07:34:42 -05:00
|
|
|
expect(wrapper.find('input').prop('placeholder')).toEqual(
|
|
|
|
'Type to search...'
|
|
|
|
);
|
2017-11-29 04:59:55 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have <input /> element with correct properties', () => {
|
|
|
|
const props = {
|
|
|
|
handleSearchInput: () => {},
|
|
|
|
placeHolder: 'Test placeholder'
|
|
|
|
};
|
|
|
|
const wrapper = shallow(<Search {...props} />);
|
|
|
|
expect(wrapper.find('input')).toHaveLength(1);
|
|
|
|
expect(wrapper.find('input').prop('placeholder')).toEqual(
|
|
|
|
'Test placeholder'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the handleSearchInput function', () => {
|
|
|
|
const props = {
|
2017-12-02 09:01:06 -05:00
|
|
|
handleSearchInput: jest.fn()
|
2017-11-29 04:59:55 -05:00
|
|
|
};
|
|
|
|
const wrapper = shallow(<Search {...props} />);
|
|
|
|
wrapper.find('input').simulate('change');
|
|
|
|
expect(props.handleSearchInput).toBeCalled();
|
|
|
|
});
|
2017-12-02 09:01:06 -05:00
|
|
|
|
|
|
|
it('should match the snapshot', () => {
|
|
|
|
const props = { handleSearchInput: () => {} };
|
|
|
|
const wrapper = shallow(<Search {...props} />);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2017-12-02 07:34:42 -05:00
|
|
|
});
|