Skip to content

Commit

Permalink
Fixes auto suggest in security solution (elastic#145924)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Nov 28, 2022
1 parent 48adb0c commit 3a6825c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import { compact, debounce, isEmpty, isEqual, isFunction, partition } from 'loda
import { CoreStart, DocLinksStart, Toast } from '@kbn/core/public';
import type { Query } from '@kbn/es-query';
import { DataPublicPluginStart, getQueryLog } from '@kbn/data-plugin/public';
import {
type DataView,
DataView as KibanaDataView,
DataViewsPublicPluginStart,
} from '@kbn/data-views-plugin/public';
import { type DataView, DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { PersistedLog } from '@kbn/data-plugin/public';
import { getFieldSubtypeNested, KIBANA_USER_QUERY_LANGUAGE_KEY } from '@kbn/data-plugin/common';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
Expand Down Expand Up @@ -188,7 +184,7 @@ export default class QueryStringInputUI extends PureComponent<QueryStringInputPr
QueryStringInputProps['indexPatterns'][number],
DataView
>(this.props.indexPatterns || [], (indexPattern): indexPattern is DataView => {
return indexPattern instanceof KibanaDataView;
return indexPattern.hasOwnProperty('fields') && indexPattern.hasOwnProperty('title');
});
const idOrTitlePatterns = stringPatterns.map((sp) =>
typeof sp === 'string' ? { type: 'title', value: sp } : sp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
*/

import { login, visit } from '../../tasks/login';
import { openAddFilterPopover, fillAddFilterForm } from '../../tasks/search_bar';
import { GLOBAL_SEARCH_BAR_FILTER_ITEM } from '../../screens/search_bar';
import {
openAddFilterPopover,
fillAddFilterForm,
openKqlQueryBar,
fillKqlQueryBar,
} from '../../tasks/search_bar';
import {
AUTO_SUGGEST_AGENT_NAME,
AUTO_SUGGEST_HOST_NAME_VALUE,
GLOBAL_SEARCH_BAR_FILTER_ITEM,
} from '../../screens/search_bar';
import { getHostIpFilter } from '../../objects/filter';

import { HOSTS_URL } from '../../urls/navigation';
Expand All @@ -29,4 +38,11 @@ describe('SearchBar', () => {
`${getHostIpFilter().key}: ${getHostIpFilter().value}`
);
});

it('auto suggests fields from the data view and auto completes available field values', () => {
openKqlQueryBar();
cy.get(AUTO_SUGGEST_AGENT_NAME).should('be.visible');
fillKqlQueryBar(`host.name:`);
cy.get(AUTO_SUGGEST_HOST_NAME_VALUE).should('be.visible');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ export const GLOBAL_SEARCH_BAR_FILTER_ITEM = '#popoverFor_filter0';
export const GLOBAL_SEARCH_BAR_FILTER_ITEM_AT = (value: number) => `#popoverFor_filter${value}`;

export const GLOBAL_SEARCH_BAR_PINNED_FILTER = '.globalFilterItem-isPinned';

export const GLOBAL_KQL_INPUT =
'[data-test-subj="filters-global-container"] [data-test-subj="unifiedQueryInput"] textarea';

export const AUTO_SUGGEST_AGENT_NAME = `[data-test-subj="autocompleteSuggestion-field-agent.name-"]`;

export const AUTO_SUGGEST_HOST_NAME_VALUE = `[data-test-subj='autocompleteSuggestion-value-"siem-kibana"-']`;
11 changes: 11 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/search_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ADD_FILTER_FORM_OPERATOR_FIELD,
ADD_FILTER_FORM_FIELD_OPTION,
ADD_FILTER_FORM_FILTER_VALUE_INPUT,
GLOBAL_KQL_INPUT,
} from '../screens/search_bar';

export const openAddFilterPopover = () => {
Expand All @@ -24,6 +25,16 @@ export const openAddFilterPopover = () => {
cy.get(GLOBAL_SEARCH_BAR_ADD_FILTER).click();
};

export const openKqlQueryBar = () => {
cy.get(GLOBAL_KQL_INPUT).should('be.visible');
cy.get(GLOBAL_KQL_INPUT).click();
};

export const fillKqlQueryBar = (query: string) => {
cy.get(GLOBAL_KQL_INPUT).should('be.visible');
cy.get(GLOBAL_KQL_INPUT).type(query);
};

export const fillAddFilterForm = ({ key, value, operator }: SearchBarFilter) => {
cy.get(ADD_FILTER_FORM_FIELD_INPUT).should('exist');
cy.get(ADD_FILTER_FORM_FIELD_INPUT).should('be.visible');
Expand Down

0 comments on commit 3a6825c

Please sign in to comment.