From 133eebf22bb94a227f7f4ef1e796901770f06b24 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Thu, 2 Sep 2021 12:51:16 -0400 Subject: [PATCH 1/3] fixed missing tags api when loading saved dashboard. Added tests --- .../apps/dashboard/dashboard_tagging.ts | 92 +++++++++++++++++++ .../test/functional/apps/dashboard/index.ts | 1 + 2 files changed, 93 insertions(+) create mode 100644 x-pack/test/functional/apps/dashboard/dashboard_tagging.ts diff --git a/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts new file mode 100644 index 0000000000000..5d4c2fea0523a --- /dev/null +++ b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts @@ -0,0 +1,92 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const listingTable = getService('listingTable'); + const testSubjects = getService('testSubjects'); + const esArchiver = getService('esArchiver'); + const retry = getService('retry'); + const find = getService('find'); + const dashboardAddPanel = getService('dashboardAddPanel'); + const dashboardPanelActions = getService('dashboardPanelActions'); + const PageObjects = getPageObjects([ + 'common', + 'tagManagement', + 'header', + 'dashboard', + 'visualize', + 'lens', + ]); + + const dashboardTag = 'extremely-cool-dashboard'; + const dashboardTitle = 'Coolest Blank Dashboard'; + + describe.only('dashboard tagging', () => { + const verifyTagFromListingPage = async () => { + await PageObjects.dashboard.gotoDashboardLandingPage(); + await listingTable.waitUntilTableIsLoaded(); + + // open the filter dropdown + const filterButton = await find.byCssSelector('.euiFilterGroup .euiFilterButton'); + await filterButton.click(); + await testSubjects.click( + `tag-searchbar-option-${PageObjects.tagManagement.testSubjFriendly(dashboardTag)}` + ); + // click elsewhere to close the filter dropdown + const searchFilter = await find.byCssSelector('.euiPageBody .euiFieldSearch'); + await searchFilter.click(); + // wait until the table refreshes + await listingTable.waitUntilTableIsLoaded(); + const itemNames = await listingTable.getAllItemsNames(); + expect(itemNames).to.contain(dashboardTitle); + }; + + const createTagFromDashboard = async () => { + await testSubjects.click('dashboardSaveMenuItem'); + await testSubjects.click('savedObjectTagSelector'); + await testSubjects.click(`tagSelectorOption-action__create`); + + expect(await PageObjects.tagManagement.tagModal.isOpened()).to.be(true); + + await PageObjects.tagManagement.tagModal.fillForm( + { + name: dashboardTag, + color: '#fc03db', + description: '', + }, + { + submit: true, + } + ); + expect(await PageObjects.tagManagement.tagModal.isOpened()).to.be(false); + }; + + before(async () => { + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/logstash_functional'); + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/lens/basic'); + await PageObjects.common.navigateToApp('dashboard'); + await PageObjects.dashboard.preserveCrossAppState(); + await PageObjects.dashboard.clickNewDashboard(); + }); + + it('adds a new tag to a new Dashboard', async () => { + await createTagFromDashboard(); + PageObjects.dashboard.saveDashboard(dashboardTitle, { tags: [dashboardTag] }, false); + await verifyTagFromListingPage(); + }); + + it('retains its saved object tags after quicksave', async () => { + await PageObjects.dashboard.gotoDashboardEditMode(dashboardTitle); + await PageObjects.dashboard.useMargins(false); // turn margins off to cause quicksave to be enabled + await PageObjects.dashboard.clickQuickSave(); + await verifyTagFromListingPage(); + }); + }); +} diff --git a/x-pack/test/functional/apps/dashboard/index.ts b/x-pack/test/functional/apps/dashboard/index.ts index 5979ae378c22b..73c9b83de917f 100644 --- a/x-pack/test/functional/apps/dashboard/index.ts +++ b/x-pack/test/functional/apps/dashboard/index.ts @@ -17,6 +17,7 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./drilldowns')); loadTestFile(require.resolve('./sync_colors')); loadTestFile(require.resolve('./_async_dashboard')); + loadTestFile(require.resolve('./dashboard_tagging')); loadTestFile(require.resolve('./dashboard_lens_by_value')); loadTestFile(require.resolve('./dashboard_maps_by_value')); From 77726fb0f9cf2a7f320f62114fd171b9afa3d4c9 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Thu, 2 Sep 2021 12:53:03 -0400 Subject: [PATCH 2/3] fixed missing tags api when loading saved dashboard. Added tests --- .../hooks/use_dashboard_app_state.ts | 1 + .../functional/page_objects/dashboard_page.ts | 20 ++++++++++++------- .../apps/dashboard/dashboard_tagging.ts | 5 +---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts b/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts index c01cd43b1f1e3..bea9ec8af291d 100644 --- a/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts +++ b/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts @@ -127,6 +127,7 @@ export const useDashboardAppState = ({ savedDashboards, kbnUrlStateStorage, initializerContext, + savedObjectsTagging, isEmbeddedExternally, dashboardCapabilities, dispatchDashboardStateChange, diff --git a/test/functional/page_objects/dashboard_page.ts b/test/functional/page_objects/dashboard_page.ts index 210c8f61b2391..3d2ba53e7ba98 100644 --- a/test/functional/page_objects/dashboard_page.ts +++ b/test/functional/page_objects/dashboard_page.ts @@ -284,9 +284,11 @@ export class DashboardPageObject extends FtrService { } public async clickQuickSave() { - await this.expectQuickSaveButtonEnabled(); - this.log.debug('clickQuickSave'); - await this.testSubjects.click('dashboardQuickSaveMenuItem'); + await this.retry.try(async () => { + await this.expectQuickSaveButtonEnabled(); + this.log.debug('clickQuickSave'); + await this.testSubjects.click('dashboardQuickSaveMenuItem'); + }); } public async clickNewDashboard(continueEditing = false) { @@ -392,10 +394,11 @@ export class DashboardPageObject extends FtrService { */ public async saveDashboard( dashboardName: string, - saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true, exitFromEditMode: true } + saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true, exitFromEditMode: true }, + clickMenuItem = true ) { await this.retry.try(async () => { - await this.enterDashboardTitleAndClickSave(dashboardName, saveOptions); + await this.enterDashboardTitleAndClickSave(dashboardName, saveOptions, clickMenuItem); if (saveOptions.needsConfirm) { await this.ensureDuplicateTitleCallout(); @@ -435,9 +438,12 @@ export class DashboardPageObject extends FtrService { */ public async enterDashboardTitleAndClickSave( dashboardTitle: string, - saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true } + saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true }, + clickMenuItem = true ) { - await this.testSubjects.click('dashboardSaveMenuItem'); + if (clickMenuItem) { + await this.testSubjects.click('dashboardSaveMenuItem'); + } const modalDialog = await this.testSubjects.find('savedObjectSaveModal'); this.log.debug('entering new title'); diff --git a/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts index 5d4c2fea0523a..c62ff641debd8 100644 --- a/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts +++ b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts @@ -12,10 +12,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const listingTable = getService('listingTable'); const testSubjects = getService('testSubjects'); const esArchiver = getService('esArchiver'); - const retry = getService('retry'); const find = getService('find'); - const dashboardAddPanel = getService('dashboardAddPanel'); - const dashboardPanelActions = getService('dashboardPanelActions'); const PageObjects = getPageObjects([ 'common', 'tagManagement', @@ -28,7 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const dashboardTag = 'extremely-cool-dashboard'; const dashboardTitle = 'Coolest Blank Dashboard'; - describe.only('dashboard tagging', () => { + describe('dashboard tagging', () => { const verifyTagFromListingPage = async () => { await PageObjects.dashboard.gotoDashboardLandingPage(); await listingTable.waitUntilTableIsLoaded(); From 129e3f5bd557a5caf472c78e64b089d48158a5c8 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Fri, 3 Sep 2021 12:02:07 -0400 Subject: [PATCH 3/3] Remove second tag selection --- x-pack/test/functional/apps/dashboard/dashboard_tagging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts index c62ff641debd8..707b3877a70b5 100644 --- a/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts +++ b/x-pack/test/functional/apps/dashboard/dashboard_tagging.ts @@ -75,7 +75,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('adds a new tag to a new Dashboard', async () => { await createTagFromDashboard(); - PageObjects.dashboard.saveDashboard(dashboardTitle, { tags: [dashboardTag] }, false); + PageObjects.dashboard.saveDashboard(dashboardTitle, {}, false); await verifyTagFromListingPage(); });