From 068aab16787ac25f247d97f164a7558e620549d0 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Fri, 15 Jan 2021 17:19:59 -0500 Subject: [PATCH] removed code duplication --- .../functional/page_objects/visualize_page.ts | 46 +++++++++++-------- .../test/functional/page_objects/lens_page.ts | 38 ++++----------- .../functional/tests/visualize_integration.ts | 16 +------ 3 files changed, 38 insertions(+), 62 deletions(-) diff --git a/test/functional/page_objects/visualize_page.ts b/test/functional/page_objects/visualize_page.ts index 14160cc106261..d5df15968f741 100644 --- a/test/functional/page_objects/visualize_page.ts +++ b/test/functional/page_objects/visualize_page.ts @@ -27,6 +27,11 @@ interface VisualizeSaveModalArgs { dashboardId?: string; } +type DashboardPickerOption = + | 'add-to-library-option' + | 'existing-dashboard-option' + | 'new-dashboard-option'; + export function VisualizePageProvider({ getService, getPageObjects }: FtrProviderContext) { const testSubjects = getService('testSubjects'); const retry = getService('retry'); @@ -353,11 +358,27 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide } } - public async saveVisualization( + public async saveVisualization(vizName: string, saveModalArgs: VisualizeSaveModalArgs = {}) { + await this.ensureSavePanelOpen(); + + await this.setSaveModalValues(vizName, saveModalArgs); + log.debug('Click Save Visualization button'); + + await testSubjects.click('confirmSaveSavedObjectButton'); + + // Confirm that the Visualization has actually been saved + await testSubjects.existOrFail('saveVisualizationSuccess'); + const message = await common.closeToast(); + await header.waitUntilLoadingHasFinished(); + await common.waitForSaveModalToClose(); + + return message; + } + + public async setSaveModalValues( vizName: string, { saveAsNew, redirectToOrigin, addToDashboard, dashboardId }: VisualizeSaveModalArgs = {} ) { - await this.ensureSavePanelOpen(); await testSubjects.setValue('savedObjectTitle', vizName); const saveAsNewCheckboxExists = await testSubjects.exists('saveAsNewCheckbox'); @@ -376,30 +397,19 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide const dashboardSelectorExists = await testSubjects.exists('add-to-dashboard-options'); if (dashboardSelectorExists) { - const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); - let optionSelector = 'add-to-library-option'; + let option: DashboardPickerOption = 'add-to-library-option'; if (addToDashboard) { - optionSelector = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option'; + option = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option'; } - log.debug('dashboard selector exists, choosing option:', optionSelector); - const label = await dashboardSelector.findByCssSelector(`label[for="${optionSelector}"]`); + log.debug('save modal dashboard selector, choosing option:', option); + const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); + const label = await dashboardSelector.findByCssSelector(`label[for="${option}"]`); await label.click(); if (dashboardId) { // TODO - selecting an existing dashboard } } - log.debug('Click Save Visualization button'); - - await testSubjects.click('confirmSaveSavedObjectButton'); - - // Confirm that the Visualization has actually been saved - await testSubjects.existOrFail('saveVisualizationSuccess'); - const message = await common.closeToast(); - await header.waitUntilLoadingHasFinished(); - await common.waitForSaveModalToClose(); - - return message; } public async saveVisualizationExpectSuccess( diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts index dc19de47bbb41..04c660847bcee 100644 --- a/x-pack/test/functional/page_objects/lens_page.ts +++ b/x-pack/test/functional/page_objects/lens_page.ts @@ -16,7 +16,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont const find = getService('find'); const comboBox = getService('comboBox'); const browser = getService('browser'); - const PageObjects = getPageObjects(['header', 'timePicker', 'common']); + const PageObjects = getPageObjects(['header', 'timePicker', 'common', 'visualize']); return logWrapper('lensPage', log, { /** @@ -275,39 +275,17 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont saveAsNew?: boolean, redirectToOrigin?: boolean, addToDashboard?: boolean, - dashboardId?: boolean + dashboardId?: string ) { await PageObjects.header.waitUntilLoadingHasFinished(); await testSubjects.click('lnsApp_saveButton'); - await testSubjects.setValue('savedObjectTitle', title); - const saveAsNewCheckboxExists = await testSubjects.exists('saveAsNewCheckbox'); - if (saveAsNewCheckboxExists) { - const state = saveAsNew ? 'check' : 'uncheck'; - await testSubjects.setEuiSwitch('saveAsNewCheckbox', state); - } - - const redirectToOriginCheckboxExists = await testSubjects.exists('returnToOriginModeSwitch'); - if (redirectToOriginCheckboxExists) { - const state = redirectToOrigin ? 'check' : 'uncheck'; - await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state); - } - - const dashboardSelectorExists = await testSubjects.exists('add-to-dashboard-options'); - if (dashboardSelectorExists) { - const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); - let optionSelector = 'add-to-library-option'; - if (addToDashboard) { - optionSelector = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option'; - } - log.debug('dashboard selector exists, choosing option:', optionSelector); - const label = await dashboardSelector.findByCssSelector(`label[for="${optionSelector}"]`); - await label.click(); - - if (dashboardId) { - // TODO - selecting an existing dashboard - } - } + await PageObjects.visualize.setSaveModalValues(title, { + saveAsNew, + redirectToOrigin, + addToDashboard, + dashboardId, + }); await testSubjects.click('confirmSaveSavedObjectButton'); await retry.waitForWithTimeout('Save modal to disappear', 1000, () => diff --git a/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts b/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts index 3353078ae0ffa..e92ba226f3959 100644 --- a/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts +++ b/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts @@ -94,13 +94,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.visEditor.clickGo(); await PageObjects.visualize.ensureSavePanelOpen(); - await testSubjects.setValue('savedObjectTitle', 'My new markdown viz'); - - const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); - const label = await dashboardSelector.findByCssSelector( - `label[for="add-to-library-option"]` - ); - await label.click(); + await PageObjects.visualize.setSaveModalValues('My new markdown viz'); await selectSavedObjectTags('tag-1'); @@ -125,13 +119,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.visEditor.clickGo(); await PageObjects.visualize.ensureSavePanelOpen(); - await testSubjects.setValue('savedObjectTitle', 'vis-with-new-tag'); - - const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); - const label = await dashboardSelector.findByCssSelector( - `label[for="add-to-library-option"]` - ); - await label.click(); + await PageObjects.visualize.setSaveModalValues('vis-with-new-tag'); await testSubjects.click('savedObjectTagSelector'); await testSubjects.click(`tagSelectorOption-action__create`);