Skip to content

Commit

Permalink
[Lens] Fix bug where suggestions didn't use filters (#63293) (#63468)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Wylie Conlon and elasticmachine authored Apr 14, 2020
1 parent 0bf3c24 commit 67037bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../mocks';
import { act } from 'react-dom/test-utils';
import { ReactExpressionRendererType } from '../../../../../../../src/plugins/expressions/public';
import { esFilters, IFieldType, IIndexPattern } from '../../../../../../../src/plugins/data/public';
import { SuggestionPanel, SuggestionPanelProps } from './suggestion_panel';
import { getSuggestions, Suggestion } from './suggestion_helpers';
import { EuiIcon, EuiPanel, EuiToolTip } from '@elastic/eui';
Expand Down Expand Up @@ -243,14 +244,25 @@ describe('suggestion_panel', () => {
(mockVisualization.toPreviewExpression as jest.Mock).mockReturnValueOnce('test | expression');
mockDatasource.toExpression.mockReturnValue('datasource_expression');

mount(<SuggestionPanel {...defaultProps} />);
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
const field = ({ name: 'myfield' } as unknown) as IFieldType;

mount(
<SuggestionPanel
{...defaultProps}
frame={{
...createMockFramePublicAPI(),
filters: [esFilters.buildExistsFilter(field, indexPattern)],
}}
/>
);

expect(expressionRendererMock).toHaveBeenCalledTimes(1);
const passedExpression = (expressionRendererMock as jest.Mock).mock.calls[0][0].expression;

expect(passedExpression).toMatchInlineSnapshot(`
"kibana
| kibana_context timeRange=\\"{\\\\\\"from\\\\\\":\\\\\\"now-7d\\\\\\",\\\\\\"to\\\\\\":\\\\\\"now\\\\\\"}\\" query=\\"{\\\\\\"query\\\\\\":\\\\\\"\\\\\\",\\\\\\"language\\\\\\":\\\\\\"lucene\\\\\\"}\\" filters=\\"[]\\"
| kibana_context timeRange=\\"{\\\\\\"from\\\\\\":\\\\\\"now-7d\\\\\\",\\\\\\"to\\\\\\":\\\\\\"now\\\\\\"}\\" query=\\"{\\\\\\"query\\\\\\":\\\\\\"\\\\\\",\\\\\\"language\\\\\\":\\\\\\"lucene\\\\\\"}\\" filters=\\"[{\\\\\\"meta\\\\\\":{\\\\\\"index\\\\\\":\\\\\\"index1\\\\\\"},\\\\\\"exists\\\\\\":{\\\\\\"field\\\\\\":\\\\\\"myfield\\\\\\"}}]\\"
| lens_merge_tables layerIds=\\"first\\" tables={datasource_expression}
| test
| expression"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export function SuggestionPanel({

const expressionContext = {
query: frame.query,
filters: frame.filters,
timeRange: {
from: frame.dateRange.fromDate,
to: frame.dateRange.toDate,
Expand Down

0 comments on commit 67037bb

Please sign in to comment.