QueryField.test.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { QueryField } from './QueryField';
  4. describe('<QueryField />', () => {
  5. it('should render with null initial value', () => {
  6. const wrapper = shallow(<QueryField initialQuery={null} />);
  7. expect(wrapper.find('div').exists()).toBeTruthy();
  8. });
  9. it('should render with empty initial value', () => {
  10. const wrapper = shallow(<QueryField initialQuery="" />);
  11. expect(wrapper.find('div').exists()).toBeTruthy();
  12. });
  13. it('should render with initial value', () => {
  14. const wrapper = shallow(<QueryField initialQuery="my query" />);
  15. expect(wrapper.find('div').exists()).toBeTruthy();
  16. });
  17. it('should execute query when enter is pressed and there are no suggestions visible', () => {
  18. const wrapper = shallow(<QueryField initialQuery="my query" />);
  19. const instance = wrapper.instance() as QueryField;
  20. instance.executeOnChangeAndRunQueries = jest.fn();
  21. const handleEnterAndTabKeySpy = jest.spyOn(instance, 'handleEnterKey');
  22. instance.onKeyDown({ key: 'Enter', preventDefault: () => {} } as KeyboardEvent, {});
  23. expect(handleEnterAndTabKeySpy).toBeCalled();
  24. expect(instance.executeOnChangeAndRunQueries).toBeCalled();
  25. });
  26. });