mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* fix landing url on rule delete * add cypress test * fix cypress Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c4a0d037fd
commit
9378cefbd8
4 changed files with 59 additions and 8 deletions
|
@ -88,6 +88,7 @@ import {
|
|||
import {
|
||||
changeRowsPerPageTo100,
|
||||
deleteFirstRule,
|
||||
deleteRuleFromDetailsPage,
|
||||
deleteSelectedRules,
|
||||
editFirstRule,
|
||||
filterByCustomRules,
|
||||
|
@ -237,8 +238,10 @@ describe('Custom detection rules deletion and edition', () => {
|
|||
goToManageAlertsDetectionRules();
|
||||
waitForAlertsIndexToBeCreated();
|
||||
createCustomRuleActivated(getNewRule(), 'rule1');
|
||||
createCustomRuleActivated(getNewOverrideRule(), 'rule2');
|
||||
createCustomRuleActivated(getExistingRule(), 'rule3');
|
||||
createCustomRuleActivated(getNewRule(), 'rule2');
|
||||
|
||||
createCustomRuleActivated(getNewOverrideRule(), 'rule3');
|
||||
createCustomRuleActivated(getExistingRule(), 'rule4');
|
||||
reload();
|
||||
});
|
||||
|
||||
|
@ -292,7 +295,7 @@ describe('Custom detection rules deletion and edition', () => {
|
|||
});
|
||||
cy.get(SHOWING_RULES_TEXT).should(
|
||||
'have.text',
|
||||
`Showing ${expectedNumberOfRulesAfterDeletion} rule`
|
||||
`Showing ${expectedNumberOfRulesAfterDeletion} rules`
|
||||
);
|
||||
cy.get(CUSTOM_RULES_BTN).should(
|
||||
'have.text',
|
||||
|
@ -300,6 +303,38 @@ describe('Custom detection rules deletion and edition', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Deletes one rule from detail page', () => {
|
||||
cy.get(RULES_TABLE)
|
||||
.find(RULES_ROW)
|
||||
.then((rules) => {
|
||||
const initialNumberOfRules = rules.length;
|
||||
const expectedNumberOfRulesAfterDeletion = initialNumberOfRules - 1;
|
||||
|
||||
goToRuleDetails();
|
||||
cy.intercept('POST', '/api/detection_engine/rules/_bulk_delete').as('deleteRule');
|
||||
|
||||
deleteRuleFromDetailsPage();
|
||||
|
||||
cy.waitFor('@deleteRule').then(() => {
|
||||
cy.get(RULES_TABLE).should('exist');
|
||||
cy.get(RULES_TABLE).then(($table) => {
|
||||
cy.wrap($table.find(RULES_ROW).length).should(
|
||||
'eql',
|
||||
expectedNumberOfRulesAfterDeletion
|
||||
);
|
||||
});
|
||||
cy.get(SHOWING_RULES_TEXT).should(
|
||||
'have.text',
|
||||
`Showing ${expectedNumberOfRulesAfterDeletion} rules`
|
||||
);
|
||||
cy.get(CUSTOM_RULES_BTN).should(
|
||||
'have.text',
|
||||
`Custom rules (${expectedNumberOfRulesAfterDeletion})`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('Edition', () => {
|
||||
|
|
|
@ -103,3 +103,5 @@ export const RULES_EMPTY_PROMPT = '[data-test-subj="rulesEmptyPrompt"]';
|
|||
export const RULES_DELETE_CONFIRMATION_MODAL = '[data-test-subj="allRulesDeleteConfirmationModal"]';
|
||||
|
||||
export const MODAL_CONFIRMATION_BTN = '[data-test-subj="confirmModalConfirmButton"]';
|
||||
|
||||
export const RULE_DETAILS_DELETE_BTN = '[data-test-subj="rules-details-delete-rule"]';
|
||||
|
|
|
@ -42,6 +42,7 @@ import {
|
|||
ACTIVATE_RULE_BULK_BTN,
|
||||
DEACTIVATE_RULE_BULK_BTN,
|
||||
EXPORT_RULE_BULK_BTN,
|
||||
RULE_DETAILS_DELETE_BTN,
|
||||
} from '../screens/alerts_detection_rules';
|
||||
import { ALL_ACTIONS, DELETE_RULE } from '../screens/rule_details';
|
||||
|
||||
|
@ -107,6 +108,17 @@ export const deleteSelectedRules = () => {
|
|||
cy.get(DELETE_RULE_BULK_BTN).click();
|
||||
};
|
||||
|
||||
export const deleteRuleFromDetailsPage = () => {
|
||||
cy.get(ALL_ACTIONS).should('be.visible');
|
||||
cy.root()
|
||||
.pipe(($el) => {
|
||||
$el.find(ALL_ACTIONS).trigger('click');
|
||||
return $el.find(RULE_DETAILS_DELETE_BTN);
|
||||
})
|
||||
.should(($el) => expect($el).to.be.visible);
|
||||
cy.get(RULE_DETAILS_DELETE_BTN).pipe(($el) => $el.trigger('click'));
|
||||
};
|
||||
|
||||
export const duplicateSelectedRules = () => {
|
||||
cy.get(BULK_ACTIONS_BTN).click({ force: true });
|
||||
cy.get(DUPLICATE_RULE_BULK_BTN).click();
|
||||
|
@ -143,7 +155,7 @@ export const goToCreateNewRule = () => {
|
|||
};
|
||||
|
||||
export const goToRuleDetails = () => {
|
||||
cy.get(RULE_NAME).click({ force: true });
|
||||
cy.get(RULE_NAME).first().click({ force: true });
|
||||
};
|
||||
|
||||
export const loadPrebuiltDetectionRules = () => {
|
||||
|
|
|
@ -16,7 +16,6 @@ import React, { useCallback, useMemo } from 'react';
|
|||
import styled from 'styled-components';
|
||||
|
||||
import { noop } from 'lodash/fp';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { Rule } from '../../../containers/detection_engine/rules';
|
||||
import * as i18n from './translations';
|
||||
import * as i18nActions from '../../../pages/detection_engine/rules/translations';
|
||||
|
@ -31,6 +30,7 @@ import { getRulesUrl } from '../../../../common/components/link_to/redirect_to_d
|
|||
import { getToolTipContent } from '../../../../common/utils/privileges';
|
||||
import { useBoolState } from '../../../../common/hooks/use_bool_state';
|
||||
import { useKibana } from '../../../../common/lib/kibana';
|
||||
import { APP_ID, SecurityPageName } from '../../../../../common/constants';
|
||||
|
||||
const MyEuiButtonIcon = styled(EuiButtonIcon)`
|
||||
&.euiButtonIcon {
|
||||
|
@ -58,13 +58,15 @@ const RuleActionsOverflowComponent = ({
|
|||
canDuplicateRuleWithActions,
|
||||
}: RuleActionsOverflowComponentProps) => {
|
||||
const [isPopoverOpen, , closePopover, togglePopover] = useBoolState();
|
||||
const history = useHistory();
|
||||
const { navigateToApp } = useKibana().services.application;
|
||||
const [, dispatchToaster] = useStateToaster();
|
||||
|
||||
const onRuleDeletedCallback = useCallback(() => {
|
||||
history.push(getRulesUrl());
|
||||
}, [history]);
|
||||
navigateToApp(APP_ID, {
|
||||
deepLinkId: SecurityPageName.rules,
|
||||
path: getRulesUrl(),
|
||||
});
|
||||
}, [navigateToApp]);
|
||||
|
||||
const actions = useMemo(
|
||||
() =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue