From b3d2cc3e2f765928a7c1194f2ea34f4a3e1e2d27 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 9 Aug 2019 17:08:59 +0200 Subject: [PATCH] Explore: Fix loading error for empty queries (#18488) * Explore: Fix loading error for empty queries * Explore: Render tests for QueryField --- .../app/features/explore/QueryField.test.tsx | 19 +++++++++++++++++++ public/app/features/explore/QueryField.tsx | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 public/app/features/explore/QueryField.test.tsx diff --git a/public/app/features/explore/QueryField.test.tsx b/public/app/features/explore/QueryField.test.tsx new file mode 100644 index 00000000000..9b3e915a93b --- /dev/null +++ b/public/app/features/explore/QueryField.test.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +import { QueryField } from './QueryField'; + +describe('', () => { + it('renders with null initial value', () => { + const wrapper = shallow(); + expect(wrapper.find('div').exists()).toBeTruthy(); + }); + it('renders with empty initial value', () => { + const wrapper = shallow(); + expect(wrapper.find('div').exists()).toBeTruthy(); + }); + it('renders with initial value', () => { + const wrapper = shallow(); + expect(wrapper.find('div').exists()).toBeTruthy(); + }); +}); diff --git a/public/app/features/explore/QueryField.tsx b/public/app/features/explore/QueryField.tsx index 06f8c6897ed..1f637c44d59 100644 --- a/public/app/features/explore/QueryField.tsx +++ b/public/app/features/explore/QueryField.tsx @@ -92,7 +92,7 @@ export class QueryField extends React.PureComponent { const { suggestions } = this.state; const menu = this.menuEl; + // Exit for unit tests + if (!window.getSelection) { + return; + } const selection = window.getSelection(); const node = selection.anchorNode;