From fd688925b3f3d4ec26ef3bdc8781b2431cced53b Mon Sep 17 00:00:00 2001 From: "konrad.szwarc" Date: Tue, 23 Apr 2024 14:55:46 +0200 Subject: [PATCH] proper undefined route state handling --- .../e2e/artifacts/artifact_tabs_in_policy_details.cy.ts | 6 ++++++ .../public/management/cypress/fixtures/artifacts_page.ts | 9 +++++---- .../management/pages/policy/view/tabs/policy_tabs.tsx | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifact_tabs_in_policy_details.cy.ts b/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifact_tabs_in_policy_details.cy.ts index b6040691c485f..3feb681f47f5c 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifact_tabs_in_policy_details.cy.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifact_tabs_in_policy_details.cy.ts @@ -56,6 +56,10 @@ const getRoleWithoutArtifactPrivilege = (privilegePrefix: string) => { const visitArtifactTab = (tabId: string) => { visitPolicyDetailsPage(); + clickArtifactTab(tabId); +}; + +const clickArtifactTab = (tabId: string) => { cy.get(`#${tabId}`).click(); }; @@ -135,6 +139,8 @@ describe('Artifact tabs in Policy Details page', { tags: ['@ess', '@serverless'] cy.getByTestSubj('backToOrigin').click(); cy.getByTestSubj('policyDetailsPage').should('exist'); + clickArtifactTab(testData.nextTabId); // Make sure the next tab is accessible and backLink doesn't throw errors + cy.getByTestSubj('policyDetailsPage'); }); }); diff --git a/x-pack/plugins/security_solution/public/management/cypress/fixtures/artifacts_page.ts b/x-pack/plugins/security_solution/public/management/cypress/fixtures/artifacts_page.ts index bbd173b60cb88..f47818208cb8f 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/fixtures/artifacts_page.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/fixtures/artifacts_page.ts @@ -21,6 +21,7 @@ interface ArtifactsFixtureType { title: string; pagePrefix: string; tabId: string; + nextTabId: string; artifactName: string; privilegePrefix: string; urlPath: string; @@ -46,6 +47,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ title: 'Trusted applications', pagePrefix: 'trustedAppsListPage', tabId: 'trustedApps', + nextTabId: 'eventFilters', artifactName: 'Trusted application name', privilegePrefix: 'trusted_applications_', create: { @@ -142,7 +144,6 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ }, urlPath: 'trusted_apps', emptyState: 'trustedAppsListPage-emptyState', - createRequestBody: { list_id: ENDPOINT_ARTIFACT_LISTS.trustedApps.id, entries: [ @@ -172,6 +173,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ title: 'Event Filters', pagePrefix: 'EventFiltersListPage', tabId: 'eventFilters', + nextTabId: 'blocklists', artifactName: 'Event filter name', privilegePrefix: 'event_filters_', create: { @@ -274,7 +276,6 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ }, urlPath: 'event_filters', emptyState: 'EventFiltersListPage-emptyState', - createRequestBody: { list_id: ENDPOINT_ARTIFACT_LISTS.eventFilters.id, entries: [ @@ -292,6 +293,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ title: 'Blocklist', pagePrefix: 'blocklistPage', tabId: 'blocklists', + nextTabId: 'hostIsolationExceptions', artifactName: 'Blocklist name', privilegePrefix: 'blocklist_', create: { @@ -397,7 +399,6 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ }, urlPath: 'blocklist', emptyState: 'blocklistPage-emptyState', - createRequestBody: { list_id: ENDPOINT_ARTIFACT_LISTS.blocklists.id, entries: [ @@ -421,6 +422,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ title: 'Host isolation exceptions', pagePrefix: 'hostIsolationExceptionsListPage', tabId: 'hostIsolationExceptions', + nextTabId: 'trustedApps', artifactName: 'Host Isolation exception name', privilegePrefix: 'host_isolation_exceptions_', create: { @@ -499,7 +501,6 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [ }, urlPath: 'host_isolation_exceptions', emptyState: 'hostIsolationExceptionsListPage-emptyState', - createRequestBody: { list_id: ENDPOINT_ARTIFACT_LISTS.hostIsolationExceptions.id, entries: [ diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/tabs/policy_tabs.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/tabs/policy_tabs.tsx index 5b37aa798effd..fd7e8793535e2 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/tabs/policy_tabs.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/tabs/policy_tabs.tsx @@ -457,7 +457,7 @@ export const PolicyTabs = React.memo(() => { cancelUnsavedChangesModal, history, policyId, - routeState.backLink, + routeState?.backLink, unsavedChangesModal.showModal, ] );