From a8d3173b18f7f207fd53da722c425ceba42f0d8a Mon Sep 17 00:00:00 2001 From: Jan Monschke Date: Fri, 12 Jan 2024 04:23:30 +0100 Subject: [PATCH] [SecuritySolution] Unskip fields browser timeline tests (#174597) --- .../field_browser/field_browser.test.tsx | 5 + .../timelines/fields_browser.cy.ts | 95 ++++++------------- .../cypress/tasks/fields_browser.ts | 24 ++--- .../cypress/tasks/timeline.ts | 2 +- 4 files changed, 46 insertions(+), 80 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/field_browser/field_browser.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/field_browser/field_browser.test.tsx index 5c3a33d5b17c8..32a6b1b85019b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/field_browser/field_browser.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/field_browser/field_browser.test.tsx @@ -42,7 +42,12 @@ describe('FieldsBrowser', () => { result.getByTestId('show-field-browser').click(); await waitFor(() => { + // the container is rendered now expect(result.getByTestId('fields-browser-container')).toBeInTheDocument(); + // by default, no categories are selected + expect(result.getByTestId('category-badges')).toHaveTextContent(''); + // the view: all button is shown by default + result.getByText('View: all'); }); }); }); diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/fields_browser.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/fields_browser.cy.ts index 776770060e85b..efa1b50ee8147 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/fields_browser.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/fields_browser.cy.ts @@ -13,9 +13,7 @@ import { FIELDS_BROWSER_MESSAGE_HEADER, FIELDS_BROWSER_FILTER_INPUT, FIELDS_BROWSER_CATEGORIES_FILTER_CONTAINER, - FIELDS_BROWSER_SELECTED_CATEGORIES_BADGES, FIELDS_BROWSER_CATEGORY_BADGE, - FIELDS_BROWSER_VIEW_BUTTON, } from '../../../screens/fields_browser'; import { TIMELINE_FIELDS_BUTTON } from '../../../screens/timeline'; @@ -29,12 +27,11 @@ import { resetFields, toggleCategory, activateViewSelected, - activateViewAll, } from '../../../tasks/fields_browser'; import { login } from '../../../tasks/login'; import { visitWithTimeRange } from '../../../tasks/navigation'; import { openTimelineUsingToggle } from '../../../tasks/security_main'; -import { openTimelineFieldsBrowser, populateTimeline } from '../../../tasks/timeline'; +import { openTimelineFieldsBrowser } from '../../../tasks/timeline'; import { hostsUrl } from '../../../urls/navigation'; @@ -49,102 +46,75 @@ const defaultHeaders = [ { id: 'user.name' }, ]; -// Flaky in serverless tests -// FLAKY: https://github.com/elastic/kibana/issues/169363 -describe.skip('Fields Browser', { tags: ['@ess', '@serverless'] }, () => { - context('Fields Browser rendering', () => { - beforeEach(() => { - login(); - visitWithTimeRange(hostsUrl('allHosts')); - openTimelineUsingToggle(); - populateTimeline(); - openTimelineFieldsBrowser(); - }); - - it('displays all categories (by default)', () => { - cy.get(FIELDS_BROWSER_SELECTED_CATEGORIES_BADGES).should('be.empty'); - }); - - it('displays "view all" option by default', () => { - cy.get(FIELDS_BROWSER_VIEW_BUTTON).should('contain.text', 'View: all'); - }); +describe('Fields Browser', { tags: ['@ess', '@serverless'] }, () => { + beforeEach(() => { + login(); + visitWithTimeRange(hostsUrl('allHosts')); + openTimelineUsingToggle(); + openTimelineFieldsBrowser(); + }); - it('displays the expected count of categories that match the filter input', () => { + describe('Fields Browser rendering', () => { + it('should display the expected count of categories and fields that match the filter input', () => { const filterInput = 'host.mac'; filterFieldsBrowser(filterInput); cy.get(FIELDS_BROWSER_CATEGORIES_COUNT).should('have.text', '2'); - }); - - it('displays a search results label with the expected count of fields matching the filter input', () => { - const filterInput = 'host.mac'; - filterFieldsBrowser(filterInput); - cy.get(FIELDS_BROWSER_FIELDS_COUNT).should('contain.text', '2'); }); - it('displays only the selected fields when "view selected" option is enabled', () => { + it('should display only the selected fields when "view selected" option is enabled', () => { activateViewSelected(); cy.get(FIELDS_BROWSER_FIELDS_COUNT).should('contain.text', `${defaultHeaders.length}`); defaultHeaders.forEach((header) => { cy.get(`[data-test-subj="field-${header.id}-checkbox"]`).should('be.checked'); }); - activateViewAll(); }); - it('creates the category badge when it is selected', () => { + it('should create the category badge when it is selected', () => { const category = 'host'; + const categoryCheck = 'event'; cy.get(FIELDS_BROWSER_CATEGORY_BADGE(category)).should('not.exist'); + toggleCategory(category); + cy.get(FIELDS_BROWSER_CATEGORY_BADGE(category)).should('exist'); + toggleCategory(category); - }); - it('search a category should match the category in the category filter', () => { - const category = 'host'; + cy.log('the category filter should contain the filtered category'); filterFieldsBrowser(category); toggleCategoryFilter(); + cy.get(FIELDS_BROWSER_CATEGORIES_FILTER_CONTAINER).should('contain.text', category); - }); - it('search a category should filter out non matching categories in the category filter', () => { - const category = 'host'; - const categoryCheck = 'event'; - filterFieldsBrowser(category); - toggleCategoryFilter(); + cy.log('non-matching categories should not be listed in the category filter'); + cy.get(FIELDS_BROWSER_CATEGORIES_FILTER_CONTAINER).should('not.contain.text', categoryCheck); }); }); - context('Editing the timeline', () => { - beforeEach(() => { - login(); - visitWithTimeRange(hostsUrl('allHosts')); - openTimelineUsingToggle(); - populateTimeline(); - openTimelineFieldsBrowser(); - }); + describe('Editing the timeline', () => { + it('should add/remove columns from the alerts table when the user checks/un-checks them', () => { + const filterInput = 'host.geo.c'; + + cy.log('removing the message column'); - it('removes the message field from the timeline when the user un-checks the field', () => { cy.get(FIELDS_BROWSER_MESSAGE_HEADER).should('exist'); removesMessageField(); closeFieldsBrowser(); cy.get(FIELDS_BROWSER_MESSAGE_HEADER).should('not.exist'); - }); - it('adds a field to the timeline when the user clicks the checkbox', () => { - const filterInput = 'host.geo.c'; + cy.log('add host.geo.city_name column'); - closeFieldsBrowser(); cy.get(FIELDS_BROWSER_HOST_GEO_CITY_NAME_HEADER).should('not.exist'); openTimelineFieldsBrowser(); - filterFieldsBrowser(filterInput); addsHostGeoCityNameToTimeline(); closeFieldsBrowser(); @@ -152,7 +122,7 @@ describe.skip('Fields Browser', { tags: ['@ess', '@serverless'] }, () => { cy.get(FIELDS_BROWSER_HOST_GEO_CITY_NAME_HEADER).should('exist'); }); - it('resets all fields in the timeline when `Reset Fields` is clicked', () => { + it('should reset all fields in the timeline when `Reset Fields` is clicked', () => { const filterInput = 'host.geo.c'; filterFieldsBrowser(filterInput); @@ -168,19 +138,16 @@ describe.skip('Fields Browser', { tags: ['@ess', '@serverless'] }, () => { resetFields(); cy.get(FIELDS_BROWSER_HEADER_HOST_GEO_CONTINENT_NAME_HEADER).should('not.exist'); - }); - it('restores focus to the Customize Columns button when `Reset Fields` is clicked', () => { - openTimelineFieldsBrowser(); - resetFields(); + cy.log('restores focus to the Customize Columns button when `Reset Fields` is clicked'); cy.get(TIMELINE_FIELDS_BUTTON).should('have.focus'); - }); - it('restores focus to the Customize Columns button when Esc is pressed', () => { + cy.log('restores focus to the Customize Columns button when Esc is pressed'); + openTimelineFieldsBrowser(); - cy.get(FIELDS_BROWSER_FILTER_INPUT).type('{esc}'); + cy.get(FIELDS_BROWSER_FILTER_INPUT).type('{esc}'); cy.get(TIMELINE_FIELDS_BUTTON).should('have.focus'); }); }); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/fields_browser.ts b/x-pack/test/security_solution_cypress/cypress/tasks/fields_browser.ts index c31196a96a550..f9e83fb449b77 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/fields_browser.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/fields_browser.ts @@ -29,15 +29,11 @@ export const addsFields = (fields: string[]) => { }; export const addsHostGeoCityNameToTimeline = () => { - cy.get(FIELDS_BROWSER_HOST_GEO_CITY_NAME_CHECKBOX).check({ - force: true, - }); + cy.get(FIELDS_BROWSER_HOST_GEO_CITY_NAME_CHECKBOX).check(); }; export const addsHostGeoContinentNameToTimeline = () => { - cy.get(FIELDS_BROWSER_HOST_GEO_CONTINENT_NAME_CHECKBOX).check({ - force: true, - }); + cy.get(FIELDS_BROWSER_HOST_GEO_CONTINENT_NAME_CHECKBOX).check(); }; export const clearFieldsBrowser = () => { @@ -67,7 +63,7 @@ export const filterFieldsBrowser = (fieldName: string) => { }; export const toggleCategoryFilter = () => { - cy.get(FIELDS_BROWSER_CATEGORIES_FILTER_BUTTON).click({ force: true }); + cy.get(FIELDS_BROWSER_CATEGORIES_FILTER_BUTTON).click(); }; export const toggleCategory = (category: string) => { @@ -79,9 +75,7 @@ export const toggleCategory = (category: string) => { }; export const removesMessageField = () => { - cy.get(FIELDS_BROWSER_MESSAGE_CHECKBOX).uncheck({ - force: true, - }); + cy.get(FIELDS_BROWSER_MESSAGE_CHECKBOX).uncheck(); }; export const removeField = (fieldName: string) => { @@ -89,14 +83,14 @@ export const removeField = (fieldName: string) => { }; export const resetFields = () => { - cy.get(FIELDS_BROWSER_RESET_FIELDS).click({ force: true }); + cy.get(FIELDS_BROWSER_RESET_FIELDS).click(); }; export const activateViewSelected = () => { - cy.get(FIELDS_BROWSER_VIEW_BUTTON).click({ force: true }); - cy.get(FIELDS_BROWSER_VIEW_SELECTED).click({ force: true }); + cy.get(FIELDS_BROWSER_VIEW_BUTTON).click(); + cy.get(FIELDS_BROWSER_VIEW_SELECTED).click(); }; export const activateViewAll = () => { - cy.get(FIELDS_BROWSER_VIEW_BUTTON).click({ force: true }); - cy.get(FIELDS_BROWSER_VIEW_ALL).click({ force: true }); + cy.get(FIELDS_BROWSER_VIEW_BUTTON).click(); + cy.get(FIELDS_BROWSER_VIEW_ALL).click(); }; diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts b/x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts index 35248f80ca895..d8543ec852c17 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts @@ -370,7 +370,7 @@ export const markAsFavorite = () => { }; export const openTimelineFieldsBrowser = () => { - cy.get(TIMELINE_FIELDS_BUTTON).first().click({ force: true }); + cy.get(TIMELINE_FIELDS_BUTTON).first().click(); }; export const openTimelineInspectButton = () => {