Skip to content

Commit

Permalink
test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Sep 14, 2020
1 parent d78f5cb commit 352f699
Show file tree
Hide file tree
Showing 8 changed files with 2,678 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,71 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { loginAndWaitForPageWithoutDateRange, loginAndWaitForTimeline } from '../tasks/login';
import { CASES_URL } from '../urls/navigation';
import { openTimeline } from '../tasks/security_main';
import { loginAndWaitForTimeline } from '../tasks/login';
import {
createNewTimeline,
attachTimelineToNewCase,
openTimelineFromSettings,
waitForTimelinesPanelToBeLoaded,
attachTimelineToExistingCase,
addNewCase,
selectCase,
} from '../tasks/timeline';
import { DESCRIPTION_INPUT } from '../screens/create_new_case';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { TIMELINE } from '../screens/timeline';
import { caseTimeline, case1 } from '../objects/case';
import { ALL_CASES_CREATE_NEW_CASE_TABLE_BTN, ALL_CASES_CASE } from '../screens/all_cases';
import { goToCreateNewCase } from '../tasks/all_cases';
import { createNewCase } from '../tasks/create_new_case';
import { navigateFromHeaderTo } from '../tasks/security_header';
import { HOSTS } from '../screens/security_header';
import { SIEM_TIMELINE_ID } from '../objects/timeline';
import { caseTimeline, TIMELINE_CASE_ID } from '../objects/case';

describe('attach timeline to case', () => {
before(() => {
esArchiverLoad('timeline');
cy.server();
cy.route('POST', '**api/cases*').as('createCase');
});

afterEach(() => {
createNewTimeline();
beforeEach(() => {
loginAndWaitForTimeline(caseTimeline.id);
});
context('without cases created', () => {
before(() => {
esArchiverLoad('timeline');
});

after(() => {
esArchiverUnload('timeline');
});
after(() => {
esArchiverUnload('timeline');
});

it('attach timeline to a new case', () => {
loginAndWaitForTimeline(SIEM_TIMELINE_ID);
attachTimelineToNewCase();
it('attach timeline to a new case', () => {
attachTimelineToNewCase();

cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseTimeline.id}',isOpen:!t))`
);
cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseTimeline.id}',isOpen:!t))`
);
});
});
});

it('attach timeline to an existing case with no case', () => {
loginAndWaitForTimeline(SIEM_TIMELINE_ID);
attachTimelineToExistingCase();
it('attach timeline to an existing case with no case', () => {
attachTimelineToExistingCase();
addNewCase();

cy.get(ALL_CASES_CREATE_NEW_CASE_TABLE_BTN).click();
cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseTimeline.id}',isOpen:!t))`
);
cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseTimeline.id}',isOpen:!t))`
);
});
});
});

it('attach timeline to an existing case', () => {
loginAndWaitForPageWithoutDateRange(CASES_URL);
goToCreateNewCase();
createNewCase(case1);

cy.wait('@createCase').then((response) => {
cy.wrap(response.status).should('eql', 200);
const caseRes = JSON.parse(response.xhr.responseText);
navigateFromHeaderTo(HOSTS);
context('with cases created', () => {
before(() => {
esArchiverLoad('case_and_timeline');
});

openTimeline();
openTimelineFromSettings();
waitForTimelinesPanelToBeLoaded();
after(() => {
esArchiverUnload('case_and_timeline');
});

cy.get(TIMELINE(caseTimeline.id!)).click();
it('attach timeline to an existing case', () => {
attachTimelineToExistingCase();
cy.get(ALL_CASES_CASE(caseRes.id!)).click();
selectCase(TIMELINE_CASE_ID);

cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseRes.id}',isOpen:!t))`
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:'${caseTimeline.id}',isOpen:!t))`
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/security_solution/cypress/objects/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Timeline } from './timeline';
import { Timeline, TimelineWithId } from './timeline';

export interface TestCase {
name: string;
Expand All @@ -21,7 +21,7 @@ export interface Connector {
password: string;
}

export const caseTimeline: Timeline = {
export const caseTimeline: TimelineWithId = {
title: 'SIEM test',
description: 'description',
query: 'host.name:*',
Expand All @@ -42,3 +42,5 @@ export const serviceNowConnector: Connector = {
username: 'Username Name',
password: 'password',
};

export const TIMELINE_CASE_ID = '68248e00-f689-11ea-9ab2-59238b522856';
5 changes: 3 additions & 2 deletions x-pack/plugins/security_solution/cypress/objects/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export interface Timeline {
title: string;
description: string;
query: string;
id?: string;
}

export const SIEM_TIMELINE_ID = '0162c130-78be-11ea-9718-118a926974a4';
export interface TimelineWithId extends Timeline {
id: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

export const BACK_TO_CASES_BTN = '[data-test-subj="backToCases"]';

export const DESCRIPTION_INPUT =
'[data-test-subj="caseDescription"] [data-test-subj="textAreaInput"]';
export const DESCRIPTION_INPUT = '[data-test-subj="textAreaInput"]';

export const INSERT_TIMELINE_BTN = '[data-test-subj="insert-timeline-button"]';

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/security_solution/cypress/screens/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const ATTACH_TIMELINE_TO_EXISTING_CASE_ICON =

export const BULK_ACTIONS = '[data-test-subj="utility-bar-action-button"]';

export const CASE = (id: string) => {
return `[data-test-subj="cases-table-row-${id}"]`;
};

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

export const CREATE_NEW_TIMELINE = '[data-test-subj="timeline-new"]';
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ALL_CASES_CREATE_NEW_CASE_TABLE_BTN } from '../screens/all_cases';
import {
BULK_ACTIONS,
CLOSE_TIMELINE_BTN,
Expand Down Expand Up @@ -31,6 +32,7 @@ import {
ATTACH_TIMELINE_TO_NEW_CASE_ICON,
OPEN_TIMELINE_ICON,
ATTACH_TIMELINE_TO_EXISTING_CASE_ICON,
CASE,
} from '../screens/timeline';

import { drag, drop } from '../tasks/common';
Expand All @@ -47,6 +49,10 @@ export const addNameToTimeline = (name: string) => {
cy.get(TIMELINE_TITLE).should('have.attr', 'value', name);
};

export const addNewCase = () => {
cy.get(ALL_CASES_CREATE_NEW_CASE_TABLE_BTN).click();
};

export const attachTimelineToNewCase = () => {
cy.get(TIMELINE_SETTINGS_ICON).click({ force: true });
cy.get(ATTACH_TIMELINE_TO_NEW_CASE_ICON).click({ force: true });
Expand Down Expand Up @@ -150,6 +156,10 @@ export const resetFields = () => {
cy.get(RESET_FIELDS).click({ force: true });
};

export const selectCase = (caseId: string) => {
cy.get(CASE(caseId)).click();
};

export const waitForTimelinesPanelToBeLoaded = () => {
cy.get(TIMELINES_TABLE).should('exist');
};
Expand Down
Binary file not shown.
Loading

0 comments on commit 352f699

Please sign in to comment.