From d05a7e5740e35c91f483ba502c8c786f3aa97773 Mon Sep 17 00:00:00 2001 From: Angela Chuang <6295984+angorayc@users.noreply.github.com> Date: Tue, 15 Dec 2020 09:29:37 +0000 Subject: [PATCH] [Security Solution] Unskip timeline creation Cypress test (#85871) * fix cypress * add a comment --- .../integration/timeline_creation.spec.ts | 20 +++++++++++-------- .../cypress/objects/timeline.ts | 1 + .../cypress/screens/timeline.ts | 5 ++++- .../cypress/tasks/api_calls/timelines.ts | 15 ++++++++++++++ .../cypress/tasks/timelines.ts | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/cypress/integration/timeline_creation.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timeline_creation.spec.ts index 4009ac13ab120..f087c0348f6af 100644 --- a/x-pack/plugins/security_solution/cypress/integration/timeline_creation.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/timeline_creation.spec.ts @@ -8,12 +8,13 @@ import { timeline } from '../objects/timeline'; import { FAVORITE_TIMELINE, LOCKED_ICON, - NOTES, NOTES_TAB_BUTTON, // NOTES_COUNT, NOTES_TEXT_AREA, + NOTE_BY_NOTE_ID, PIN_EVENT, TIMELINE_DESCRIPTION, + TIMELINE_FILTER, // TIMELINE_FILTER, TIMELINE_QUERY, TIMELINE_TITLE, @@ -24,7 +25,7 @@ import { TIMELINES_NOTES_COUNT, TIMELINES_FAVORITE, } from '../screens/timelines'; -import { deleteTimeline } from '../tasks/api_calls/timelines'; +import { deleteTimeline, getTimelineById } from '../tasks/api_calls/timelines'; import { loginAndWaitForPage } from '../tasks/login'; import { openTimelineUsingToggle } from '../tasks/security_main'; @@ -46,11 +47,11 @@ import { openTimeline } from '../tasks/timelines'; import { OVERVIEW_URL } from '../urls/navigation'; // FLAKY: https://github.com/elastic/kibana/issues/79389 -describe.skip('Timelines', () => { +describe('Timelines', () => { let timelineId: string; after(() => { - deleteTimeline(timelineId); + if (timelineId) deleteTimeline(timelineId); }); it('Creates a timeline', () => { @@ -90,13 +91,16 @@ describe.skip('Timelines', () => { cy.get(TIMELINE_TITLE).should('have.text', timeline.title); cy.get(TIMELINE_DESCRIPTION).should('have.text', timeline.description); cy.get(TIMELINE_QUERY).should('have.text', `${timeline.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(TIMELINE_FILTER(timeline.filter)).should('exist'); cy.get(PIN_EVENT).should('have.attr', 'aria-label', 'Pinned event'); cy.get(NOTES_TAB_BUTTON).click(); cy.get(NOTES_TEXT_AREA).should('exist'); - cy.get(NOTES).should('have.text', timeline.notes); + + getTimelineById(timelineId).then((singleTimeline) => { + const noteId = singleTimeline!.body.data.getOneTimeline.notes[0].noteId; + + cy.get(`${NOTE_BY_NOTE_ID(noteId)} p`).should('have.text', timeline.notes); + }); }); }); }); diff --git a/x-pack/plugins/security_solution/cypress/objects/timeline.ts b/x-pack/plugins/security_solution/cypress/objects/timeline.ts index 1cfb0afd445bd..61c98f6186038 100644 --- a/x-pack/plugins/security_solution/cypress/objects/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/objects/timeline.ts @@ -25,6 +25,7 @@ export interface TimelineFilter { export const filter: TimelineFilter = { field: 'host.name', operator: 'exists', + value: 'exists', }; export const timeline: CompleteTimeline = { diff --git a/x-pack/plugins/security_solution/cypress/screens/timeline.ts b/x-pack/plugins/security_solution/cypress/screens/timeline.ts index 0f5e8c133f0d0..4972cba937584 100644 --- a/x-pack/plugins/security_solution/cypress/screens/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/screens/timeline.ts @@ -53,6 +53,8 @@ export const LOCKED_ICON = '[data-test-subj="timeline-date-picker-lock-button"]' export const NOTES = '[data-test-subj="note-card-body"]'; +export const NOTE_BY_NOTE_ID = (noteId: string) => `[data-test-subj="note-preview-${noteId}"]`; + export const NOTES_TEXT_AREA = '[data-test-subj="add-a-note"] textarea'; export const NOTES_TAB_BUTTON = '[data-test-subj="timelineTabs-notes"]'; @@ -103,7 +105,8 @@ export const TIMELINE_FIELDS_BUTTON = '[data-test-subj="timeline"] [data-test-subj="show-field-browser"]'; export const TIMELINE_FILTER = (filter: TimelineFilter) => { - return `[data-test-subj="filter filter-enabled filter-key-${filter.field} filter-value-${filter.value} filter-unpinned"]`; + // The space at the end of the line is required. We want to keep it until it is updated. + return `[data-test-subj="filter filter-enabled filter-key-${filter.field} filter-value-${filter.value} filter-unpinned "]`; }; export const TIMELINE_FILTER_FIELD = '[data-test-subj="filterFieldSuggestionList"]'; diff --git a/x-pack/plugins/security_solution/cypress/tasks/api_calls/timelines.ts b/x-pack/plugins/security_solution/cypress/tasks/api_calls/timelines.ts index f7d1a1967e197..32c2af1a1866b 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/api_calls/timelines.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/api_calls/timelines.ts @@ -108,3 +108,18 @@ export const deleteTimeline = (timelineId: string) => { headers: { 'kbn-xsrf': 'delete-signals' }, }); }; + +export const getTimelineById = (timelineId: string) => + cy.request({ + method: 'POST', + url: 'api/solutions/security/graphql', + body: { + operationName: 'GetOneTimeline', + variables: { + id: timelineId, + }, + query: + 'query GetOneTimeline($id: ID!, $timelineType: TimelineType) {\n getOneTimeline(id: $id, timelineType: $timelineType) {\n savedObjectId\n columns {\n aggregatable\n category\n columnHeaderType\n description\n example\n indexes\n id\n name\n searchable\n type\n __typename\n }\n dataProviders {\n id\n name\n enabled\n excluded\n kqlQuery\n type\n queryMatch {\n field\n displayField\n value\n displayValue\n operator\n __typename\n }\n and {\n id\n name\n enabled\n excluded\n kqlQuery\n type\n queryMatch {\n field\n displayField\n value\n displayValue\n operator\n __typename\n }\n __typename\n }\n __typename\n }\n dateRange {\n start\n end\n __typename\n }\n description\n eventType\n eventIdToNoteIds {\n eventId\n note\n timelineId\n noteId\n created\n createdBy\n timelineVersion\n updated\n updatedBy\n version\n __typename\n }\n excludedRowRendererIds\n favorite {\n fullName\n userName\n favoriteDate\n __typename\n }\n filters {\n meta {\n alias\n controlledBy\n disabled\n field\n formattedValue\n index\n key\n negate\n params\n type\n value\n __typename\n }\n query\n exists\n match_all\n missing\n range\n script\n __typename\n }\n kqlMode\n kqlQuery {\n filterQuery {\n kuery {\n kind\n expression\n __typename\n }\n serializedQuery\n __typename\n }\n __typename\n }\n indexNames\n notes {\n eventId\n note\n timelineId\n timelineVersion\n noteId\n created\n createdBy\n updated\n updatedBy\n version\n __typename\n }\n noteIds\n pinnedEventIds\n pinnedEventsSaveObject {\n pinnedEventId\n eventId\n timelineId\n created\n createdBy\n updated\n updatedBy\n version\n __typename\n }\n status\n title\n timelineType\n templateTimelineId\n templateTimelineVersion\n savedQueryId\n sort\n created\n createdBy\n updated\n updatedBy\n version\n __typename\n }\n}\n', + }, + headers: { 'kbn-xsrf': '' }, + }); diff --git a/x-pack/plugins/security_solution/cypress/tasks/timelines.ts b/x-pack/plugins/security_solution/cypress/tasks/timelines.ts index 1c5ce246a35b3..a04ecb1f9ccaa 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/timelines.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/timelines.ts @@ -19,7 +19,7 @@ export const exportTimeline = (timelineId: string) => { }; export const openTimeline = (id: string) => { - cy.get(TIMELINE(id)).click(); + cy.get(TIMELINE(id), { timeout: 500 }).click(); }; export const waitForTimelinesPanelToBeLoaded = () => {