Skip to content

Commit

Permalink
[Investigations] - Fix search_filter tests (#173325)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelolo24 authored Dec 18, 2023
1 parent c86c9e5 commit 8a53f32
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,73 +23,74 @@ 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'],
},
() => {
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');
cy.get(GET_DISCOVER_DATA_GRID_CELL_HEADER('host.name')).should('be.visible');
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
);
});
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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), ' ');
};

Expand Down

0 comments on commit 8a53f32

Please sign in to comment.