Skip to content

Commit

Permalink
fix flaky timeline template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed Dec 12, 2023
1 parent c14d94f commit 6515df5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,90 @@
import { getTimeline } from '../../../objects/timeline';

import {
FAVORITE_TIMELINE,
LOCKED_ICON,
NOTES,
NOTES_TAB_BUTTON,
NOTES_TEXT_AREA,
PIN_EVENT,
TIMELINE_DESCRIPTION,
TIMELINE_FLYOUT_WRAPPER,
TIMELINE_QUERY,
TIMELINE_TITLE,
TIMELINE_DATE_PICKER_CONTAINER,
} from '../../../screens/timeline';
import {
TIMELINES_DESCRIPTION,
TIMELINES_PINNED_EVENT_COUNT,
TIMELINES_NOTES_COUNT,
TIMELINES_FAVORITE,
} from '../../../screens/timelines';
import { TIMELINES_DESCRIPTION, TIMELINES_FAVORITE } from '../../../screens/timelines';
import { createTimeline } from '../../../tasks/api_calls/timelines';
import { deleteTimelines } from '../../../tasks/api_calls/common';

import { login } from '../../../tasks/login';
import { visit } from '../../../tasks/navigation';
import { openTimelineUsingToggle } from '../../../tasks/security_main';
import {
addDescriptionToTimeline,
addFilter,
addNameToTimelineAndSave,
addNotesToTimeline,
clickingOnCreateTemplateFromTimelineBtn,
closeTimeline,
createNewTimelineTemplate,
expandEventAction,
markAsFavorite,
openTimelineTemplateFromSettings,
openTimelineTemplate,
populateTimeline,
addNameAndDescriptionToTimeline,
openTimelineTemplatesTab,
} from '../../../tasks/timeline';
import { openTimeline, waitForTimelinesPanelToBeLoaded } from '../../../tasks/timelines';
import {
updateTimelineDates,
showStartEndDate,
setStartDate,
setEndDateNow,
} from '../../../tasks/date_picker';
import { waitForTimelinesPanelToBeLoaded } from '../../../tasks/timelines';

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

// FLAKY: https://github.com/elastic/kibana/issues/165661
describe('Timeline Templates', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
deleteTimelines();
cy.intercept('PATCH', '/api/timeline').as('timeline');
});

it.skip('Creates a timeline template', () => {
it('Creates a timeline template', () => {
createTimeline(getTimeline());
visit(TIMELINES_URL);
waitForTimelinesPanelToBeLoaded();
openTimelineUsingToggle();

createNewTimelineTemplate();
populateTimeline();
addFilter(getTimeline().filter);

showStartEndDate(TIMELINE_DATE_PICKER_CONTAINER);
setEndDateNow(TIMELINE_DATE_PICKER_CONTAINER);
setStartDate('Jan 18, 2018 @ 00:00:00.000', TIMELINE_DATE_PICKER_CONTAINER);
updateTimelineDates();

cy.get(PIN_EVENT).should(
'have.attr',
'aria-label',
'This event may not be pinned while editing a template timeline'
);
cy.get(LOCKED_ICON).should('be.visible');

addNameToTimelineAndSave(getTimeline().title);
addNameAndDescriptionToTimeline(getTimeline());

cy.wait('@timeline').then(({ response }) => {
const timelineId = response?.body.data.persistTimeline.timeline.savedObjectId;

addDescriptionToTimeline(getTimeline().description);
addNotesToTimeline(getTimeline().notes);
markAsFavorite();
createNewTimelineTemplate();
closeTimeline();
openTimelineTemplateFromSettings(timelineId);

openTimelineTemplatesTab();
openTimelineTemplate(timelineId);

cy.contains(getTimeline().title).should('exist');
cy.get(TIMELINE_TITLE).should('have.text', getTimeline().title);
cy.get(TIMELINES_DESCRIPTION).first().should('have.text', getTimeline().description);
cy.get(TIMELINES_PINNED_EVENT_COUNT).first().should('have.text', '1');
cy.get(TIMELINES_NOTES_COUNT).first().should('have.text', '1');
cy.get(TIMELINES_FAVORITE).first().should('exist');

openTimeline(timelineId);

cy.get(FAVORITE_TIMELINE).should('exist');
cy.get(TIMELINE_TITLE).should('have.text', getTimeline().title);
cy.get(TIMELINE_DESCRIPTION).should('have.text', getTimeline().description);
cy.get(TIMELINE_QUERY).should('have.text', getTimeline().query);
cy.get(TIMELINE_QUERY).should('contain.text', getTimeline().query);
// Comments this assertion until we agreed what to do with the filters.
// cy.get(TIMELINE_FILTER(timeline.filter)).should('exist');
// cy.get(NOTES_COUNT).should('have.text', '1');
cy.get(NOTES_TAB_BUTTON).click();
cy.get(NOTES_TEXT_AREA).should('exist');
cy.get(NOTES).should('have.text', getTimeline().notes);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export const CORRELATION_EVENT_TABLE_CELL =

export const CLOSE_TIMELINE_BTN = '[data-test-subj="close-timeline"]';

export const COMBO_BOX = 'button.euiFilterSelectItem[role="option"]';

export const COMBO_BOX_INPUT = '[data-test-subj="comboBoxInput"]';

export const CREATE_NEW_TIMELINE = '[data-test-subj="timeline-new"]';
Expand Down Expand Up @@ -110,9 +108,6 @@ export const OPEN_TIMELINE_MODAL = '[data-test-subj="open-timeline-modal"]';

export const CLOSE_OPEN_TIMELINE_MODAL_BTN = `${OPEN_TIMELINE_MODAL} > button`;

export const OPEN_TIMELINE_TEMPLATE_ICON =
'[data-test-subj="open-timeline-modal-body-filter-template"]';

export const PIN_EVENT = '[data-test-subj="pin"]';

export const PINNED_TAB_BUTTON = '[data-test-subj="timelineTabs-pinned"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ export const TIMELINES_OVERVIEW_SEARCH = `${TIMELINES_OVERVIEW} [data-test-subj=
export const TIMELINES_OVERVIEW_TABLE = `${TIMELINES_OVERVIEW} [data-test-subj="timelines-table"]`;

export const ROWS = '.euiTableRow';

export const TIMELINES_TAB_TEMPLATE = '[data-test-subj="timeline-tab-template"]';
17 changes: 8 additions & 9 deletions x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ATTACH_TIMELINE_TO_EXISTING_CASE_ICON,
ATTACH_TIMELINE_TO_NEW_CASE_ICON,
CLOSE_TIMELINE_BTN,
COMBO_BOX,
COMBO_BOX_INPUT,
CREATE_NEW_TIMELINE,
DELETE_TIMELINE_BTN,
Expand Down Expand Up @@ -52,7 +51,6 @@ import {
TIMESTAMP_TOGGLE_FIELD,
TOGGLE_TIMELINE_EXPAND_EVENT,
CREATE_NEW_TIMELINE_TEMPLATE,
OPEN_TIMELINE_TEMPLATE_ICON,
TIMELINE_SAVE_MODAL,
TIMELINE_EDIT_MODAL_SAVE_BUTTON,
TIMELINE_EDIT_MODAL_SAVE_AS_NEW_SWITCH,
Expand Down Expand Up @@ -94,7 +92,7 @@ import {
TOGGLE_DATA_PROVIDER_BTN,
SAVE_TIMELINE_ACTION_BTN,
} from '../screens/timeline';
import { REFRESH_BUTTON, TIMELINE } from '../screens/timelines';
import { REFRESH_BUTTON, TIMELINE, TIMELINES_TAB_TEMPLATE } from '../screens/timelines';
import { drag, drop } from './common';

import { closeFieldsBrowser, filterFieldsBrowser } from './fields_browser';
Expand Down Expand Up @@ -211,8 +209,7 @@ export const addEqlToTimeline = (eql: string) => {
export const addFilter = (filter: TimelineFilter): Cypress.Chainable<JQuery<HTMLElement>> => {
cy.get(ADD_FILTER).click();
cy.get(TIMELINE_FILTER_FIELD).type(`${filter.field}{downarrow}{enter}`);
cy.get(TIMELINE_FILTER_OPERATOR).type(filter.operator);
cy.get(COMBO_BOX).contains(filter.operator).trigger('click');
cy.get(TIMELINE_FILTER_OPERATOR).type(`${filter.operator}{downarrow}{enter}`);
if (filter.operator !== 'exists') {
cy.get(TIMELINE_FILTER_VALUE).type(`${filter.value}{enter}`);
}
Expand Down Expand Up @@ -403,10 +400,12 @@ export const openTimelineFromSettings = () => {
cy.get(OPEN_TIMELINE_ICON).click();
};

export const openTimelineTemplateFromSettings = (id: string) => {
openTimelineFromSettings();
cy.get(OPEN_TIMELINE_TEMPLATE_ICON).click({ force: true });
cy.get(TIMELINE_TITLE_BY_ID(id)).click({ force: true });
export const openTimelineTemplate = (id: string) => {
cy.get(TIMELINE_TITLE_BY_ID(id)).click();
};

export const openTimelineTemplatesTab = () => {
cy.get(TIMELINES_TAB_TEMPLATE).click();
};

export const openTimelineById = (timelineId: string): Cypress.Chainable<JQuery<HTMLElement>> => {
Expand Down
11 changes: 10 additions & 1 deletion x-pack/test/security_solution_cypress/cypress/tasks/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
TIMELINE_ITEM_ACTION_BTN,
} from '../screens/timelines';
import { SELECT_ALL_CHECKBOX } from '../screens/shared';
import { CREATE_NEW_TIMELINE_WITH_BORDER } from '../screens/timeline';
import {
CREATE_NEW_TIMELINE_WITH_BORDER,
TIMELINE_COLLAPSED_ITEMS_BTN,
TIMELINE_CREATE_TIMELINE_FROM_TEMPLATE_BTN,
} from '../screens/timeline';

export const expandNotes = () => {
cy.get(EXPAND_NOTES_BTN).click();
Expand Down Expand Up @@ -66,3 +70,8 @@ export const exportSelectedTimelines = () => {
};

export const createTimeline = () => cy.get(CREATE_NEW_TIMELINE_WITH_BORDER).click();

export const createTimelineFromFirstTemplateInList = () => {
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).first().click();
cy.get(TIMELINE_CREATE_TIMELINE_FROM_TEMPLATE_BTN).click();
};

0 comments on commit 6515df5

Please sign in to comment.