Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Adds sort rules Cypress test #62700

Merged
merged 5 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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