Skip to content

Commit

Permalink
[Security Solution][Detections] Adds Rules monitoring table actions (e…
Browse files Browse the repository at this point in the history
…lastic#119644)

[Security Solution][Detections] Adds actions for Rules monitoring table: single/bulk enable, disable, duplicate, export, remove (elastic#119644)
  • Loading branch information
vitaliidm authored and TinLe committed Dec 22, 2021
1 parent 6361ab3 commit a2c9026
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
RULES_EMPTY_PROMPT,
RULE_SWITCH,
SHOWING_RULES_TEXT,
RULES_MONIROTING_TABLE,
SELECT_ALL_RULES_ON_PAGE_CHECKBOX,
} from '../../screens/alerts_detection_rules';

import { goToManageAlertsDetectionRules, waitForAlertsIndexToBeCreated } from '../../tasks/alerts';
Expand Down Expand Up @@ -94,6 +96,19 @@ describe('Actions with prebuilt rules', () => {
cy.get(RULE_SWITCH).should('have.attr', 'aria-checked', 'false');
});

it('Allows to activate all rules on a page and deactivate single one at monitoring table', () => {
cy.get(RULES_MONIROTING_TABLE).click();
cy.get(SELECT_ALL_RULES_ON_PAGE_CHECKBOX).click();
activateSelectedRules();
waitForRuleToChangeStatus();
cy.get(RULE_SWITCH).should('have.attr', 'aria-checked', 'true');

selectNumberOfRules(1);
cy.get(RULE_SWITCH).first().click();
waitForRuleToChangeStatus();
cy.get(RULE_SWITCH).first().should('have.attr', 'aria-checked', 'false');
});

it('Allows to delete all rules at once', () => {
selectAllRules();
deleteSelectedRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ export const RULE_DETAILS_DELETE_BTN = '[data-test-subj="rules-details-delete-ru
export const ALERT_DETAILS_CELLS = '[data-test-subj="dataGridRowCell"]';

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

export const SELECT_ALL_RULES_ON_PAGE_CHECKBOX = '[data-test-subj="checkboxSelectAll"]';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ describe('useRuleStatus', () => {
},
failures: [],
id: '12345678987654321',
activate: true,
name: 'Test rule',
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useEffect, useRef, useState } from 'react';
import { isNotFoundError } from '@kbn/securitysolution-t-grid';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';

import { RuleStatusRowItemType } from '../../../pages/detection_engine/rules/all/columns';
import { EnhancedRuleStatus } from '../../../pages/detection_engine/rules/all/columns';
import { getRuleStatusById, getRulesStatusByIds } from './api';
import * as i18n from './translations';
import { RuleStatus, Rules } from './types';
Expand All @@ -18,7 +18,7 @@ type Func = (ruleId: string) => void;
export type ReturnRuleStatus = [boolean, RuleStatus | null, Func | null];
export interface ReturnRulesStatuses {
loading: boolean;
rulesStatuses: RuleStatusRowItemType[];
rulesStatuses: EnhancedRuleStatus[];
}

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ export const useRuleStatus = (id: string | undefined | null): ReturnRuleStatus =
*
*/
export const useRulesStatuses = (rules: Rules): ReturnRulesStatuses => {
const [rulesStatuses, setRuleStatuses] = useState<RuleStatusRowItemType[]>([]);
const [rulesStatuses, setRuleStatuses] = useState<EnhancedRuleStatus[]>([]);
const [loading, setLoading] = useState(false);
const { addError } = useAppToasts();

Expand All @@ -98,8 +98,6 @@ export const useRulesStatuses = (rules: Rules): ReturnRulesStatuses => {
setRuleStatuses(
rules.map((rule) => ({
id: rule.id,
activate: rule.enabled,
name: rule.name,
...ruleStatusesResponse[rule.id],
}))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { scopedHistoryMock } from 'src/core/public/mocks';
import uuid from 'uuid';
import '../../../../../common/mock/match_media';
import { deleteRulesAction, duplicateRulesAction, editRuleAction } from './actions';
Expand All @@ -18,7 +17,6 @@ jest.mock('./actions', () => ({
editRuleAction: jest.fn(),
}));

const history = scopedHistoryMock.create();
const duplicateRulesActionMock = duplicateRulesAction as jest.Mock;
const deleteRulesActionMock = deleteRulesAction as jest.Mock;
const editRuleActionMock = editRuleAction as jest.Mock;
Expand All @@ -45,7 +43,6 @@ describe('AllRulesTable Columns', () => {
const duplicateRulesActionObject = getActions(
dispatch,
dispatchToaster,
history,
navigateToApp,
reFetchRules,
refetchPrePackagedRulesStatus,
Expand All @@ -62,7 +59,6 @@ describe('AllRulesTable Columns', () => {
const deleteRulesActionObject = getActions(
dispatch,
dispatchToaster,
history,
navigateToApp,
reFetchRules,
refetchPrePackagedRulesStatus,
Expand Down
Loading

0 comments on commit a2c9026

Please sign in to comment.