2019-08-09 10:08:59 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
|
|
|
|
import { QueryField } from './QueryField';
|
|
|
|
|
|
|
|
describe('<QueryField />', () => {
|
2019-08-14 07:37:04 -05:00
|
|
|
it('should render with null initial value', () => {
|
2019-08-09 10:08:59 -05:00
|
|
|
const wrapper = shallow(<QueryField initialQuery={null} />);
|
|
|
|
expect(wrapper.find('div').exists()).toBeTruthy();
|
|
|
|
});
|
2019-08-14 07:37:04 -05:00
|
|
|
|
|
|
|
it('should render with empty initial value', () => {
|
2019-08-09 10:08:59 -05:00
|
|
|
const wrapper = shallow(<QueryField initialQuery="" />);
|
|
|
|
expect(wrapper.find('div').exists()).toBeTruthy();
|
|
|
|
});
|
2019-08-14 07:37:04 -05:00
|
|
|
|
|
|
|
it('should render with initial value', () => {
|
2019-08-09 10:08:59 -05:00
|
|
|
const wrapper = shallow(<QueryField initialQuery="my query" />);
|
|
|
|
expect(wrapper.find('div').exists()).toBeTruthy();
|
|
|
|
});
|
2019-08-14 07:37:04 -05:00
|
|
|
|
|
|
|
it('should execute query when enter is pressed and there are no suggestions visible', () => {
|
|
|
|
const wrapper = shallow(<QueryField initialQuery="my query" />);
|
|
|
|
const instance = wrapper.instance() as QueryField;
|
|
|
|
instance.executeOnChangeAndRunQueries = jest.fn();
|
2019-08-23 08:17:13 -05:00
|
|
|
const handleEnterAndTabKeySpy = jest.spyOn(instance, 'handleEnterKey');
|
2019-08-14 07:37:04 -05:00
|
|
|
instance.onKeyDown({ key: 'Enter', preventDefault: () => {} } as KeyboardEvent, {});
|
|
|
|
expect(handleEnterAndTabKeySpy).toBeCalled();
|
|
|
|
expect(instance.executeOnChangeAndRunQueries).toBeCalled();
|
|
|
|
});
|
2019-08-09 10:08:59 -05:00
|
|
|
});
|