From e804ef2dc84f9518807d3ee48d878d3ba6173807 Mon Sep 17 00:00:00 2001 From: Mykola Harmash Date: Mon, 30 Oct 2023 11:49:47 +0100 Subject: [PATCH] [ObsUX] Enable Hosts advanced setting on serverless (#170035) Closes https://github.com/elastic/kibana/issues/169198 ## Summary * Adds Hosts advanced setting to the observability settings allowlist * Adds tests for Hosts sidenav item visibility https://github.com/elastic/kibana/assets/793851/3c9252c8-a4cb-4da8-aa60-23a8aeb60d4c # How to test * Run locally in serverless mode * Make sure "Observability Hosts view" toggle is visible on the Advanced Settings screen * Toggle the setting on and off, make sure sidenav properly reacts to the changes * Go to Infra settings screen * Toggle the same setting on and off, and also make sure sidenav properly reacts to the changes --- .../settings/observability_project/index.ts | 1 + .../page_objects/svl_common_navigation.ts | 11 ++++ .../test_suites/observability/infra/index.ts | 1 + .../observability/infra/navigation.ts | 63 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 x-pack/test_serverless/functional/test_suites/observability/infra/navigation.ts diff --git a/packages/serverless/settings/observability_project/index.ts b/packages/serverless/settings/observability_project/index.ts index a1ae020b8abe3..cae05789e3116 100644 --- a/packages/serverless/settings/observability_project/index.ts +++ b/packages/serverless/settings/observability_project/index.ts @@ -27,4 +27,5 @@ export const OBSERVABILITY_PROJECT_SETTINGS = [ settings.OBSERVABILITY_APM_TRACE_EXPLORER_TAB_ID, settings.OBSERVABILITY_ENABLE_AWS_LAMBDA_METRICS_ID, settings.OBSERVABILITY_APM_ENABLE_CRITICAL_PATH_ID, + settings.OBSERVABILITY_ENABLE_INFRASTRUCTURE_HOSTS_VIEW_ID, ]; diff --git a/x-pack/test_serverless/functional/page_objects/svl_common_navigation.ts b/x-pack/test_serverless/functional/page_objects/svl_common_navigation.ts index 483496315bd04..41101d5a653d4 100644 --- a/x-pack/test_serverless/functional/page_objects/svl_common_navigation.ts +++ b/x-pack/test_serverless/functional/page_objects/svl_common_navigation.ts @@ -65,6 +65,17 @@ export function SvlCommonNavigationProvider(ctx: FtrProviderContext) { expect(await getByVisibleText('~nav-item', by.text)).not.be(null); } }, + async expectLinkMissing( + by: { deepLinkId: AppDeepLinkId } | { navId: string } | { text: string } + ) { + if ('deepLinkId' in by) { + await testSubjects.missingOrFail(`~nav-item-deepLinkId-${by.deepLinkId}`); + } else if ('navId' in by) { + await testSubjects.missingOrFail(`~nav-item-id-${by.navId}`); + } else { + expect(await getByVisibleText('~nav-item', by.text)).be(null); + } + }, async expectLinkActive( by: { deepLinkId: AppDeepLinkId } | { navId: string } | { text: string } ) { diff --git a/x-pack/test_serverless/functional/test_suites/observability/infra/index.ts b/x-pack/test_serverless/functional/test_suites/observability/infra/index.ts index 814b0c97e4b1a..b646ba71f960e 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/infra/index.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/infra/index.ts @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('Observability Infra', function () { loadTestFile(require.resolve('./header_menu')); + loadTestFile(require.resolve('./navigation')); loadTestFile(require.resolve('./node_details')); loadTestFile(require.resolve('./hosts_page')); loadTestFile(require.resolve('./infra')); diff --git a/x-pack/test_serverless/functional/test_suites/observability/infra/navigation.ts b/x-pack/test_serverless/functional/test_suites/observability/infra/navigation.ts new file mode 100644 index 0000000000000..6f03c8831ce85 --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/observability/infra/navigation.ts @@ -0,0 +1,63 @@ +/* + * 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 { enableInfrastructureHostsView } from '@kbn/observability-plugin/common'; +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default ({ getPageObjects, getService }: FtrProviderContext) => { + const kibanaServer = getService('kibanaServer'); + const svlObltNavigation = getService('svlObltNavigation'); + const browser = getService('browser'); + const pageObjects = getPageObjects(['svlCommonPage', 'svlCommonNavigation', 'header']); + + const setHostsSetting = async (value: boolean) => { + await kibanaServer.uiSettings.update({ [enableInfrastructureHostsView]: value }); + await browser.refresh(); + await pageObjects.svlCommonNavigation.expectExists(); + }; + + const openInfraSection = async () => { + await pageObjects.svlCommonNavigation.sidenav.openSection('observability_project_nav.metrics'); + }; + + describe('Infra Side Navigation', () => { + before(async () => { + await pageObjects.svlCommonPage.login(); + await svlObltNavigation.navigateToLandingPage(); + }); + + after(async () => { + await pageObjects.svlCommonPage.forceLogout(); + }); + + describe('when Hosts settings is on', () => { + before(async () => { + await setHostsSetting(true); + await openInfraSection(); + }); + + it("shows the 'Hosts' nav item", async () => { + await pageObjects.svlCommonNavigation.sidenav.expectLinkExists({ + deepLinkId: 'metrics:hosts', + }); + }); + }); + + describe('when Hosts settings is off', () => { + before(async () => { + await setHostsSetting(false); + await openInfraSection(); + }); + + it("hides the 'Hosts' nav item", async () => { + await pageObjects.svlCommonNavigation.sidenav.expectLinkMissing({ + deepLinkId: 'metrics:hosts', + }); + }); + }); + }); +};