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

[Security Solution] Add cypress tests for global search bar #68535

Merged
Show file tree
Hide file tree
Changes from 9 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
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { loginAndWaitForPage } from '../tasks/login';
import { openAddFilterPopover, fillAddFilterForm } from '../tasks/search_bar';
import { GLOBAL_SEARCH_BAR_FILTER_ITEM } from '../screens/search_bar';
import { SearchBarFilter } from '../objects/filter';

import { HOSTS_PAGE } from '../urls/navigation';

describe('SearchBar', () => {
before(() => {
loginAndWaitForPage(HOSTS_PAGE);
});

it('adds correctly a filter to the global search bar', () => {
const filter: SearchBarFilter = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create the filter constant in objects/filter.ts

key: 'host.ip',
value: '1.1.1.1',
};

openAddFilterPopover();
fillAddFilterForm(filter);
cy.get(GLOBAL_SEARCH_BAR_FILTER_ITEM(filter)).should('be.visible');
});
});
10 changes: 10 additions & 0 deletions x-pack/plugins/security_solution/cypress/objects/filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface SearchBarFilter {
key: string;
value: string;
}
29 changes: 29 additions & 0 deletions x-pack/plugins/security_solution/cypress/screens/search_bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchBarFilter } from '../objects/filter';

export const GLOBAL_SEARCH_BAR_ADD_FILTER =
'[data-test-subj="globalDatePicker"] [data-test-subj="addFilter"]';

export const ADD_FILTER_FORM_FIELD_INPUT =
'[data-test-subj="filterFieldSuggestionList"] input[data-test-subj="comboBoxSearchInput"]';

export const ADD_FILTER_FORM_FIELD_OPTION = (value: string) =>
`[data-test-subj="comboBoxOptionsList filterFieldSuggestionList-optionsList"] button[title="${value}"] strong`;

export const ADD_FILTER_FORM_OPERATOR_FIELD =
'[data-test-subj="filterOperatorList"] input[data-test-subj="comboBoxSearchInput"]';

export const ADD_FILTER_FORM_OPERATOR_OPTION_IS =
'[data-test-subj="comboBoxOptionsList filterOperatorList-optionsList"] button[title="is"]';

export const ADD_FILTER_FORM_FILTER_VALUE_INPUT = '[data-test-subj="filterParams"] input';

export const ADD_FILTER_FORM_SAVE_BUTTON = '[data-test-subj="saveFilter"]';

export const GLOBAL_SEARCH_BAR_FILTER_ITEM = ({ key, value }: SearchBarFilter) =>
`[data-test-subj="filter filter-enabled filter-key-${key} filter-value-${value} filter-unpinned"]`;
30 changes: 30 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/search_bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchBarFilter } from '../objects/filter';

import {
GLOBAL_SEARCH_BAR_ADD_FILTER,
ADD_FILTER_FORM_SAVE_BUTTON,
ADD_FILTER_FORM_FIELD_INPUT,
ADD_FILTER_FORM_OPERATOR_OPTION_IS,
ADD_FILTER_FORM_OPERATOR_FIELD,
ADD_FILTER_FORM_FIELD_OPTION,
ADD_FILTER_FORM_FILTER_VALUE_INPUT,
} from '../screens/search_bar';

export const openAddFilterPopover = () => {
cy.get(GLOBAL_SEARCH_BAR_ADD_FILTER).click({ force: true });
};

export const fillAddFilterForm = ({ key, value }: SearchBarFilter) => {
cy.get(ADD_FILTER_FORM_FIELD_INPUT).type(key);
cy.get(ADD_FILTER_FORM_FIELD_OPTION(key)).click({ force: true });
cy.get(ADD_FILTER_FORM_OPERATOR_FIELD).click();
cy.get(ADD_FILTER_FORM_OPERATOR_OPTION_IS).click();
cy.get(ADD_FILTER_FORM_FILTER_VALUE_INPUT).type(value);
cy.get(ADD_FILTER_FORM_SAVE_BUTTON).click();
};