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

[Security Solution][Detections] Adds Rules monitoring table actions #119644

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