From 7669b2e0bd7e769e74f0cde511077a57b4b7c5db Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 6 Apr 2020 17:02:33 +0200 Subject: [PATCH 1/5] adds 'singal detection rules' spec --- .../siem/cypress/integration/signal_detection_rules.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts diff --git a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts new file mode 100644 index 0000000000000..41bc2aa258807 --- /dev/null +++ b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts @@ -0,0 +1,5 @@ +/* + * 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. + */ From 438cb744cf38b2caed257c978897ef73938f95af Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 6 Apr 2020 17:03:43 +0200 Subject: [PATCH 2/5] adds 'Sorts by activated rules' test --- .../cypress/integration/signal_detection_rules.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts index 41bc2aa258807..23141b2837ad4 100644 --- a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts +++ b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts @@ -3,3 +3,10 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +describe('Signal detection rules', () => { + before(() => {}); + + after(() => {}); + + it('Sorts by activated rules', () => {}); +}); From 80d1ac34d2161da6dc64b00a3fc4fe16a17da450 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 6 Apr 2020 17:30:01 +0200 Subject: [PATCH 3/5] implements 'Sort by activated rules' --- .../signal_detection_rules.spec.ts | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts index 23141b2837ad4..32ebb7728ff64 100644 --- a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts +++ b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts @@ -3,10 +3,62 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver'; +import { loginAndWaitForPageWithoutDateRange } from '../tasks/login'; +import { DETECTIONS } from '../urls/navigation'; +import { goToManageSignalDetectionRules } from '../tasks/detections'; +import { + waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded, + waitForRulesToBeLoaded, +} from '../tasks/signal_detection_rules'; + describe('Signal detection rules', () => { - before(() => {}); + before(() => { + esArchiverLoad('prebuilt_rules_loaded'); + }); + + after(() => { + esArchiverUnload('prebuilt_rules_loaded'); + }); + + it('Sorts by activated rules', () => { + loginAndWaitForPageWithoutDateRange(DETECTIONS); + goToManageSignalDetectionRules(); + waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded(); + + cy.get('[data-test-subj="ruleName"]') + .eq(4) + .invoke('text') + .then(fifthRuleName => { + cy.get('[data-test-subj="rule-switch"]') + .eq(4) + .click({ force: true }); + cy.get('[data-test-subj="rule-switch-loader"]').should('exist'); + cy.get('[data-test-subj="rule-switch-loader"]').should('not.exist'); + + cy.get('[data-test-subj="ruleName"]') + .eq(6) + .invoke('text') + .then(seventhRuleName => { + cy.get('[data-test-subj="rule-switch"]') + .eq(6) + .click({ force: true }); + cy.get('[data-test-subj="rule-switch-loader"]').should('exist'); + cy.get('[data-test-subj="rule-switch-loader"]').should('not.exist'); - after(() => {}); + cy.get('[data-test-subj="tableHeaderSortButton"]').click({ force: true }); + waitForRulesToBeLoaded(); + cy.get('[data-test-subj="tableHeaderSortButton"]').click({ force: true }); + waitForRulesToBeLoaded(); - it('Sorts by activated rules', () => {}); + cy.get('[data-test-subj="ruleName"]') + .eq(0) + .should('have.text', fifthRuleName); + cy.get('[data-test-subj="ruleName"]') + .eq(1) + .should('have.text', seventhRuleName); + }); + }); + }); }); From 8adfc4c097274b1a54ced61e012a2451da31e8b3 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 6 Apr 2020 21:41:24 +0200 Subject: [PATCH 4/5] refactors code --- .../signal_detection_rules.spec.ts | 54 +++++++++---------- .../cypress/screens/signal_detection_rules.ts | 12 +++++ .../cypress/tasks/signal_detection_rules.ts | 23 +++++++- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts index 32ebb7728ff64..1559285d508ed 100644 --- a/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts +++ b/x-pack/legacy/plugins/siem/cypress/integration/signal_detection_rules.spec.ts @@ -3,16 +3,26 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { + FIFTH_RULE, + FIRST_RULE, + RULE_NAME, + SECOND_RULE, + SEVENTH_RULE, +} from '../screens/signal_detection_rules'; +import { goToManageSignalDetectionRules } from '../tasks/detections'; import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver'; import { loginAndWaitForPageWithoutDateRange } from '../tasks/login'; -import { DETECTIONS } from '../urls/navigation'; -import { goToManageSignalDetectionRules } from '../tasks/detections'; import { + activateRule, + sortByActivatedRules, waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded, - waitForRulesToBeLoaded, + waitForRuleToBeActivated, } from '../tasks/signal_detection_rules'; +import { DETECTIONS } from '../urls/navigation'; + describe('Signal detection rules', () => { before(() => { esArchiverLoad('prebuilt_rules_loaded'); @@ -26,37 +36,25 @@ describe('Signal detection rules', () => { loginAndWaitForPageWithoutDateRange(DETECTIONS); goToManageSignalDetectionRules(); waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded(); - - cy.get('[data-test-subj="ruleName"]') - .eq(4) + cy.get(RULE_NAME) + .eq(FIFTH_RULE) .invoke('text') .then(fifthRuleName => { - cy.get('[data-test-subj="rule-switch"]') - .eq(4) - .click({ force: true }); - cy.get('[data-test-subj="rule-switch-loader"]').should('exist'); - cy.get('[data-test-subj="rule-switch-loader"]').should('not.exist'); - - cy.get('[data-test-subj="ruleName"]') - .eq(6) + activateRule(FIFTH_RULE); + waitForRuleToBeActivated(); + cy.get(RULE_NAME) + .eq(SEVENTH_RULE) .invoke('text') .then(seventhRuleName => { - cy.get('[data-test-subj="rule-switch"]') - .eq(6) - .click({ force: true }); - cy.get('[data-test-subj="rule-switch-loader"]').should('exist'); - cy.get('[data-test-subj="rule-switch-loader"]').should('not.exist'); - - cy.get('[data-test-subj="tableHeaderSortButton"]').click({ force: true }); - waitForRulesToBeLoaded(); - cy.get('[data-test-subj="tableHeaderSortButton"]').click({ force: true }); - waitForRulesToBeLoaded(); + activateRule(SEVENTH_RULE); + waitForRuleToBeActivated(); + sortByActivatedRules(); - cy.get('[data-test-subj="ruleName"]') - .eq(0) + cy.get(RULE_NAME) + .eq(FIRST_RULE) .should('have.text', fifthRuleName); - cy.get('[data-test-subj="ruleName"]') - .eq(1) + cy.get(RULE_NAME) + .eq(SECOND_RULE) .should('have.text', seventhRuleName); }); }); diff --git a/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts b/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts index 09fbc2132302c..95dde435de132 100644 --- a/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts +++ b/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts @@ -18,6 +18,10 @@ export const DELETE_RULE_BULK_BTN = '[data-test-subj="deleteRuleBulk"]'; export const ELASTIC_RULES_BTN = '[data-test-subj="show-elastic-rules-filter-button"]'; +export const FIFTH_RULE = 5; + +export const FIRST_RULE = 0; + export const LOAD_PREBUILT_RULES_BTN = '[data-test-subj="load-prebuilt-rules"]'; export const LOADING_INITIAL_PREBUILT_RULES_TABLE = @@ -31,18 +35,26 @@ export const RISK_SCORE = '[data-test-subj="riskScore"]'; export const RELOAD_PREBUILT_RULES_BTN = '[data-test-subj="reloadPrebuiltRulesBtn"]'; +export const SECOND_RULE = 1; + export const RULE_CHECKBOX = '.euiTableRow .euiCheckbox__input'; export const RULE_NAME = '[data-test-subj="ruleName"]'; export const RULE_SWITCH = '[data-test-subj="rule-switch"]'; +export const RULE_SWITCH_LOADER = '[data-test-subj="rule-switch-loader"]'; + export const RULES_TABLE = '[data-test-subj="rules-table"]'; export const RULES_ROW = '.euiTableRow'; +export const SEVENTH_RULE = 6; + export const SEVERITY = '[data-test-subj="severity"]'; export const SHOWING_RULES_TEXT = '[data-test-subj="showingRules"]'; +export const SORT_RULES_BTN = '[data-test-subj="tableHeaderSortButton"]'; + export const THREE_HUNDRED_ROWS = '[data-test-subj="tablePagination-300-rows"]'; diff --git a/x-pack/legacy/plugins/siem/cypress/tasks/signal_detection_rules.ts b/x-pack/legacy/plugins/siem/cypress/tasks/signal_detection_rules.ts index cfc490526d84e..a404f1142cba7 100644 --- a/x-pack/legacy/plugins/siem/cypress/tasks/signal_detection_rules.ts +++ b/x-pack/legacy/plugins/siem/cypress/tasks/signal_detection_rules.ts @@ -15,13 +15,22 @@ import { LOADING_INITIAL_PREBUILT_RULES_TABLE, LOADING_SPINNER, PAGINATION_POPOVER_BTN, + RELOAD_PREBUILT_RULES_BTN, RULE_CHECKBOX, RULE_NAME, + RULE_SWITCH, + RULE_SWITCH_LOADER, RULES_TABLE, + SORT_RULES_BTN, THREE_HUNDRED_ROWS, - RELOAD_PREBUILT_RULES_BTN, } from '../screens/signal_detection_rules'; +export const activateRule = (rulePosition: number) => { + cy.get(RULE_SWITCH) + .eq(rulePosition) + .click({ force: true }); +}; + export const changeToThreeHundredRowsPerPage = () => { cy.get(PAGINATION_POPOVER_BTN).click({ force: true }); cy.get(THREE_HUNDRED_ROWS).click(); @@ -71,6 +80,13 @@ export const selectNumberOfRules = (numberOfRules: number) => { } }; +export const sortByActivatedRules = () => { + cy.get(SORT_RULES_BTN).click({ force: true }); + waitForRulesToBeLoaded(); + cy.get(SORT_RULES_BTN).click({ force: true }); + waitForRulesToBeLoaded(); +}; + export const waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded = () => { cy.get(LOADING_INITIAL_PREBUILT_RULES_TABLE).should('exist'); cy.get(LOADING_INITIAL_PREBUILT_RULES_TABLE).should('not.exist'); @@ -81,6 +97,11 @@ export const waitForPrebuiltDetectionRulesToBeLoaded = () => { cy.get(RULES_TABLE).should('exist'); }; +export const waitForRuleToBeActivated = () => { + cy.get(RULE_SWITCH_LOADER).should('exist'); + cy.get(RULE_SWITCH_LOADER).should('not.exist'); +}; + export const waitForRulesToBeLoaded = () => { cy.get(LOADING_SPINNER).should('exist'); cy.get(LOADING_SPINNER).should('not.exist'); From 8663a890fd0a57100a279610e52fe221d843253e Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 6 Apr 2020 22:31:37 +0200 Subject: [PATCH 5/5] fixes index --- .../plugins/siem/cypress/screens/signal_detection_rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts b/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts index 95dde435de132..f74f5c26ddc2e 100644 --- a/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts +++ b/x-pack/legacy/plugins/siem/cypress/screens/signal_detection_rules.ts @@ -18,7 +18,7 @@ export const DELETE_RULE_BULK_BTN = '[data-test-subj="deleteRuleBulk"]'; export const ELASTIC_RULES_BTN = '[data-test-subj="show-elastic-rules-filter-button"]'; -export const FIFTH_RULE = 5; +export const FIFTH_RULE = 4; export const FIRST_RULE = 0;