From f28d9674872faebd2f9fd2b5b52954e22c1af497 Mon Sep 17 00:00:00 2001 From: MadameSheema Date: Thu, 13 Aug 2020 17:30:52 +0200 Subject: [PATCH] [SIEM] Adds pin event to timeline cypress test (#74256) (#74862) * adds 'pin event' cypress test * refactors code Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../integration/timeline_events.spec.ts | 39 +++++++++++++++++++ .../cypress/screens/timeline.ts | 2 + .../cypress/tasks/timeline.ts | 9 +++++ 3 files changed, 50 insertions(+) create mode 100644 x-pack/plugins/security_solution/cypress/integration/timeline_events.spec.ts diff --git a/x-pack/plugins/security_solution/cypress/integration/timeline_events.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timeline_events.spec.ts new file mode 100644 index 0000000000000..549cd134a04a4 --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/integration/timeline_events.spec.ts @@ -0,0 +1,39 @@ +/* + * 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 { PIN_EVENT } from '../screens/timeline'; + +import { loginAndWaitForPage } from '../tasks/login'; +import { openTimeline } from '../tasks/security_main'; +import { pinFirstEvent, populateTimeline, unpinFirstEvent } from '../tasks/timeline'; + +import { HOSTS_URL } from '../urls/navigation'; + +describe('timeline events', () => { + before(() => { + loginAndWaitForPage(HOSTS_URL); + openTimeline(); + populateTimeline(); + }); + + after(() => { + unpinFirstEvent(); + }); + + it('pins the first event to the timeline', () => { + cy.server(); + cy.route('POST', '**/api/solutions/security/graphql').as('persistTimeline'); + + pinFirstEvent(); + + cy.wait('@persistTimeline', { timeout: 10000 }).then((response) => { + cy.wrap(response.status).should('eql', 200); + cy.wrap(response.xhr.responseText).should('include', 'persistPinnedEventOnTimeline'); + }); + + cy.get(PIN_EVENT).should('have.attr', 'aria-label', 'Pinned event'); + }); +}); diff --git a/x-pack/plugins/security_solution/cypress/screens/timeline.ts b/x-pack/plugins/security_solution/cypress/screens/timeline.ts index 14282b84b5ffc..68425731f149a 100644 --- a/x-pack/plugins/security_solution/cypress/screens/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/screens/timeline.ts @@ -19,6 +19,8 @@ export const ID_FIELD = '[data-test-subj="timeline"] [data-test-subj="field-name export const ID_TOGGLE_FIELD = '[data-test-subj="toggle-field-_id"]'; +export const PIN_EVENT = '[data-test-subj="pin"]'; + export const PROVIDER_BADGE = '[data-test-subj="providerBadge"]'; export const REMOVE_COLUMN = diff --git a/x-pack/plugins/security_solution/cypress/tasks/timeline.ts b/x-pack/plugins/security_solution/cypress/tasks/timeline.ts index 761fd2c1e6a0b..d5106f34cc9c5 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/timeline.ts @@ -12,6 +12,7 @@ import { ID_FIELD, ID_HEADER_FIELD, ID_TOGGLE_FIELD, + PIN_EVENT, SEARCH_OR_FILTER_CONTAINER, SERVER_SIDE_EVENT_COUNT, TIMELINE_DESCRIPTION, @@ -78,6 +79,10 @@ export const openTimelineSettings = () => { cy.get(TIMELINE_SETTINGS_ICON).trigger('click', { force: true }); }; +export const pinFirstEvent = () => { + cy.get(PIN_EVENT).first().click({ force: true }); +}; + export const populateTimeline = () => { executeTimelineKQL(hostExistsQuery); cy.get(SERVER_SIDE_EVENT_COUNT) @@ -88,6 +93,10 @@ export const populateTimeline = () => { }); }; +export const unpinFirstEvent = () => { + cy.get(PIN_EVENT).first().click({ force: true }); +}; + export const uncheckTimestampToggleField = () => { cy.get(TIMESTAMP_TOGGLE_FIELD).should('exist');