Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes auto suggest in security solution #145924

Merged
merged 6 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-"]`;
stephmilovic marked this conversation as resolved.
Show resolved Hide resolved

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