Skip to content

Commit

Permalink
[SecuritySolution] Move manual test cases to Cypress (#100730)
Browse files Browse the repository at this point in the history
* add scenarios 1-3

* add tests for toggle full screen

* add tests for timeline pagination

* add tests for timeline correlation tab

* fix cypress tests

* add data-test-subj for timeline tabs content

* fix up

* fix flaky tests

* fix mark as favorite scenario

* fix flaky test

* fix flaky test

* fix flaky test

* refactors 'can be marked as favourite' test

* fixes test

* fixes typecheck issue

* refactors the pipe

* little fix

* mark as favourite refactor

* removes code that causes the flakiness

* apply the fix for 7.13 branch

* fix timeline api call

* fix timeline api call

* fix timeline api call

* fix syntax

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Gloria Hornero <[email protected]>
  • Loading branch information
3 people authored Jun 21, 2021
1 parent 1fb2640 commit 62eece5
Show file tree
Hide file tree
Showing 23 changed files with 595 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { createTimeline } from '../../tasks/api_calls/timelines';
import { cleanKibana } from '../../tasks/common';
import { createCase } from '../../tasks/api_calls/cases';

// TODO: enable once attach timeline to cases is re-enabled
describe.skip('attach timeline to case', () => {
describe('attach timeline to case', () => {
context('without cases created', () => {
beforeEach(() => {
cleanKibana();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { OVERVIEW_URL } from '../../urls/navigation';
import overviewFixture from '../../fixtures/overview_search_strategy.json';
import emptyInstance from '../../fixtures/empty_instance.json';
import { cleanKibana } from '../../tasks/common';
import { createTimeline, favoriteTimeline } from '../../tasks/api_calls/timelines';
import { timeline } from '../../objects/timeline';

describe('Overview Page', () => {
before(() => {
Expand Down Expand Up @@ -48,4 +50,21 @@ describe('Overview Page', () => {
cy.get(OVERVIEW_EMPTY_PAGE).should('be.visible');
});
});

describe('Favorite Timelines', () => {
it('should appear on overview page', () => {
createTimeline(timeline)
.then((response) => response.body.data.persistTimeline.timeline.savedObjectId)
.then((timelineId: string) => {
favoriteTimeline({ timelineId, timelineType: 'default' }).then(() => {
cy.stubSearchStrategyApi(overviewFixture, 'overviewNetwork');
loginAndWaitForPage(OVERVIEW_URL);
cy.get('[data-test-subj="overview-recent-timelines"]').should(
'contain',
timeline.title
);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
NOTES_TEXT_AREA,
PIN_EVENT,
TIMELINE_DESCRIPTION,
TIMELINE_FLYOUT_WRAPPER,
TIMELINE_QUERY,
TIMELINE_TITLE,
} from '../../screens/timeline';
Expand All @@ -25,34 +26,38 @@ import {
TIMELINES_NOTES_COUNT,
TIMELINES_FAVORITE,
} from '../../screens/timelines';
import { createTimeline } from '../../tasks/api_calls/timelines';
import { cleanKibana } from '../../tasks/common';

import { loginAndWaitForPage } from '../../tasks/login';
import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import { openTimelineUsingToggle } from '../../tasks/security_main';
import {
addDescriptionToTimeline,
addFilter,
addNameToTimeline,
addNotesToTimeline,
clickingOnCreateTemplateFromTimelineBtn,
closeTimeline,
createNewTimelineTemplate,
expandEventAction,
markAsFavorite,
openTimelineTemplateFromSettings,
populateTimeline,
waitForTimelineChanges,
} from '../../tasks/timeline';
import { openTimeline } from '../../tasks/timelines';
import { openTimeline, waitForTimelinesPanelToBeLoaded } from '../../tasks/timelines';

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

describe('Timeline Templates', () => {
beforeEach(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(TIMELINES_URL);

cy.intercept('PATCH', '/api/timeline').as('timeline');
});

it('Creates a timeline template', async () => {
loginAndWaitForPage(OVERVIEW_URL);
openTimelineUsingToggle();
createNewTimelineTemplate();
populateTimeline();
Expand Down Expand Up @@ -97,4 +102,22 @@ describe('Timeline Templates', () => {
cy.get(NOTES).should('have.text', timeline.notes);
});
});

it('Create template from timeline', () => {
waitForTimelinesPanelToBeLoaded();

createTimeline(timeline).then(() => {
expandEventAction();
clickingOnCreateTemplateFromTimelineBtn();
cy.wait('@timeline', { timeout: 100000 }).then(({ request }) => {
expect(request.body.timeline).to.haveOwnProperty('templateTimelineId');
expect(request.body.timeline).to.haveOwnProperty('description', timeline.description);
expect(request.body.timeline.kqlQuery.filterQuery.kuery).to.haveOwnProperty(
'expression',
timeline.query
);
cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,37 @@
import { timeline } from '../../objects/timeline';

import {
FAVORITE_TIMELINE,
LOCKED_ICON,
NOTES_TEXT,
PIN_EVENT,
SERVER_SIDE_EVENT_COUNT,
TIMELINE_FILTER,
TIMELINE_FLYOUT_WRAPPER,
TIMELINE_PANEL,
TIMELINE_TAB_CONTENT_EQL,
} from '../../screens/timeline';
import { createTimelineTemplate } from '../../tasks/api_calls/timelines';

import { cleanKibana } from '../../tasks/common';

import { loginAndWaitForPage } from '../../tasks/login';
import { loginAndWaitForPage, loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import { openTimelineUsingToggle } from '../../tasks/security_main';
import {
addEqlToTimeline,
addFilter,
addNameAndDescriptionToTimeline,
addNotesToTimeline,
clickingOnCreateTimelineFormTemplateBtn,
closeTimeline,
createNewTimeline,
expandEventAction,
goToQueryTab,
markAsFavorite,
pinFirstEvent,
populateTimeline,
waitForTimelineChanges,
} from '../../tasks/timeline';

import { OVERVIEW_URL } from '../../urls/navigation';
import { OVERVIEW_URL, TIMELINE_TEMPLATES_URL } from '../../urls/navigation';
import { waitForTimelinesPanelToBeLoaded } from '../../tasks/timelines';

describe('Timelines', (): void => {
before(() => {
Expand Down Expand Up @@ -88,10 +93,44 @@ describe('Timelines', (): void => {
cy.get(NOTES_TEXT).should('have.text', timeline.notes);
});

it('can be marked as favorite', () => {
markAsFavorite();
waitForTimelineChanges();
cy.get(FAVORITE_TIMELINE).should('have.text', 'Remove from favorites');
it('should update timeline after adding eql', () => {
cy.intercept('PATCH', '/api/timeline').as('updateTimeline');
const eql = 'any where process.name == "which"';
addEqlToTimeline(eql);

cy.wait('@updateTimeline', { timeout: 10000 }).its('response.statusCode').should('eq', 200);

cy.get(`${TIMELINE_TAB_CONTENT_EQL} ${SERVER_SIDE_EVENT_COUNT}`)
.invoke('text')
.then(parseInt)
.should('be.gt', 0);
});
});
});

describe('Create a timeline from a template', () => {
before(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(TIMELINE_TEMPLATES_URL);
waitForTimelinesPanelToBeLoaded();
});

it('Should have the same query and open the timeline modal', () => {
createTimelineTemplate(timeline).then(() => {
expandEventAction();
cy.intercept('/api/timeline').as('timeline');

clickingOnCreateTimelineFormTemplateBtn();
cy.wait('@timeline', { timeout: 100000 }).then(({ request }) => {
if (request.body && request.body.timeline) {
expect(request.body.timeline).to.haveOwnProperty('description', timeline.description);
expect(request.body.timeline.kqlQuery.filterQuery.kuery).to.haveOwnProperty(
'expression',
timeline.query
);
cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
}
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ describe('timeline flyout button', () => {

it('the `(+)` button popover menu owns focus', () => {
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').click({ force: true });
cy.get(CREATE_NEW_TIMELINE).should('have.focus');
cy.get('body').type('{esc}');
cy.get(`${CREATE_NEW_TIMELINE}`)
.pipe(($el) => $el.trigger('focus'))
.should('have.focus');
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').type('{esc}');
cy.get(CREATE_NEW_TIMELINE).should('not.be.visible');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TIMELINE_HEADER, TIMELINE_TABS } from '../../screens/timeline';
import { cleanKibana } from '../../tasks/common';

import { loginAndWaitForPage } from '../../tasks/login';
import {
openTimelineUsingToggle,
enterFullScreenMode,
exitFullScreenMode,
} from '../../tasks/security_main';
import { populateTimeline } from '../../tasks/timeline';

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

describe('Toggle full screen', () => {
before(() => {
cleanKibana();
loginAndWaitForPage(HOSTS_URL);
openTimelineUsingToggle();
populateTimeline();
});

it('Should hide timeline header and tab list area', () => {
enterFullScreenMode();

cy.get(TIMELINE_TABS).should('not.exist');
cy.get(TIMELINE_HEADER).should('not.be.visible');
});

it('Should show timeline header and tab list area', () => {
exitFullScreenMode();
cy.get(TIMELINE_TABS).should('exist');
cy.get(TIMELINE_HEADER).should('be.visible');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import { timelineNonValidQuery } from '../../objects/timeline';

import { NOTES_TEXT, NOTES_TEXT_AREA } from '../../screens/timeline';
import {
NOTES_AUTHOR,
NOTES_CODE_BLOCK,
NOTES_LINK,
NOTES_TEXT,
NOTES_TEXT_AREA,
} from '../../screens/timeline';
import { createTimeline } from '../../tasks/api_calls/timelines';

import { cleanKibana } from '../../tasks/common';
Expand All @@ -16,15 +22,19 @@ import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import {
addNotesToTimeline,
closeTimeline,
goToNotesTab,
openTimelineById,
refreshTimelinesUntilTimeLinePresent,
} from '../../tasks/timeline';
import { waitForTimelinesPanelToBeLoaded } from '../../tasks/timelines';

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

const text = 'elastic';
const link = 'https://www.elastic.co/';

describe('Timeline notes tab', () => {
before(() => {
beforeEach(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(TIMELINES_URL);
waitForTimelinesPanelToBeLoaded();
Expand All @@ -37,19 +47,62 @@ describe('Timeline notes tab', () => {
// request responses and indeterminism since on clicks to activates URL's.
.then(() => cy.wait(1000))
.then(() => openTimelineById(timelineId))
.then(() => addNotesToTimeline(timelineNonValidQuery.notes))
.then(() => goToNotesTab())
);
});

after(() => {
closeTimeline();
});
it('should render mockdown', () => {
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(timelineNonValidQuery.notes);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(NOTES_TEXT_AREA).should('exist');
});

it('should contain notes', () => {
cy.get(NOTES_TEXT).should('have.text', timelineNonValidQuery.notes);
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(timelineNonValidQuery.notes);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(NOTES_TEXT).first().should('have.text', timelineNonValidQuery.notes);
});

it('should render mockdown', () => {
cy.get(NOTES_TEXT_AREA).should('exist');
it('should be able to render font in bold', () => {
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(`**bold**`);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(`${NOTES_TEXT} strong`).last().should('have.text', `bold`);
});

it('should be able to render font in italics', () => {
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(`_italics_`);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(`${NOTES_TEXT} em`).last().should('have.text', `italics`);
});

it('should be able to render code blocks', () => {
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(`\`code\``);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(NOTES_CODE_BLOCK).should('exist');
});

it('should render the right author', () => {
cy.intercept('/api/note').as(`updateNote`);
addNotesToTimeline(timelineNonValidQuery.notes);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(NOTES_AUTHOR).first().should('have.text', text);
});

it('should be able to render a link', () => {
cy.intercept('/api/note').as(`updateNote`);
cy.intercept(link).as(`link`);
addNotesToTimeline(`[${text}](${link})`);
cy.wait('@updateNote').its('response.statusCode').should('eq', 200);
cy.get(NOTES_LINK).last().should('have.text', `${text}(opens in a new tab or window)`);
cy.get(NOTES_LINK).last().click();
cy.wait('@link').its('response.statusCode').should('eq', 200);
});
});
Loading

0 comments on commit 62eece5

Please sign in to comment.