diff --git a/x-pack/plugins/security_solution/cypress/integration/detection_rules/links.spec.ts b/x-pack/plugins/security_solution/cypress/integration/detection_rules/links.spec.ts new file mode 100644 index 0000000000000..fdc4bce677f74 --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/integration/detection_rules/links.spec.ts @@ -0,0 +1,37 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { newRule } from '../../objects/rule'; +import { RULES_MONIROTING_TABLE, RULE_NAME } from '../../screens/alerts_detection_rules'; +import { goToManageAlertsDetectionRules, waitForAlertsIndexToBeCreated } from '../../tasks/alerts'; +import { createCustomRuleActivated } from '../../tasks/api_calls/rules'; +import { cleanKibana, reload } from '../../tasks/common'; +import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login'; +import { ALERTS_URL } from '../../urls/navigation'; + +describe('Rules talbes links', () => { + beforeEach(() => { + cleanKibana(); + loginAndWaitForPageWithoutDateRange(ALERTS_URL); + goToManageAlertsDetectionRules(); + waitForAlertsIndexToBeCreated(); + createCustomRuleActivated(newRule, 'rule1'); + + reload(); + }); + + it('should render correct link for rule name - rules', () => { + cy.get(RULE_NAME).first().click(); + cy.url().should('contain', 'rules/id/'); + }); + + it('should render correct link for rule name - rule monitoring', () => { + cy.get(RULES_MONIROTING_TABLE).first().click(); + cy.get(RULE_NAME).first().click(); + cy.url().should('contain', 'rules/id/'); + }); +}); diff --git a/x-pack/plugins/security_solution/cypress/screens/alerts_detection_rules.ts b/x-pack/plugins/security_solution/cypress/screens/alerts_detection_rules.ts index ba071184d98eb..0bf0e5a09e328 100644 --- a/x-pack/plugins/security_solution/cypress/screens/alerts_detection_rules.ts +++ b/x-pack/plugins/security_solution/cypress/screens/alerts_detection_rules.ts @@ -72,6 +72,8 @@ export const RULES_TABLE = '[data-test-subj="rules-table"]'; export const RULES_ROW = '.euiTableRow'; +export const RULES_MONIROTING_TABLE = '[data-test-subj="allRulesTableTab-monitoring"]'; + export const SEVENTH_RULE = 6; export const SEVERITY = '[data-test-subj="severity"]'; diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/columns.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/columns.tsx index 8d0492267258f..c6145a70ec8d2 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/columns.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/columns.tsx @@ -313,7 +313,7 @@ export const getColumns = ({ }; export const getMonitoringColumns = ( - history: H.History, + navigateToApp: (appId: string, options?: NavigateToAppOptions | undefined) => Promise, formatUrl: FormatUrl ): RulesStatusesColumns[] => { const cols: RulesStatusesColumns[] = [ @@ -326,7 +326,10 @@ export const getMonitoringColumns = ( data-test-subj="ruleName" onClick={(ev: { preventDefault: () => void }) => { ev.preventDefault(); - history.push(getRuleDetailsUrl(item.id)); + navigateToApp(APP_ID, { + deepLinkId: SecurityPageName.rules, + path: getRuleDetailsUrl(item.id), + }); }} href={formatUrl(getRuleDetailsUrl(item.id))} > diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/rules_tables.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/rules_tables.tsx index 77ca5be0c0ac1..22281fa2c8687 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/rules_tables.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/rules_tables.tsx @@ -300,8 +300,8 @@ export const RulesTables = React.memo( reFetchRules, ]); - const monitoringColumns = useMemo(() => getMonitoringColumns(history, formatUrl), [ - history, + const monitoringColumns = useMemo(() => getMonitoringColumns(navigateToApp, formatUrl), [ + navigateToApp, formatUrl, ]);