Explore: Fix loading error for empty queries (#18488)

* Explore: Fix loading error for empty queries

* Explore: Render tests for QueryField
This commit is contained in:
David 2019-08-09 17:08:59 +02:00 committed by GitHub
parent 445f1dabcc
commit b3d2cc3e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import { QueryField } from './QueryField';
describe('<QueryField />', () => {
it('renders with null initial value', () => {
const wrapper = shallow(<QueryField initialQuery={null} />);
expect(wrapper.find('div').exists()).toBeTruthy();
});
it('renders with empty initial value', () => {
const wrapper = shallow(<QueryField initialQuery="" />);
expect(wrapper.find('div').exists()).toBeTruthy();
});
it('renders with initial value', () => {
const wrapper = shallow(<QueryField initialQuery="my query" />);
expect(wrapper.find('div').exists()).toBeTruthy();
});
});

View File

@ -92,7 +92,7 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
typeaheadIndex: 0, typeaheadIndex: 0,
typeaheadPrefix: '', typeaheadPrefix: '',
typeaheadText: '', typeaheadText: '',
value: makeValue(props.initialQuery, props.syntax), value: makeValue(props.initialQuery || '', props.syntax),
lastExecutedValue: null, lastExecutedValue: null,
}; };
} }
@ -420,6 +420,10 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
updateMenu = () => { updateMenu = () => {
const { suggestions } = this.state; const { suggestions } = this.state;
const menu = this.menuEl; const menu = this.menuEl;
// Exit for unit tests
if (!window.getSelection) {
return;
}
const selection = window.getSelection(); const selection = window.getSelection();
const node = selection.anchorNode; const node = selection.anchorNode;