From 473c048041144ab911dca9f3498e25bb6c464f19 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Wed, 31 Jul 2024 16:10:51 -0700 Subject: [PATCH] Functional test for spaces grid --- .../spaces_grid/spaces_grid_page.tsx | 2 +- x-pack/test/functional/apps/spaces/index.ts | 1 + .../functional/apps/spaces/spaces_grid.ts | 47 +++++++++++++++++++ x-pack/test/functional/config.base.js | 3 ++ .../page_objects/space_selector_page.ts | 12 +++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 x-pack/test/functional/apps/spaces/spaces_grid.ts diff --git a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx index 549433c3b3078..e3069743cec42 100644 --- a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx +++ b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx @@ -292,7 +292,7 @@ export class SpacesGridPage extends Component { {this.state.activeSpace?.name === rowRecord.name && ( - + {i18n.translate('xpack.spaces.management.spacesGridPage.currentSpaceMarkerText', { defaultMessage: 'current', })} diff --git a/x-pack/test/functional/apps/spaces/index.ts b/x-pack/test/functional/apps/spaces/index.ts index aa034f4be012b..3fe77a1a4528b 100644 --- a/x-pack/test/functional/apps/spaces/index.ts +++ b/x-pack/test/functional/apps/spaces/index.ts @@ -14,5 +14,6 @@ export default function spacesApp({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./spaces_selection')); loadTestFile(require.resolve('./enter_space')); loadTestFile(require.resolve('./create_edit_space')); + loadTestFile(require.resolve('./spaces_grid')); }); } diff --git a/x-pack/test/functional/apps/spaces/spaces_grid.ts b/x-pack/test/functional/apps/spaces/spaces_grid.ts new file mode 100644 index 0000000000000..62363802db98a --- /dev/null +++ b/x-pack/test/functional/apps/spaces/spaces_grid.ts @@ -0,0 +1,47 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function enterSpaceFunctionalTests({ + getService, + getPageObjects, +}: FtrProviderContext) { + const kibanaServer = getService('kibanaServer'); + const PageObjects = getPageObjects(['security', 'spaceSelector', 'common']); + const spacesService = getService('spaces'); + const testSubjects = getService('testSubjects'); + + const anotherSpace = { + id: 'space2', + name: 'space2', + disabledFeatures: [], + }; + + describe('Spaces grid', function () { + before(async () => { + await spacesService.create(anotherSpace); + + await PageObjects.common.navigateToApp('spacesManagement'); + await testSubjects.existOrFail('spaces-grid-page'); + }); + + after(async () => { + await spacesService.delete('another-space'); + await kibanaServer.savedObjects.cleanStandardList(); + }); + + it('can switch to a space from the row in the grid', async () => { + // use the "current" badge confirm that Default is the current space + await testSubjects.existOrFail('spacesListCurrentBadge-default'); + // click the switch button of "another space" + await PageObjects.spaceSelector.clickSwitchSpaceButton('space2'); + // use the "current" badge confirm that "Another Space" is now the current space + await testSubjects.existOrFail('spacesListCurrentBadge-space2'); + }); + }); +} diff --git a/x-pack/test/functional/config.base.js b/x-pack/test/functional/config.base.js index 834aee5fbaa8c..56ecbef55759f 100644 --- a/x-pack/test/functional/config.base.js +++ b/x-pack/test/functional/config.base.js @@ -146,6 +146,9 @@ export default async function ({ readConfigFile }) { snapshotRestore: { pathname: '/app/management/data/snapshot_restore', }, + spacesManagement: { + pathname: '/app/management/kibana/spaces', + }, remoteClusters: { pathname: '/app/management/data/remote_clusters', }, diff --git a/x-pack/test/functional/page_objects/space_selector_page.ts b/x-pack/test/functional/page_objects/space_selector_page.ts index 00f28c5a63e48..ea9a7948410f3 100644 --- a/x-pack/test/functional/page_objects/space_selector_page.ts +++ b/x-pack/test/functional/page_objects/space_selector_page.ts @@ -212,9 +212,21 @@ export class SpaceSelectorPageObject extends FtrService { await this.testSubjects.setValue('descriptionSpaceText', descriptionSpace); } + async clickSwitchSpaceButton(spaceName: string) { + const collapsedButtonSelector = '[data-test-subj=euiCollapsedItemActionsButton]'; + // open context menu + await this.find.clickByCssSelector(`#${spaceName}-actions ${collapsedButtonSelector}`); + // click context menu item + await this.find.clickByCssSelector( + `.euiContextMenuItem[data-test-subj="${spaceName}-switchSpace"]` // can not use testSubj: multiple elements exist with the same data-test-subj + ); + } + async clickOnDeleteSpaceButton(spaceName: string) { const collapsedButtonSelector = '[data-test-subj=euiCollapsedItemActionsButton]'; + // open context menu await this.find.clickByCssSelector(`#${spaceName}-actions ${collapsedButtonSelector}`); + // click context menu item await this.testSubjects.click(`${spaceName}-deleteSpace`); }