runner.test.tsx 676 B

1234567891011121314151617
  1. import Plain from 'slate-plain-serializer';
  2. import React from 'react';
  3. import { Editor } from '@grafana/slate-react';
  4. import { shallow } from 'enzyme';
  5. import RunnerPlugin from './runner';
  6. describe('runner', () => {
  7. const mockHandler = jest.fn();
  8. const handler = RunnerPlugin({ handler: mockHandler }).onKeyDown;
  9. it('should execute query when enter is pressed and there are no suggestions visible', () => {
  10. const value = Plain.deserialize('');
  11. const editor = shallow<Editor>(<Editor value={value} />);
  12. handler({ key: 'Enter', preventDefault: () => {} } as KeyboardEvent, editor.instance() as any, () => {});
  13. expect(mockHandler).toBeCalled();
  14. });
  15. });