Skip to content

Commit

Permalink
refactors test
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Mar 12, 2020
1 parent b1d41e4 commit bd9b7b2
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 81 deletions.
138 changes: 59 additions & 79 deletions x-pack/legacy/plugins/siem/cypress/integration/detections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { NUMBER_OF_SIGNALS, SHOWING_SIGNALS, SIGNALS } from '../screens/detections';

import {
closeSignals,
goToClosedSignals,
goToOpenedSignals,
openSignals,
selectNumberOfSignals,
waitForSignalsPanelToBeLoaded,
waitForSignals,
waitForSignalsToBeLoaded,
} from '../tasks/detections';
import { esArchiverLoad } from '../tasks/es_archiver';
import { loginAndWaitForPage } from '../tasks/login';

import { DETECTIONS } from '../urls/navigation';
import { REFRESH_BUTTON } from '../screens/siem_header';
import { waitForSignalsIndexToBeCreated } from '../tasks/detections';

describe('Detections', () => {
before(() => {
Expand All @@ -17,103 +27,73 @@ describe('Detections', () => {
});

it('Closes and opens signals', () => {
cy.get('[data-test-subj="loading-signals-panel"]').should('exist');
cy.get('[data-test-subj="loading-signals-panel"]').should('not.exist');

cy.get(REFRESH_BUTTON)
.invoke('text')
.should('not.equal', 'Updating');
cy.get('[data-test-subj="event"]').should('have.length', 25);

waitForSignalsIndexToBeCreated();
waitForSignalsPanelToBeLoaded();
waitForSignalsToBeLoaded();

cy.get('[data-test-subj="server-side-event-count"]')
cy.get(NUMBER_OF_SIGNALS)
.invoke('text')
.then(numberOfSignals => {
cy.get('[data-test-subj="showingRules"]')
cy.get(SHOWING_SIGNALS)
.invoke('text')
.should('eql', `Showing ${numberOfSignals} signals`);

for (let i = 0; i < 3; i++) {
cy.get('[data-test-subj="select-event-container"] .euiCheckbox__input')
.eq(i)
.click({ force: true });
}
// cy.wait(1000);
cy.get('[data-test-subj="openCloseSignal"] .siemLinkIcon__label').click({ force: true });
const numberOfSignalsToBeClosed = 3;
selectNumberOfSignals(numberOfSignalsToBeClosed);
closeSignals();
waitForSignals();
cy.reload();
waitForSignals();

cy.get(REFRESH_BUTTON)
const expectedNumberOfSignalsAfterClosing = +numberOfSignals - numberOfSignalsToBeClosed;
cy.get(NUMBER_OF_SIGNALS)
.invoke('text')
.should('not.equal', 'Updating');

waitForSignalsIndexToBeCreated();

const expected = +numberOfSignals - 3;
// cy.wait(5000);
// cy.pause();
cy.get('[data-test-subj="server-side-event-count"]')
.invoke('text')
.should('eq', expected.toString());
cy.get('[data-test-subj="showingRules"]')
.should('eq', expectedNumberOfSignalsAfterClosing.toString());
cy.get(SHOWING_SIGNALS)
.invoke('text')
.should('eql', `Showing ${expected.toString()} signals`);

cy.get('[data-test-subj="closedSignals"]').click({ force: true });

// cy.wait(3000);
.should('eql', `Showing ${expectedNumberOfSignalsAfterClosing.toString()} signals`);

cy.get(REFRESH_BUTTON)
.invoke('text')
.should('not.equal', 'Updating');
goToClosedSignals();
waitForSignals();

cy.get('[data-test-subj=server-side-event-count]')
cy.get(NUMBER_OF_SIGNALS)
.invoke('text')
.should('eql', '3');
cy.get('[data-test-subj="showingRules"]')
.should('eql', numberOfSignalsToBeClosed.toString());
cy.get(SHOWING_SIGNALS)
.invoke('text')
.should('eql', `Showing 3 signals`);
cy.get('[data-test-subj="event"]').should('have.length', 3);

for (let i = 0; i < 1; i++) {
cy.get('[data-test-subj="select-event-container"] .euiCheckbox__input')
.eq(i)
.click({ force: true });
}

// cy.wait(5000);
// cy.pause();

cy.get('[data-test-subj="openCloseSignal"] .siemLinkIcon__label').click({ force: true });

cy.get(REFRESH_BUTTON)
.should('eql', `Showing ${numberOfSignalsToBeClosed.toString()} signals`);
cy.get(SIGNALS).should('have.length', numberOfSignalsToBeClosed);

const numberOfSignalsToBeOpened = 1;
selectNumberOfSignals(numberOfSignalsToBeOpened);
openSignals();
waitForSignals();
cy.reload();
waitForSignalsToBeLoaded();
waitForSignals();
goToClosedSignals();
waitForSignals();

const expectedNumberOfClosedSignalsAfterOpened = 2;
cy.get(NUMBER_OF_SIGNALS)
.invoke('text')
.should('not.equal', 'Updating');

waitForSignalsIndexToBeCreated();

// cy.wait(5000)

cy.get('[data-test-subj=server-side-event-count]')
.invoke('text')
.should('eql', '2');
cy.get('[data-test-subj="showingRules"]')
.should('eql', expectedNumberOfClosedSignalsAfterOpened.toString());
cy.get(SHOWING_SIGNALS)
.invoke('text')
.should('eql', `Showing 2 signals`);

cy.get('[data-test-subj="event"]').should('have.length', 2);

cy.get('[data-test-subj=openSignals]').click({ force: true });
.should('eql', `Showing ${expectedNumberOfClosedSignalsAfterOpened.toString()} signals`);
cy.get(SIGNALS).should('have.length', expectedNumberOfClosedSignalsAfterOpened);

// cy.wait(5000);
// cy.pause();
goToOpenedSignals();
waitForSignals();

cy.get('[data-test-subj="showingRules"]')
const expectedNumberOfOpenedSignals =
+numberOfSignals - expectedNumberOfClosedSignalsAfterOpened;
cy.get(SHOWING_SIGNALS)
.invoke('text')
.should('eql', `Showing 106 signals`);
.should('eql', `Showing ${expectedNumberOfOpenedSignals.toString()} signals`);

cy.get('[data-test-subj="server-side-event-count"]')
.invoke('text')
.should('eql', '106');
.should('eql', expectedNumberOfOpenedSignals.toString());
});
});
});
14 changes: 14 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/screens/detections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const CLOSED_SIGNALS_BTN = '[data-test-subj="closedSignals"]';

export const LOADING_SIGNALS_PANEL = '[data-test-subj="loading-signals-panel"]';

export const MANAGE_SIGNAL_DETECTION_RULES_BTN = '[data-test-subj="manage-signal-detection-rules"]';

export const NUMBER_OF_SIGNALS = '[data-test-subj="server-side-event-count"]';

export const OPEN_CLOSE_SIGNALS_BTN = '[data-test-subj="openCloseSignal"] .siemLinkIcon__label';

export const OPENED_SIGNALS_BTN = '[data-test-subj=openSignals]';

export const SHOWING_SIGNALS = '[data-test-subj="showingSignals"]';

export const SIGNALS = '[data-test-subj="event"]';

export const SIGNAL_CHECKBOX = '[data-test-subj="select-event-container"] .euiCheckbox__input';
46 changes: 45 additions & 1 deletion x-pack/legacy/plugins/siem/cypress/tasks/detections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,53 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LOADING_SIGNALS_PANEL, MANAGE_SIGNAL_DETECTION_RULES_BTN } from '../screens/detections';
import {
CLOSED_SIGNALS_BTN,
LOADING_SIGNALS_PANEL,
MANAGE_SIGNAL_DETECTION_RULES_BTN,
OPEN_CLOSE_SIGNALS_BTN,
OPENED_SIGNALS_BTN,
SIGNALS,
SIGNAL_CHECKBOX,
} from '../screens/detections';
import { REFRESH_BUTTON } from '../screens/siem_header';

export const closeSignals = () => {
cy.get(OPEN_CLOSE_SIGNALS_BTN).click({ force: true });
};

export const goToClosedSignals = () => {
cy.get(CLOSED_SIGNALS_BTN).click({ force: true });
};

export const goToManageSignalDetectionRules = () => {
cy.get(MANAGE_SIGNAL_DETECTION_RULES_BTN)
.should('exist')
.click({ force: true });
};

export const goToOpenedSignals = () => {
cy.get(OPENED_SIGNALS_BTN).click({ force: true });
};

export const openSignals = () => {
cy.get(OPEN_CLOSE_SIGNALS_BTN).click({ force: true });
};

export const selectNumberOfSignals = (numberOfSignals: number) => {
for (let i = 0; i < numberOfSignals; i++) {
cy.get(SIGNAL_CHECKBOX)
.eq(i)
.click({ force: true });
}
};

export const waitForSignals = () => {
cy.get(REFRESH_BUTTON)
.invoke('text')
.should('not.equal', 'Updating');
};

export const waitForSignalsIndexToBeCreated = () => {
cy.request({ url: '/api/detection_engine/index', retryOnStatusCodeFailure: true }).then(
response => {
Expand All @@ -26,3 +65,8 @@ export const waitForSignalsPanelToBeLoaded = () => {
cy.get(LOADING_SIGNALS_PANEL).should('exist');
cy.get(LOADING_SIGNALS_PANEL).should('not.exist');
};

export const waitForSignalsToBeLoaded = () => {
const expectedNumberOfDisplayedSignals = 25;
cy.get(SIGNALS).should('have.length', expectedNumberOfDisplayedSignals);
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const SignalsUtilityBarComponent: React.FC<SignalsUtilityBarProps> = ({
<UtilityBar>
<UtilityBarSection>
<UtilityBarGroup>
<UtilityBarText dataTestSubj="showingRules">
<UtilityBarText dataTestSubj="showingSignals">
{i18n.SHOWING_SIGNALS(formattedTotalCount, totalCount)}
</UtilityBarText>
</UtilityBarGroup>
Expand Down

0 comments on commit bd9b7b2

Please sign in to comment.