mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
445f1dabcc
commit
b3d2cc3e2f
19
public/app/features/explore/QueryField.test.tsx
Normal file
19
public/app/features/explore/QueryField.test.tsx
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user