Skip to content

Commit

Permalink
[SIEM] Adds sort rules Cypress test (elastic#62700)
Browse files Browse the repository at this point in the history
* adds 'singal detection rules' spec

* adds 'Sorts by activated rules' test

* implements 'Sort by activated rules'

* refactors code

* fixes index
  • Loading branch information
MadameSheema committed Apr 7, 2020
1 parent 0e16f5b commit fdd7916
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/
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 {
activateRule,
sortByActivatedRules,
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRuleToBeActivated,
} from '../tasks/signal_detection_rules';

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

describe('Signal detection rules', () => {
before(() => {
esArchiverLoad('prebuilt_rules_loaded');
});

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

it('Sorts by activated rules', () => {
loginAndWaitForPageWithoutDateRange(DETECTIONS);
goToManageSignalDetectionRules();
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded();
cy.get(RULE_NAME)
.eq(FIFTH_RULE)
.invoke('text')
.then(fifthRuleName => {
activateRule(FIFTH_RULE);
waitForRuleToBeActivated();
cy.get(RULE_NAME)
.eq(SEVENTH_RULE)
.invoke('text')
.then(seventhRuleName => {
activateRule(SEVENTH_RULE);
waitForRuleToBeActivated();
sortByActivatedRules();

cy.get(RULE_NAME)
.eq(FIRST_RULE)
.should('have.text', fifthRuleName);
cy.get(RULE_NAME)
.eq(SECOND_RULE)
.should('have.text', seventhRuleName);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 4;

export const FIRST_RULE = 0;

export const LOAD_PREBUILT_RULES_BTN = '[data-test-subj="load-prebuilt-rules"]';

export const LOADING_INITIAL_PREBUILT_RULES_TABLE =
Expand All @@ -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"]';
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit fdd7916

Please sign in to comment.