Skip to content

Commit

Permalink
[data.ui.query] Write filters to query log from default editor. (#74474)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Aug 11, 2020
1 parent f4b44c7 commit d49662e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,44 @@ describe('QueryStringInput', () => {
expect(mockCallback).toHaveBeenCalledWith({ query: 'response:200', language: 'kuery' });
});

it('Should fire onBlur callback on input blur', () => {
const mockCallback = jest.fn();

const component = mount(
wrapQueryStringInputInContext({
query: kqlQuery,
onBlur: mockCallback,
indexPatterns: [stubIndexPatternWithFields],
disableAutoFocus: true,
})
);

const inputWrapper = component.find(EuiTextArea).find('textarea');
inputWrapper.simulate('blur');

expect(mockCallback).toHaveBeenCalledTimes(1);
expect(mockCallback).toHaveBeenCalledWith();
});

it('Should fire onChangeQueryInputFocus callback on input blur', () => {
const mockCallback = jest.fn();

const component = mount(
wrapQueryStringInputInContext({
query: kqlQuery,
onChangeQueryInputFocus: mockCallback,
indexPatterns: [stubIndexPatternWithFields],
disableAutoFocus: true,
})
);

const inputWrapper = component.find(EuiTextArea).find('textarea');
inputWrapper.simulate('blur');

expect(mockCallback).toHaveBeenCalledTimes(1);
expect(mockCallback).toHaveBeenCalledWith(false);
});

it('Should use PersistedLog for recent search suggestions', async () => {
const component = mount(
wrapQueryStringInputInContext({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';
import { debounce, compact, isEqual } from 'lodash';
import { debounce, compact, isEqual, isFunction } from 'lodash';
import { Toast } from 'src/core/public';
import { IDataPluginServices, IIndexPattern, Query } from '../..';
import { QuerySuggestion, QuerySuggestionTypes } from '../../autocomplete';
Expand Down Expand Up @@ -460,6 +460,9 @@ export class QueryStringInputUI extends Component<Props, State> {
if (this.props.onChangeQueryInputFocus) {
this.props.onChangeQueryInputFocus(false);
}
if (isFunction(this.props.onBlur)) {
this.props.onBlur();
}
};

private onClickSuggestion = (suggestion: QuerySuggestion) => {
Expand Down

0 comments on commit d49662e

Please sign in to comment.