diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/esql/search_filter.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/esql/search_filter.cy.ts index e54a78c5c6fd2..b0e5bcb397c0e 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/esql/search_filter.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/timelines/esql/search_filter.cy.ts @@ -5,9 +5,11 @@ * 2.0. */ +import { deleteTimelines } from '../../../../tasks/api_calls/common'; import { GET_LOCAL_DATE_PICKER_START_DATE_POPOVER_BUTTON } from '../../../../screens/date_picker'; import { setStartDate, + showStartEndDate, updateDateRangeInLocalDatePickers, updateDates, } from '../../../../tasks/date_picker'; @@ -21,20 +23,20 @@ import { addDiscoverEsqlQuery, submitDiscoverSearchBar, addFieldToTable, - convertNBSPToSP, + convertEditorNonBreakingSpaceToSpace, } from '../../../../tasks/discover'; -import { createNewTimeline, goToEsqlTab } from '../../../../tasks/timeline'; +import { createNewTimeline, goToEsqlTab, openActiveTimeline } from '../../../../tasks/timeline'; import { login } from '../../../../tasks/login'; import { visitWithTimeRange } from '../../../../tasks/navigation'; import { ALERTS_URL } from '../../../../urls/navigation'; +const DEFAULT_DATE = '~ 15 minutes ago'; const INITIAL_START_DATE = 'Jan 18, 2021 @ 20:33:29.186'; const INITIAL_END_DATE = 'Jan 19, 2024 @ 20:33:29.186'; const NEW_START_DATE = 'Jan 18, 2023 @ 20:33:29.186'; const esqlQuery = 'from auditbeat-* | where ecs.version == "8.0.0"'; -// FLAKY: https://github.com/elastic/kibana/issues/168758 -describe.skip( +describe( 'Basic esql search and filter operations', { tags: ['@ess'], @@ -42,17 +44,20 @@ describe.skip( () => { beforeEach(() => { login(); + deleteTimelines(); visitWithTimeRange(ALERTS_URL); + openActiveTimeline(); createNewTimeline(); goToEsqlTab(); updateDateRangeInLocalDatePickers(DISCOVER_CONTAINER, INITIAL_START_DATE, INITIAL_END_DATE); }); - it('should show data according to esql query', () => { + it('should show data according to the esql query', () => { addDiscoverEsqlQuery(`${esqlQuery} | limit 1`); submitDiscoverSearchBar(); cy.get(DISCOVER_RESULT_HITS).should('have.text', 1); }); + it('should be able to add fields to the table', () => { addFieldToTable('host.name'); addFieldToTable('user.name'); @@ -60,34 +65,32 @@ describe.skip( cy.get(GET_DISCOVER_DATA_GRID_CELL_HEADER('user.name')).should('be.visible'); }); - context('navigation', () => { - it('should remove the query when back is pressed after adding a query', () => { - addDiscoverEsqlQuery(esqlQuery); - submitDiscoverSearchBar(); - cy.get(DISCOVER_ESQL_INPUT_TEXT_CONTAINER).then((subj) => { - const currentQuery = subj.text(); - const sanitizedQuery = convertNBSPToSP(currentQuery); - expect(sanitizedQuery).to.eq(esqlQuery); - }); - cy.go('back'); - cy.get(DISCOVER_ESQL_INPUT_TEXT_CONTAINER).then((subj) => { - const currentQuery = subj.text(); - const sanitizedQuery = convertNBSPToSP(currentQuery); - expect(sanitizedQuery).to.not.eq(esqlQuery); - }); + it('should remove the query when the back button is pressed after adding a query', () => { + addDiscoverEsqlQuery(esqlQuery); + submitDiscoverSearchBar(); + cy.get(DISCOVER_ESQL_INPUT_TEXT_CONTAINER).then((subj) => { + const currentQuery = subj.text(); + const sanitizedQuery = convertEditorNonBreakingSpaceToSpace(currentQuery); + expect(sanitizedQuery).to.eq(esqlQuery); }); + cy.go('back'); + cy.get(DISCOVER_ESQL_INPUT_TEXT_CONTAINER).then((subj) => { + const currentQuery = subj.text(); + const sanitizedQuery = convertEditorNonBreakingSpaceToSpace(currentQuery); + expect(sanitizedQuery).to.not.eq(esqlQuery); + }); + }); - it(`should changed the timerange to ${INITIAL_START_DATE} when back is pressed after modifying timerange from ${INITIAL_START_DATE} to ${NEW_START_DATE} `, () => { - setStartDate(NEW_START_DATE, DISCOVER_CONTAINER); - updateDates(DISCOVER_CONTAINER); - - cy.go('back'); + it(`should change the timerange to ${DEFAULT_DATE} when back is pressed after modifying timerange to ${NEW_START_DATE} without saving`, () => { + setStartDate(NEW_START_DATE, DISCOVER_CONTAINER); + updateDates(DISCOVER_CONTAINER); - cy.get(GET_LOCAL_DATE_PICKER_START_DATE_POPOVER_BUTTON(DISCOVER_CONTAINER)).should( - 'have.text', - INITIAL_START_DATE - ); - }); + cy.go('back'); + showStartEndDate(DISCOVER_CONTAINER); + cy.get(GET_LOCAL_DATE_PICKER_START_DATE_POPOVER_BUTTON(DISCOVER_CONTAINER)).should( + 'have.text', + DEFAULT_DATE + ); }); } ); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/discover.ts b/x-pack/test/security_solution_cypress/cypress/tasks/discover.ts index 4402e1c65f477..364f292124913 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/discover.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/discover.ts @@ -64,7 +64,7 @@ export const addDiscoverEsqlQuery = (esqlQuery: string) => { cy.get(GET_LOCAL_SEARCH_BAR_SUBMIT_BUTTON(DISCOVER_CONTAINER)).realClick(); }; -export const convertNBSPToSP = (str: string) => { +export const convertEditorNonBreakingSpaceToSpace = (str: string) => { return str.replaceAll(String.fromCharCode(160), ' '); };