Skip to content

Commit

Permalink
[Security Solution] Unskip timeline creation Cypress test (#85871)
Browse files Browse the repository at this point in the history
* fix cypress

* add a comment
  • Loading branch information
angorayc authored Dec 15, 2020
1 parent bd7e709 commit e261aa2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface TimelineFilter {
export const filter: TimelineFilter = {
field: 'host.name',
operator: 'exists',
value: 'exists',
};

export const timeline: CompleteTimeline = {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/security_solution/cypress/screens/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]';
Expand Down Expand Up @@ -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"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': '' },
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down

0 comments on commit e261aa2

Please sign in to comment.