From 957a18b31f3cc0215346e9a06735cf882f1bc132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Tue, 26 Nov 2024 21:53:48 +0000 Subject: [PATCH] [APM] Fix inventory plugin link (#201122) closes https://github.com/elastic/kibana/issues/201116 - Fix Inventory locator removing `observability` from the url. - ~~Unify service inventory E2E tests to run it faster avoiding Kibana loading page on every test.~~ - Add test to navigate to the inventory plugin. (cherry picked from commit 4bc9a59fcccbe0f58bcb58bbe42fa294dd3f041a) --- .../service_inventory/service_inventory.cy.ts | 14 +++-- .../apm/ftr_e2e/cypress/support/commands.ts | 54 +++++++++++-------- .../apm/ftr_e2e/cypress/support/types.d.ts | 2 +- .../public/hooks/use_inventory_router.ts | 2 +- .../entity_inventory_locator.ts | 4 +- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/e2e/service_inventory/service_inventory.cy.ts b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/e2e/service_inventory/service_inventory.cy.ts index 3e913d4f527f0..5d87b55757b24 100644 --- a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/e2e/service_inventory/service_inventory.cy.ts +++ b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/e2e/service_inventory/service_inventory.cy.ts @@ -23,10 +23,12 @@ const serviceInventoryHref = url.format({ const mainApiRequestsToIntercept = [ { + method: 'GET', endpoint: '/internal/apm/services?*', aliasName: 'servicesRequest', }, { + method: 'POST', endpoint: '/internal/apm/services/detailed_statistics?*', aliasName: 'detailedStatisticsRequest', }, @@ -51,8 +53,13 @@ describe.skip('Service inventory', () => { describe('When navigating to the service inventory', () => { beforeEach(() => { + mainApiRequestsToIntercept.forEach(({ aliasName, endpoint, method }) => + cy.intercept(method, endpoint).as(aliasName) + ); cy.loginAsViewerUser(); - cy.visitKibana(serviceInventoryHref); + cy.visitKibana(serviceInventoryHref, { + localStorageOptions: [['apm.dismissedEntitiesInventoryCallout', 'false']], + }); }); it('has no detectable a11y violations on load', () => { @@ -80,9 +87,8 @@ describe.skip('Service inventory', () => { describe('Calls APIs', () => { beforeEach(() => { - cy.intercept('GET', '/internal/apm/services?*').as('servicesRequest'); - cy.intercept('POST', '/internal/apm/services/detailed_statistics?*').as( - 'detailedStatisticsRequest' + mainApiRequestsToIntercept.forEach(({ aliasName, endpoint, method }) => + cy.intercept(method, endpoint).as(aliasName) ); cy.loginAsViewerUser(); diff --git a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/commands.ts b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/commands.ts index d9c0ef08590ce..68d6bb08c9282 100644 --- a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/commands.ts +++ b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/commands.ts @@ -55,26 +55,32 @@ Cypress.Commands.add('loginAsApmReadPrivilegesWithWriteSettingsUser', () => { Cypress.Commands.add( 'loginAs', ({ username, password }: { username: string; password: string }) => { - // cy.session(username, () => { - const kibanaUrl = Cypress.env('KIBANA_URL'); - cy.log(`Logging in as ${username} on ${kibanaUrl}`); - cy.visit('/'); - cy.request({ - log: true, - method: 'POST', - url: `${kibanaUrl}/internal/security/login`, - body: { - providerType: 'basic', - providerName: 'basic', - currentURL: `${kibanaUrl}/login`, - params: { username, password }, - }, - headers: { - 'kbn-xsrf': 'e2e_test', + cy.session( + username, + () => { + const kibanaUrl = Cypress.env('KIBANA_URL'); + cy.log(`Logging in as ${username} on ${kibanaUrl}`); + cy.visit('/'); + cy.request({ + log: true, + method: 'POST', + url: `${kibanaUrl}/internal/security/login`, + body: { + providerType: 'basic', + providerName: 'basic', + currentURL: `${kibanaUrl}/login`, + params: { username, password }, + }, + headers: { + 'kbn-xsrf': 'e2e_test', + }, + }); + cy.visit('/'); }, - // }); - }); - cy.visit('/'); + { + cacheAcrossSpecs: true, + } + ); } ); @@ -87,8 +93,14 @@ Cypress.Commands.add('changeTimeRange', (value: string) => { cy.contains(value).click(); }); -Cypress.Commands.add('visitKibana', (url: string) => { - cy.visit(url); +Cypress.Commands.add('visitKibana', (url, options) => { + cy.visit(url, { + onBeforeLoad(win) { + if (options?.localStorageOptions && options.localStorageOptions.length > 0) { + options.localStorageOptions.forEach(([key, value]) => win.localStorage.setItem(key, value)); + } + }, + }); cy.getByTestSubj('kbnLoadingMessage').should('exist'); cy.getByTestSubj('kbnLoadingMessage').should('not.exist', { timeout: 50000, diff --git a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/types.d.ts b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/types.d.ts index 2c5a4ae35f311..f2d138bf46385 100644 --- a/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/types.d.ts +++ b/x-pack/plugins/observability_solution/apm/ftr_e2e/cypress/support/types.d.ts @@ -19,7 +19,7 @@ declare namespace Cypress { password: string; }): Cypress.Chainable>; changeTimeRange(value: string): void; - visitKibana(url: string): void; + visitKibana(url: string, options?: { localStorageOptions?: Array<[string, string]> }): void; selectAbsoluteTimeRange(start: string, end: string): void; expectAPIsToHaveBeenCalledWith(params: { apisIntercepted: string[]; value: string }): void; updateAdvancedSettings(settings: Record): void; diff --git a/x-pack/plugins/observability_solution/inventory/public/hooks/use_inventory_router.ts b/x-pack/plugins/observability_solution/inventory/public/hooks/use_inventory_router.ts index a917daf576ded..34aaf0b319d95 100644 --- a/x-pack/plugins/observability_solution/inventory/public/hooks/use_inventory_router.ts +++ b/x-pack/plugins/observability_solution/inventory/public/hooks/use_inventory_router.ts @@ -47,7 +47,7 @@ export function useInventoryRouter(): StatefulInventoryRouter { navigateToApp('inventory', { path: next, replace: true }); }, link: (path, ...args) => { - return http.basePath.prepend('/app/observability/inventory' + link(path, ...args)); + return http.basePath.prepend('/app/inventory' + link(path, ...args)); }, }), [navigateToApp, http.basePath] diff --git a/x-pack/plugins/observability_solution/observability_shared/common/locators/entity_inventory/entity_inventory_locator.ts b/x-pack/plugins/observability_solution/observability_shared/common/locators/entity_inventory/entity_inventory_locator.ts index deb820b0d5e0a..29045de48e143 100644 --- a/x-pack/plugins/observability_solution/observability_shared/common/locators/entity_inventory/entity_inventory_locator.ts +++ b/x-pack/plugins/observability_solution/observability_shared/common/locators/entity_inventory/entity_inventory_locator.ts @@ -16,8 +16,8 @@ export class EntitiesInventoryLocatorDefinition implements LocatorDefinition { return { - app: 'observability', - path: `/inventory`, + app: 'inventory', + path: `/`, state: {}, }; };