From 70ebf697d8ff9cecfa839fdbb9a045dbcdca076a Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 24 May 2021 16:13:47 -0700 Subject: [PATCH] [ftr] migrate dashboard services to FtrService class --- .../services/dashboard/add_panel.ts | 452 +++++++------ .../services/dashboard/expectations.ts | 454 ++++++------- test/functional/services/dashboard/index.ts | 10 +- .../services/dashboard/panel_actions.ts | 596 +++++++++--------- .../services/dashboard/replace_panel.ts | 136 ++-- .../services/dashboard/visualizations.ts | 188 +++--- test/functional/services/index.ts | 20 +- 7 files changed, 928 insertions(+), 928 deletions(-) diff --git a/test/functional/services/dashboard/add_panel.ts b/test/functional/services/dashboard/add_panel.ts index a4e0c8b2647dd..98e947541b52d 100644 --- a/test/functional/services/dashboard/add_panel.ts +++ b/test/functional/services/dashboard/add_panel.ts @@ -6,235 +6,233 @@ * Side Public License, v 1. */ -import { FtrProviderContext } from '../../ftr_provider_context'; - -export function DashboardAddPanelProvider({ getService, getPageObjects }: FtrProviderContext) { - const log = getService('log'); - const retry = getService('retry'); - const testSubjects = getService('testSubjects'); - const flyout = getService('flyout'); - const PageObjects = getPageObjects(['header', 'common']); - - return new (class DashboardAddPanel { - async clickOpenAddPanel() { - log.debug('DashboardAddPanel.clickOpenAddPanel'); - await testSubjects.click('dashboardAddPanelButton'); - // Give some time for the animation to complete - await PageObjects.common.sleep(500); - } - - async clickCreateNewLink() { - log.debug('DashboardAddPanel.clickAddNewPanelButton'); - await testSubjects.click('dashboardAddNewPanelButton'); - // Give some time for the animation to complete - await PageObjects.common.sleep(500); - } - - async clickQuickButton(visType: string) { - log.debug(`DashboardAddPanel.clickQuickButton${visType}`); - await testSubjects.click(`dashboardQuickButton${visType}`); - } - - async clickMarkdownQuickButton() { - await this.clickQuickButton('markdown'); - } - - async clickMapQuickButton() { - await this.clickQuickButton('map'); - } - - async clickEditorMenuButton() { - log.debug('DashboardAddPanel.clickEditorMenuButton'); - await testSubjects.click('dashboardEditorMenuButton'); - } - - async clickAggBasedVisualizations() { - log.debug('DashboardAddPanel.clickEditorMenuAggBasedMenuItem'); - await testSubjects.click('dashboardEditorAggBasedMenuItem'); - } - - async clickVisType(visType: string) { - log.debug('DashboardAddPanel.clickVisType'); - await testSubjects.click(`visType-${visType}`); - } - - async clickEmbeddableFactoryGroupButton(groupId: string) { - log.debug('DashboardAddPanel.clickEmbeddableFactoryGroupButton'); - await testSubjects.click(`dashboardEditorMenu-${groupId}Group`); - } - - async clickAddNewEmbeddableLink(type: string) { - await testSubjects.click(`createNew-${type}`); - } - - async toggleFilterPopover() { - log.debug('DashboardAddPanel.toggleFilter'); - await testSubjects.click('savedObjectFinderFilterButton'); - } - - async toggleFilter(type: string) { - log.debug(`DashboardAddPanel.addToFilter(${type})`); - await this.waitForListLoading(); - await this.toggleFilterPopover(); - await testSubjects.click(`savedObjectFinderFilter-${type}`); - await this.toggleFilterPopover(); - } - - async addEveryEmbeddableOnCurrentPage() { - log.debug('addEveryEmbeddableOnCurrentPage'); - const itemList = await testSubjects.find('savedObjectFinderItemList'); - const embeddableList: string[] = []; - await retry.try(async () => { - const embeddableRows = await itemList.findAllByCssSelector('li'); - for (let i = 0; i < embeddableRows.length; i++) { - const name = await embeddableRows[i].getVisibleText(); - - if (embeddableList.includes(name)) { - // already added this one - continue; - } - - await embeddableRows[i].click(); - await PageObjects.common.closeToast(); - embeddableList.push(name); +import { FtrService } from '../../ftr_provider_context'; + +export class DashboardAddPanelService extends FtrService { + private readonly log = this.ctx.getService('log'); + private readonly retry = this.ctx.getService('retry'); + private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly flyout = this.ctx.getService('flyout'); + private readonly PageObjects = this.ctx.getPageObjects(['header', 'common']); + + async clickOpenAddPanel() { + this.log.debug('DashboardAddPanel.clickOpenAddPanel'); + await this.testSubjects.click('dashboardAddPanelButton'); + // Give some time for the animation to complete + await this.PageObjects.common.sleep(500); + } + + async clickCreateNewLink() { + this.log.debug('DashboardAddPanel.clickAddNewPanelButton'); + await this.testSubjects.click('dashboardAddNewPanelButton'); + // Give some time for the animation to complete + await this.PageObjects.common.sleep(500); + } + + async clickQuickButton(visType: string) { + this.log.debug(`DashboardAddPanel.clickQuickButton${visType}`); + await this.testSubjects.click(`dashboardQuickButton${visType}`); + } + + async clickMarkdownQuickButton() { + await this.clickQuickButton('markdown'); + } + + async clickMapQuickButton() { + await this.clickQuickButton('map'); + } + + async clickEditorMenuButton() { + this.log.debug('DashboardAddPanel.clickEditorMenuButton'); + await this.testSubjects.click('dashboardEditorMenuButton'); + } + + async clickAggBasedVisualizations() { + this.log.debug('DashboardAddPanel.clickEditorMenuAggBasedMenuItem'); + await this.testSubjects.click('dashboardEditorAggBasedMenuItem'); + } + + async clickVisType(visType: string) { + this.log.debug('DashboardAddPanel.clickVisType'); + await this.testSubjects.click(`visType-${visType}`); + } + + async clickEmbeddableFactoryGroupButton(groupId: string) { + this.log.debug('DashboardAddPanel.clickEmbeddableFactoryGroupButton'); + await this.testSubjects.click(`dashboardEditorMenu-${groupId}Group`); + } + + async clickAddNewEmbeddableLink(type: string) { + await this.testSubjects.click(`createNew-${type}`); + } + + async toggleFilterPopover() { + this.log.debug('DashboardAddPanel.toggleFilter'); + await this.testSubjects.click('savedObjectFinderFilterButton'); + } + + async toggleFilter(type: string) { + this.log.debug(`DashboardAddPanel.addToFilter(${type})`); + await this.waitForListLoading(); + await this.toggleFilterPopover(); + await this.testSubjects.click(`savedObjectFinderFilter-${type}`); + await this.toggleFilterPopover(); + } + + async addEveryEmbeddableOnCurrentPage() { + this.log.debug('addEveryEmbeddableOnCurrentPage'); + const itemList = await this.testSubjects.find('savedObjectFinderItemList'); + const embeddableList: string[] = []; + await this.retry.try(async () => { + const embeddableRows = await itemList.findAllByCssSelector('li'); + for (let i = 0; i < embeddableRows.length; i++) { + const name = await embeddableRows[i].getVisibleText(); + + if (embeddableList.includes(name)) { + // already added this one + continue; } - }); - log.debug(`Added ${embeddableList.length} embeddables`); - return embeddableList; - } - - async clickPagerNextButton() { - // Clear all toasts that could hide pagination controls - await PageObjects.common.clearAllToasts(); - - const isNext = await testSubjects.exists('pagination-button-next'); - if (!isNext) { - return false; - } - - const pagerNextButton = await testSubjects.find('pagination-button-next'); - - const isDisabled = await pagerNextButton.getAttribute('disabled'); - if (isDisabled != null) { - return false; - } - - await PageObjects.header.waitUntilLoadingHasFinished(); - await pagerNextButton.click(); - await PageObjects.header.waitUntilLoadingHasFinished(); - return true; - } - - async isAddPanelOpen() { - log.debug('DashboardAddPanel.isAddPanelOpen'); - return await testSubjects.exists('dashboardAddPanel'); - } - async ensureAddPanelIsShowing() { - log.debug('DashboardAddPanel.ensureAddPanelIsShowing'); - const isOpen = await this.isAddPanelOpen(); - if (!isOpen) { - await retry.try(async () => { - await this.clickOpenAddPanel(); - const isNowOpen = await this.isAddPanelOpen(); - if (!isNowOpen) { - throw new Error('Add panel still not open, trying again.'); - } - }); + await embeddableRows[i].click(); + await this.PageObjects.common.closeToast(); + embeddableList.push(name); } + }); + this.log.debug(`Added ${embeddableList.length} embeddables`); + return embeddableList; + } + + async clickPagerNextButton() { + // Clear all toasts that could hide pagination controls + await this.PageObjects.common.clearAllToasts(); + + const isNext = await this.testSubjects.exists('pagination-button-next'); + if (!isNext) { + return false; + } + + const pagerNextButton = await this.testSubjects.find('pagination-button-next'); + + const isDisabled = await pagerNextButton.getAttribute('disabled'); + if (isDisabled != null) { + return false; + } + + await this.PageObjects.header.waitUntilLoadingHasFinished(); + await pagerNextButton.click(); + await this.PageObjects.header.waitUntilLoadingHasFinished(); + return true; + } + + async isAddPanelOpen() { + this.log.debug('DashboardAddPanel.isAddPanelOpen'); + return await this.testSubjects.exists('dashboardAddPanel'); + } + + async ensureAddPanelIsShowing() { + this.log.debug('DashboardAddPanel.ensureAddPanelIsShowing'); + const isOpen = await this.isAddPanelOpen(); + if (!isOpen) { + await this.retry.try(async () => { + await this.clickOpenAddPanel(); + const isNowOpen = await this.isAddPanelOpen(); + if (!isNowOpen) { + throw new Error('Add panel still not open, trying again.'); + } + }); } - - async waitForListLoading() { - await testSubjects.waitForDeleted('savedObjectFinderLoadingIndicator'); - } - - async closeAddPanel() { - await flyout.ensureClosed('dashboardAddPanel'); - } - - async addEveryVisualization(filter: string) { - log.debug('DashboardAddPanel.addEveryVisualization'); - await this.ensureAddPanelIsShowing(); - await this.toggleFilter('visualization'); - if (filter) { - await this.filterEmbeddableNames(filter.replace('-', ' ')); - } - let morePages = true; - const vizList: string[][] = []; - while (morePages) { - vizList.push(await this.addEveryEmbeddableOnCurrentPage()); - morePages = await this.clickPagerNextButton(); - } - await this.closeAddPanel(); - return vizList.reduce((acc, list) => [...acc, ...list], []); - } - - async addEverySavedSearch(filter: string) { - log.debug('DashboardAddPanel.addEverySavedSearch'); - await this.ensureAddPanelIsShowing(); - await this.toggleFilter('search'); - const searchList = []; - if (filter) { - await this.filterEmbeddableNames(filter.replace('-', ' ')); - } - let morePages = true; - while (morePages) { - searchList.push(await this.addEveryEmbeddableOnCurrentPage()); - morePages = await this.clickPagerNextButton(); - } - await this.closeAddPanel(); - return searchList.reduce((acc, list) => [...acc, ...list], []); - } - - async addSavedSearch(searchName: string) { - return this.addEmbeddable(searchName, 'search'); - } - - async addSavedSearches(searches: string[]) { - for (const name of searches) { - await this.addSavedSearch(name); - } - } - - async addVisualizations(visualizations: string[]) { - log.debug('DashboardAddPanel.addVisualizations'); - const vizList = []; - for (const vizName of visualizations) { - await this.addVisualization(vizName); - vizList.push(vizName); - } - return vizList; - } - - async addVisualization(vizName: string) { - return this.addEmbeddable(vizName, 'visualization'); - } - - async addEmbeddable(embeddableName: string, embeddableType: string) { - log.debug( - `DashboardAddPanel.addEmbeddable, name: ${embeddableName}, type: ${embeddableType}` - ); - await this.ensureAddPanelIsShowing(); - await this.toggleFilter(embeddableType); - await this.filterEmbeddableNames(`"${embeddableName.replace('-', ' ')}"`); - await testSubjects.click(`savedObjectTitle${embeddableName.split(' ').join('-')}`); - await testSubjects.exists('addObjectToDashboardSuccess'); - await this.closeAddPanel(); - return embeddableName; - } - - async filterEmbeddableNames(name: string) { - // The search input field may be disabled while the table is loading so wait for it - await this.waitForListLoading(); - await testSubjects.setValue('savedObjectFinderSearchInput', name); - await this.waitForListLoading(); - } - - async panelAddLinkExists(name: string) { - log.debug(`DashboardAddPanel.panelAddLinkExists(${name})`); - await this.ensureAddPanelIsShowing(); - await this.filterEmbeddableNames(`"${name}"`); - return await testSubjects.exists(`savedObjectTitle${name.split(' ').join('-')}`); - } - })(); + } + + async waitForListLoading() { + await this.testSubjects.waitForDeleted('savedObjectFinderLoadingIndicator'); + } + + async closeAddPanel() { + await this.flyout.ensureClosed('dashboardAddPanel'); + } + + async addEveryVisualization(filter: string) { + this.log.debug('DashboardAddPanel.addEveryVisualization'); + await this.ensureAddPanelIsShowing(); + await this.toggleFilter('visualization'); + if (filter) { + await this.filterEmbeddableNames(filter.replace('-', ' ')); + } + let morePages = true; + const vizList: string[][] = []; + while (morePages) { + vizList.push(await this.addEveryEmbeddableOnCurrentPage()); + morePages = await this.clickPagerNextButton(); + } + await this.closeAddPanel(); + return vizList.reduce((acc, list) => [...acc, ...list], []); + } + + async addEverySavedSearch(filter: string) { + this.log.debug('DashboardAddPanel.addEverySavedSearch'); + await this.ensureAddPanelIsShowing(); + await this.toggleFilter('search'); + const searchList = []; + if (filter) { + await this.filterEmbeddableNames(filter.replace('-', ' ')); + } + let morePages = true; + while (morePages) { + searchList.push(await this.addEveryEmbeddableOnCurrentPage()); + morePages = await this.clickPagerNextButton(); + } + await this.closeAddPanel(); + return searchList.reduce((acc, list) => [...acc, ...list], []); + } + + async addSavedSearch(searchName: string) { + return this.addEmbeddable(searchName, 'search'); + } + + async addSavedSearches(searches: string[]) { + for (const name of searches) { + await this.addSavedSearch(name); + } + } + + async addVisualizations(visualizations: string[]) { + this.log.debug('DashboardAddPanel.addVisualizations'); + const vizList = []; + for (const vizName of visualizations) { + await this.addVisualization(vizName); + vizList.push(vizName); + } + return vizList; + } + + async addVisualization(vizName: string) { + return this.addEmbeddable(vizName, 'visualization'); + } + + async addEmbeddable(embeddableName: string, embeddableType: string) { + this.log.debug( + `DashboardAddPanel.addEmbeddable, name: ${embeddableName}, type: ${embeddableType}` + ); + await this.ensureAddPanelIsShowing(); + await this.toggleFilter(embeddableType); + await this.filterEmbeddableNames(`"${embeddableName.replace('-', ' ')}"`); + await this.testSubjects.click(`savedObjectTitle${embeddableName.split(' ').join('-')}`); + await this.testSubjects.exists('addObjectToDashboardSuccess'); + await this.closeAddPanel(); + return embeddableName; + } + + async filterEmbeddableNames(name: string) { + // The search input field may be disabled while the table is loading so wait for it + await this.waitForListLoading(); + await this.testSubjects.setValue('savedObjectFinderSearchInput', name); + await this.waitForListLoading(); + } + + async panelAddLinkExists(name: string) { + this.log.debug(`DashboardAddPanel.panelAddLinkExists(${name})`); + await this.ensureAddPanelIsShowing(); + await this.filterEmbeddableNames(`"${name}"`); + return await this.testSubjects.exists(`savedObjectTitle${name.split(' ').join('-')}`); + } } diff --git a/test/functional/services/dashboard/expectations.ts b/test/functional/services/dashboard/expectations.ts index c58fdd4d0305b..34a4a9de7899a 100644 --- a/test/functional/services/dashboard/expectations.ts +++ b/test/functional/services/dashboard/expectations.ts @@ -7,263 +7,271 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import { FtrService } from '../../ftr_provider_context'; import { WebElementWrapper } from '../lib/web_element_wrapper'; -export function DashboardExpectProvider({ getService, getPageObjects }: FtrProviderContext) { - const log = getService('log'); - const retry = getService('retry'); - const testSubjects = getService('testSubjects'); - const find = getService('find'); - const filterBar = getService('filterBar'); - const PageObjects = getPageObjects(['dashboard', 'visualize', 'visChart']); - const findTimeout = 2500; +export class DashboardExpectService extends FtrService { + private readonly log = this.ctx.getService('log'); + private readonly retry = this.ctx.getService('retry'); + private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly find = this.ctx.getService('find'); + private readonly filterBar = this.ctx.getService('filterBar'); + private readonly PageObjects = this.ctx.getPageObjects(['dashboard', 'visualize', 'visChart']); + private readonly findTimeout = 2500; - return new (class DashboardExpect { - async panelCount(expectedCount: number) { - log.debug(`DashboardExpect.panelCount(${expectedCount})`); - await retry.try(async () => { - const panelCount = await PageObjects.dashboard.getPanelCount(); - expect(panelCount).to.be(expectedCount); - }); - } + async panelCount(expectedCount: number) { + this.log.debug(`DashboardExpect.panelCount(${expectedCount})`); + await this.retry.try(async () => { + const panelCount = await this.PageObjects.dashboard.getPanelCount(); + expect(panelCount).to.be(expectedCount); + }); + } - async visualizationsArePresent(vizList: string[]) { - log.debug('Checking all visualisations are present on dashsboard'); - let notLoaded = await PageObjects.dashboard.getNotLoadedVisualizations(vizList); - // TODO: Determine issue occasionally preventing 'geo map' from loading - notLoaded = notLoaded.filter((x) => x !== 'Rendering Test: geo map'); - expect(notLoaded).to.be.empty(); - } + async visualizationsArePresent(vizList: string[]) { + this.log.debug('Checking all visualisations are present on dashsboard'); + let notLoaded = await this.PageObjects.dashboard.getNotLoadedVisualizations(vizList); + // TODO: Determine issue occasionally preventing 'geo map' from loading + notLoaded = notLoaded.filter((x) => x !== 'Rendering Test: geo map'); + expect(notLoaded).to.be.empty(); + } - async selectedLegendColorCount(color: string, expectedCount: number) { - log.debug(`DashboardExpect.selectedLegendColorCount(${color}, ${expectedCount})`); - await retry.try(async () => { - const selectedLegendColor = await testSubjects.findAll( - `legendSelectedColor-${color}`, - findTimeout - ); - expect(selectedLegendColor.length).to.be(expectedCount); - }); - } + async selectedLegendColorCount(color: string, expectedCount: number) { + this.log.debug(`DashboardExpect.selectedLegendColorCount(${color}, ${expectedCount})`); + await this.retry.try(async () => { + const selectedLegendColor = await this.testSubjects.findAll( + `legendSelectedColor-${color}`, + this.findTimeout + ); + expect(selectedLegendColor.length).to.be(expectedCount); + }); + } - async docTableFieldCount(expectedCount: number) { - log.debug(`DashboardExpect.docTableFieldCount(${expectedCount})`); - await retry.try(async () => { - const docTableCells = await testSubjects.findAll('docTableField', findTimeout); - expect(docTableCells.length).to.be(expectedCount); - }); - } + async docTableFieldCount(expectedCount: number) { + this.log.debug(`DashboardExpect.docTableFieldCount(${expectedCount})`); + await this.retry.try(async () => { + const docTableCells = await this.testSubjects.findAll('docTableField', this.findTimeout); + expect(docTableCells.length).to.be(expectedCount); + }); + } - async fieldSuggestions(expectedFields: string[]) { - log.debug(`DashboardExpect.fieldSuggestions(${expectedFields})`); - const fields = await filterBar.getFilterEditorFields(); - expectedFields.forEach((expectedField) => { - expect(fields).to.contain(expectedField); - }); - } + async fieldSuggestions(expectedFields: string[]) { + this.log.debug(`DashboardExpect.fieldSuggestions(${expectedFields})`); + const fields = await this.filterBar.getFilterEditorFields(); + expectedFields.forEach((expectedField) => { + expect(fields).to.contain(expectedField); + }); + } + + async legendValuesToExist(legendValues: string[]) { + this.log.debug(`DashboardExpect.legendValuesToExist(${legendValues})`); + await Promise.all( + legendValues.map(async (legend) => { + await this.retry.try(async () => { + const legendValueExists = await this.testSubjects.exists(`legend-${legend}`); + expect(legendValueExists).to.be(true); + }); + }) + ); + } - async legendValuesToExist(legendValues: string[]) { - log.debug(`DashboardExpect.legendValuesToExist(${legendValues})`); + async textWithinElementsExists(texts: string[], getElementsFn: Function) { + this.log.debug(`DashboardExpect.textWithinElementsExists(${texts})`); + await this.retry.try(async () => { + const elements: WebElementWrapper[] = await getElementsFn(); + const elementTexts: string[] = []; await Promise.all( - legendValues.map(async (legend) => { - await retry.try(async () => { - const legendValueExists = await testSubjects.exists(`legend-${legend}`); - expect(legendValueExists).to.be(true); - }); + elements.map(async (element) => { + elementTexts.push(await element.getVisibleText()); }) ); - } - - async textWithinElementsExists(texts: string[], getElementsFn: Function) { - log.debug(`DashboardExpect.textWithinElementsExists(${texts})`); - await retry.try(async () => { - const elements: WebElementWrapper[] = await getElementsFn(); - const elementTexts: string[] = []; - await Promise.all( - elements.map(async (element) => { - elementTexts.push(await element.getVisibleText()); - }) - ); - log.debug(`Found ${elements.length} elements with values: ${JSON.stringify(elementTexts)}`); - texts.forEach((value) => { - const indexOfValue = elementTexts.indexOf(value); - expect(indexOfValue).to.be.greaterThan(-1); - elementTexts.splice(indexOfValue, 1); - }); + this.log.debug( + `Found ${elements.length} elements with values: ${JSON.stringify(elementTexts)}` + ); + texts.forEach((value) => { + const indexOfValue = elementTexts.indexOf(value); + expect(indexOfValue).to.be.greaterThan(-1); + elementTexts.splice(indexOfValue, 1); }); - } + }); + } - async textWithinTestSubjectsExists(texts: string[], selector: string) { - log.debug(`DashboardExpect.textWithinTestSubjectsExists(${texts})`); - log.debug(`textWithinTestSubjectsExists:(${JSON.stringify(texts)},${selector})`); - await this.textWithinElementsExists(texts, async () => await testSubjects.findAll(selector)); - } + async textWithinTestSubjectsExists(texts: string[], selector: string) { + this.log.debug(`DashboardExpect.textWithinTestSubjectsExists(${texts})`); + this.log.debug(`textWithinTestSubjectsExists:(${JSON.stringify(texts)},${selector})`); + await this.textWithinElementsExists( + texts, + async () => await this.testSubjects.findAll(selector) + ); + } - async textWithinCssElementExists(texts: string[], selector: string) { - log.debug(`DashboardExpect.textWithinCssElementExists(${texts})`); - log.debug(`textWithinCssElementExists:(${JSON.stringify(texts)},${selector})`); - await this.textWithinElementsExists(texts, async () => await find.allByCssSelector(selector)); - } + async textWithinCssElementExists(texts: string[], selector: string) { + this.log.debug(`DashboardExpect.textWithinCssElementExists(${texts})`); + this.log.debug(`textWithinCssElementExists:(${JSON.stringify(texts)},${selector})`); + await this.textWithinElementsExists( + texts, + async () => await this.find.allByCssSelector(selector) + ); + } - async textWithinElementsDoNotExist(texts: string[], getElementsFn: Function) { - log.debug(`DashboardExpect.textWithinElementsDoNotExist(${texts})`); - await retry.try(async () => { - const elements: WebElementWrapper[] = await getElementsFn(); - const elementTexts: string[] = []; - await Promise.all( - elements.map(async (element) => { - elementTexts.push(await element.getVisibleText()); - }) - ); - log.debug(`Found ${elements.length} elements with values: ${JSON.stringify(elementTexts)}`); - texts.forEach((value) => { - const indexOfValue = elementTexts.indexOf(value); - expect(indexOfValue).to.be(-1); - }); + async textWithinElementsDoNotExist(texts: string[], getElementsFn: Function) { + this.log.debug(`DashboardExpect.textWithinElementsDoNotExist(${texts})`); + await this.retry.try(async () => { + const elements: WebElementWrapper[] = await getElementsFn(); + const elementTexts: string[] = []; + await Promise.all( + elements.map(async (element) => { + elementTexts.push(await element.getVisibleText()); + }) + ); + this.log.debug( + `Found ${elements.length} elements with values: ${JSON.stringify(elementTexts)}` + ); + texts.forEach((value) => { + const indexOfValue = elementTexts.indexOf(value); + expect(indexOfValue).to.be(-1); }); - } + }); + } - async textWithinCssElementDoNotExist(texts: string[], selector: string) { - log.debug(`textWithinCssElementExists:(${JSON.stringify(texts)},${selector})`); - await this.textWithinElementsDoNotExist( - texts, - async () => await find.allByCssSelector(selector) - ); - } + async textWithinCssElementDoNotExist(texts: string[], selector: string) { + this.log.debug(`textWithinCssElementExists:(${JSON.stringify(texts)},${selector})`); + await this.textWithinElementsDoNotExist( + texts, + async () => await this.find.allByCssSelector(selector) + ); + } - async timelionLegendCount(expectedCount: number) { - log.debug(`DashboardExpect.timelionLegendCount(${expectedCount})`); - await retry.try(async () => { - const flotLegendLabels = await testSubjects.findAll('flotLegendLabel', findTimeout); - expect(flotLegendLabels.length).to.be(expectedCount); - }); - } + async timelionLegendCount(expectedCount: number) { + this.log.debug(`DashboardExpect.timelionLegendCount(${expectedCount})`); + await this.retry.try(async () => { + const flotLegendLabels = await this.testSubjects.findAll('flotLegendLabel', this.findTimeout); + expect(flotLegendLabels.length).to.be(expectedCount); + }); + } - async emptyTagCloudFound() { - log.debug(`DashboardExpect.emptyTagCloudFound()`); - const tagCloudVisualizations = await testSubjects.findAll('tagCloudVisualization'); - const tagCloudsHaveContent = await Promise.all( - tagCloudVisualizations.map(async (tagCloud) => { - return await find.descendantExistsByCssSelector('text', tagCloud); - }) - ); - expect(tagCloudsHaveContent.indexOf(false)).to.be.greaterThan(-1); - } + async emptyTagCloudFound() { + this.log.debug(`DashboardExpect.emptyTagCloudFound()`); + const tagCloudVisualizations = await this.testSubjects.findAll('tagCloudVisualization'); + const tagCloudsHaveContent = await Promise.all( + tagCloudVisualizations.map(async (tagCloud) => { + return await this.find.descendantExistsByCssSelector('text', tagCloud); + }) + ); + expect(tagCloudsHaveContent.indexOf(false)).to.be.greaterThan(-1); + } - async tagCloudWithValuesFound(values: string[]) { - log.debug(`DashboardExpect.tagCloudWithValuesFound(${values})`); - const tagCloudVisualizations = await testSubjects.findAll('tagCloudVisualization'); - const matches = await Promise.all( - tagCloudVisualizations.map(async (tagCloud) => { - for (let i = 0; i < values.length; i++) { - const valueExists = await testSubjects.descendantExists(values[i], tagCloud); - if (!valueExists) { - return false; - } + async tagCloudWithValuesFound(values: string[]) { + this.log.debug(`DashboardExpect.tagCloudWithValuesFound(${values})`); + const tagCloudVisualizations = await this.testSubjects.findAll('tagCloudVisualization'); + const matches = await Promise.all( + tagCloudVisualizations.map(async (tagCloud) => { + for (let i = 0; i < values.length; i++) { + const valueExists = await this.testSubjects.descendantExists(values[i], tagCloud); + if (!valueExists) { + return false; } - return true; - }) - ); - expect(matches.indexOf(true)).to.be.greaterThan(-1); - } + } + return true; + }) + ); + expect(matches.indexOf(true)).to.be.greaterThan(-1); + } - async goalAndGuageLabelsExist(labels: string[]) { - log.debug(`DashboardExpect.goalAndGuageLabelsExist(${labels})`); - await this.textWithinCssElementExists(labels, '.chart-label'); - } + async goalAndGuageLabelsExist(labels: string[]) { + this.log.debug(`DashboardExpect.goalAndGuageLabelsExist(${labels})`); + await this.textWithinCssElementExists(labels, '.chart-label'); + } - async metricValuesExist(values: string[]) { - log.debug(`DashboardExpect.metricValuesExist(${values})`); - await this.textWithinCssElementExists(values, '.mtrVis__value'); - } + async metricValuesExist(values: string[]) { + this.log.debug(`DashboardExpect.metricValuesExist(${values})`); + await this.textWithinCssElementExists(values, '.mtrVis__value'); + } - async tsvbMetricValuesExist(values: string[]) { - log.debug(`DashboardExpect.tsvbMetricValuesExist(${values})`); - await this.textWithinTestSubjectsExists(values, 'tsvbMetricValue'); - } + async tsvbMetricValuesExist(values: string[]) { + this.log.debug(`DashboardExpect.tsvbMetricValuesExist(${values})`); + await this.textWithinTestSubjectsExists(values, 'tsvbMetricValue'); + } - async tsvbTopNValuesExist(values: string[]) { - log.debug(`DashboardExpect.tsvbTopNValuesExist(${values})`); - await this.textWithinTestSubjectsExists(values, 'tsvbTopNValue'); - } + async tsvbTopNValuesExist(values: string[]) { + this.log.debug(`DashboardExpect.tsvbTopNValuesExist(${values})`); + await this.textWithinTestSubjectsExists(values, 'tsvbTopNValue'); + } - async vegaTextsExist(values: string[]) { - log.debug(`DashboardExpect.vegaTextsExist(${values})`); - await this.textWithinCssElementExists(values, '.vgaVis__view text'); - } + async vegaTextsExist(values: string[]) { + this.log.debug(`DashboardExpect.vegaTextsExist(${values})`); + await this.textWithinCssElementExists(values, '.vgaVis__view text'); + } - async vegaTextsDoNotExist(values: string[]) { - log.debug(`DashboardExpect.vegaTextsDoNotExist(${values})`); - await this.textWithinCssElementDoNotExist(values, '.vgaVis__view text'); - } + async vegaTextsDoNotExist(values: string[]) { + this.log.debug(`DashboardExpect.vegaTextsDoNotExist(${values})`); + await this.textWithinCssElementDoNotExist(values, '.vgaVis__view text'); + } - async tsvbMarkdownWithValuesExists(values: string[]) { - log.debug(`DashboardExpect.tsvbMarkdownWithValuesExists(${values})`); - await this.textWithinTestSubjectsExists(values, 'tsvbMarkdown'); - } + async tsvbMarkdownWithValuesExists(values: string[]) { + this.log.debug(`DashboardExpect.tsvbMarkdownWithValuesExists(${values})`); + await this.textWithinTestSubjectsExists(values, 'tsvbMarkdown'); + } - async markdownWithValuesExists(values: string[]) { - log.debug(`DashboardExpect.markdownWithValuesExists(${values})`); - await this.textWithinTestSubjectsExists(values, 'markdownBody'); - } + async markdownWithValuesExists(values: string[]) { + this.log.debug(`DashboardExpect.markdownWithValuesExists(${values})`); + await this.textWithinTestSubjectsExists(values, 'markdownBody'); + } - async savedSearchRowCount(expectedMinCount: number) { - log.debug(`DashboardExpect.savedSearchRowCount(${expectedMinCount})`); - await retry.try(async () => { - const savedSearchRows = await testSubjects.findAll( - 'docTableExpandToggleColumn', - findTimeout - ); - expect(savedSearchRows.length).to.be.above(expectedMinCount); - }); - } + async savedSearchRowCount(expectedMinCount: number) { + this.log.debug(`DashboardExpect.savedSearchRowCount(${expectedMinCount})`); + await this.retry.try(async () => { + const savedSearchRows = await this.testSubjects.findAll( + 'docTableExpandToggleColumn', + this.findTimeout + ); + expect(savedSearchRows.length).to.be.above(expectedMinCount); + }); + } - async dataTableRowCount(expectedCount: number) { - log.debug(`DashboardExpect.dataTableRowCount(${expectedCount})`); - await retry.try(async () => { - const dataTableRows = await PageObjects.visChart.getTableVisContent(); - expect(dataTableRows.length).to.be(expectedCount); - }); - } + async dataTableRowCount(expectedCount: number) { + this.log.debug(`DashboardExpect.dataTableRowCount(${expectedCount})`); + await this.retry.try(async () => { + const dataTableRows = await this.PageObjects.visChart.getTableVisContent(); + expect(dataTableRows.length).to.be(expectedCount); + }); + } - async dataTableNoResult() { - log.debug(`DashboardExpect.dataTableNoResult`); - await retry.try(async () => { - await PageObjects.visChart.getTableVisNoResult(); - }); - } + async dataTableNoResult() { + this.log.debug(`DashboardExpect.dataTableNoResult`); + await this.retry.try(async () => { + await this.PageObjects.visChart.getTableVisNoResult(); + }); + } - async seriesElementCount(expectedCount: number) { - log.debug(`DashboardExpect.seriesElementCount(${expectedCount})`); - await retry.try(async () => { - const seriesElements = await find.allByCssSelector('.series', findTimeout); - expect(seriesElements.length).to.be(expectedCount); - }); - } + async seriesElementCount(expectedCount: number) { + this.log.debug(`DashboardExpect.seriesElementCount(${expectedCount})`); + await this.retry.try(async () => { + const seriesElements = await this.find.allByCssSelector('.series', this.findTimeout); + expect(seriesElements.length).to.be(expectedCount); + }); + } - async inputControlItemCount(expectedCount: number) { - log.debug(`DashboardExpect.inputControlItemCount(${expectedCount})`); - await retry.try(async () => { - const inputControlItems = await testSubjects.findAll('inputControlItem'); - expect(inputControlItems.length).to.be(expectedCount); - }); - } + async inputControlItemCount(expectedCount: number) { + this.log.debug(`DashboardExpect.inputControlItemCount(${expectedCount})`); + await this.retry.try(async () => { + const inputControlItems = await this.testSubjects.findAll('inputControlItem'); + expect(inputControlItems.length).to.be(expectedCount); + }); + } - async lineChartPointsCount(expectedCount: number) { - log.debug(`DashboardExpect.lineChartPointsCount(${expectedCount})`); - await retry.try(async () => { - const points = await find.allByCssSelector('.points', findTimeout); - expect(points.length).to.be(expectedCount); - }); - } + async lineChartPointsCount(expectedCount: number) { + this.log.debug(`DashboardExpect.lineChartPointsCount(${expectedCount})`); + await this.retry.try(async () => { + const points = await this.find.allByCssSelector('.points', this.findTimeout); + expect(points.length).to.be(expectedCount); + }); + } - async tsvbTableCellCount(expectedCount: number) { - log.debug(`DashboardExpect.tsvbTableCellCount(${expectedCount})`); - await retry.try(async () => { - const tableCells = await testSubjects.findAll('tvbTableVis__value', findTimeout); - expect(tableCells.length).to.be(expectedCount); - }); - } - })(); + async tsvbTableCellCount(expectedCount: number) { + this.log.debug(`DashboardExpect.tsvbTableCellCount(${expectedCount})`); + await this.retry.try(async () => { + const tableCells = await this.testSubjects.findAll('tvbTableVis__value', this.findTimeout); + expect(tableCells.length).to.be(expectedCount); + }); + } } diff --git a/test/functional/services/dashboard/index.ts b/test/functional/services/dashboard/index.ts index 2746718892cf0..0423b66d04102 100644 --- a/test/functional/services/dashboard/index.ts +++ b/test/functional/services/dashboard/index.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -export { DashboardVisualizationProvider } from './visualizations'; -export { DashboardExpectProvider } from './expectations'; -export { DashboardAddPanelProvider } from './add_panel'; -export { DashboardReplacePanelProvider } from './replace_panel'; -export { DashboardPanelActionsProvider } from './panel_actions'; +export { DashboardVisualizationsService } from './visualizations'; +export { DashboardExpectService } from './expectations'; +export { DashboardAddPanelService } from './add_panel'; +export { DashboardReplacePanelService } from './replace_panel'; +export { DashboardPanelActionsService } from './panel_actions'; diff --git a/test/functional/services/dashboard/panel_actions.ts b/test/functional/services/dashboard/panel_actions.ts index 89790b19f426a..e7c028acc0e1b 100644 --- a/test/functional/services/dashboard/panel_actions.ts +++ b/test/functional/services/dashboard/panel_actions.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { FtrProviderContext } from '../../ftr_provider_context'; import { WebElementWrapper } from '../lib/web_element_wrapper'; +import { FtrService } from '../../ftr_provider_context'; const REMOVE_PANEL_DATA_TEST_SUBJ = 'embeddablePanelAction-deletePanel'; const EDIT_PANEL_DATA_TEST_SUBJ = 'embeddablePanelAction-editPanel'; @@ -21,320 +21,318 @@ const COPY_PANEL_TO_DATA_TEST_SUBJ = 'embeddablePanelAction-copyToDashboard'; const LIBRARY_NOTIFICATION_TEST_SUBJ = 'embeddablePanelNotification-ACTION_LIBRARY_NOTIFICATION'; const SAVE_TO_LIBRARY_TEST_SUBJ = 'embeddablePanelAction-saveToLibrary'; -export function DashboardPanelActionsProvider({ getService, getPageObjects }: FtrProviderContext) { - const log = getService('log'); - const testSubjects = getService('testSubjects'); - const PageObjects = getPageObjects(['header', 'common', 'dashboard']); - const inspector = getService('inspector'); - - return new (class DashboardPanelActions { - async findContextMenu(parent?: WebElementWrapper) { - return parent - ? await testSubjects.findDescendant(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ, parent) - : await testSubjects.find(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ); - } - - async isContextMenuIconVisible() { - log.debug('isContextMenuIconVisible'); - return await testSubjects.exists(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ); - } - - async toggleContextMenu(parent?: WebElementWrapper) { - log.debug('toggleContextMenu'); - await (parent ? parent.moveMouseTo() : testSubjects.moveMouseTo('dashboardPanelTitle')); - const toggleMenuItem = await this.findContextMenu(parent); - await toggleMenuItem.click(); - } - - async expectContextMenuToBeOpen() { - await testSubjects.existOrFail('embeddablePanelContextMenuOpen'); - } - - async openContextMenu(parent?: WebElementWrapper) { - log.debug(`openContextMenu(${parent}`); - if (await testSubjects.exists('embeddablePanelContextMenuOpen')) return; - await this.toggleContextMenu(parent); - await this.expectContextMenuToBeOpen(); - } - - async hasContextMenuMoreItem() { - return await testSubjects.exists('embeddablePanelMore-mainMenu'); - } - - async clickContextMenuMoreItem() { - const hasMoreSubPanel = await testSubjects.exists('embeddablePanelMore-mainMenu'); - if (hasMoreSubPanel) { - await testSubjects.click('embeddablePanelMore-mainMenu'); - } - } - - async openContextMenuMorePanel(parent?: WebElementWrapper) { - await this.openContextMenu(parent); - await this.clickContextMenuMoreItem(); - } - - async clickEdit() { - log.debug('clickEdit'); +export class DashboardPanelActionsService extends FtrService { + private readonly log = this.ctx.getService('log'); + private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly inspector = this.ctx.getService('inspector'); + private readonly PageObjects = this.ctx.getPageObjects(['header', 'common', 'dashboard']); + + async findContextMenu(parent?: WebElementWrapper) { + return parent + ? await this.testSubjects.findDescendant(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ, parent) + : await this.testSubjects.find(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ); + } + + async isContextMenuIconVisible() { + this.log.debug('isContextMenuIconVisible'); + return await this.testSubjects.exists(OPEN_CONTEXT_MENU_ICON_DATA_TEST_SUBJ); + } + + async toggleContextMenu(parent?: WebElementWrapper) { + this.log.debug('toggleContextMenu'); + await (parent ? parent.moveMouseTo() : this.testSubjects.moveMouseTo('dashboardPanelTitle')); + const toggleMenuItem = await this.findContextMenu(parent); + await toggleMenuItem.click(); + } + + async expectContextMenuToBeOpen() { + await this.testSubjects.existOrFail('embeddablePanelContextMenuOpen'); + } + + async openContextMenu(parent?: WebElementWrapper) { + this.log.debug(`openContextMenu(${parent}`); + if (await this.testSubjects.exists('embeddablePanelContextMenuOpen')) return; + await this.toggleContextMenu(parent); + await this.expectContextMenuToBeOpen(); + } + + async hasContextMenuMoreItem() { + return await this.testSubjects.exists('embeddablePanelMore-mainMenu'); + } + + async clickContextMenuMoreItem() { + const hasMoreSubPanel = await this.testSubjects.exists('embeddablePanelMore-mainMenu'); + if (hasMoreSubPanel) { + await this.testSubjects.click('embeddablePanelMore-mainMenu'); + } + } + + async openContextMenuMorePanel(parent?: WebElementWrapper) { + await this.openContextMenu(parent); + await this.clickContextMenuMoreItem(); + } + + async clickEdit() { + this.log.debug('clickEdit'); + await this.openContextMenu(); + const isActionVisible = await this.testSubjects.exists(EDIT_PANEL_DATA_TEST_SUBJ); + if (!isActionVisible) await this.clickContextMenuMoreItem(); + await this.testSubjects.clickWhenNotDisabled(EDIT_PANEL_DATA_TEST_SUBJ); + await this.PageObjects.header.waitUntilLoadingHasFinished(); + await this.PageObjects.common.waitForTopNavToBeVisible(); + } + + async editPanelByTitle(title?: string) { + this.log.debug(`editPanelByTitle(${title})`); + if (title) { + const panelOptions = await this.getPanelHeading(title); + await this.openContextMenu(panelOptions); + } else { await this.openContextMenu(); - const isActionVisible = await testSubjects.exists(EDIT_PANEL_DATA_TEST_SUBJ); - if (!isActionVisible) await this.clickContextMenuMoreItem(); - await testSubjects.clickWhenNotDisabled(EDIT_PANEL_DATA_TEST_SUBJ); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.common.waitForTopNavToBeVisible(); - } - - async editPanelByTitle(title?: string) { - log.debug(`editPanelByTitle(${title})`); - if (title) { - const panelOptions = await this.getPanelHeading(title); - await this.openContextMenu(panelOptions); - } else { - await this.openContextMenu(); - } - await testSubjects.clickWhenNotDisabled(EDIT_PANEL_DATA_TEST_SUBJ); } - - async clickExpandPanelToggle() { - log.debug(`clickExpandPanelToggle`); + await this.testSubjects.clickWhenNotDisabled(EDIT_PANEL_DATA_TEST_SUBJ); + } + + async clickExpandPanelToggle() { + this.log.debug(`clickExpandPanelToggle`); + await this.openContextMenu(); + const isActionVisible = await this.testSubjects.exists(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); + if (!isActionVisible) await this.clickContextMenuMoreItem(); + await this.testSubjects.click(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); + } + + async removePanel(parent?: WebElementWrapper) { + this.log.debug('removePanel'); + await this.openContextMenu(parent); + const isActionVisible = await this.testSubjects.exists(REMOVE_PANEL_DATA_TEST_SUBJ); + if (!isActionVisible) await this.clickContextMenuMoreItem(); + const isPanelActionVisible = await this.testSubjects.exists(REMOVE_PANEL_DATA_TEST_SUBJ); + if (!isPanelActionVisible) await this.clickContextMenuMoreItem(); + await this.testSubjects.click(REMOVE_PANEL_DATA_TEST_SUBJ); + } + + async removePanelByTitle(title: string) { + const header = await this.getPanelHeading(title); + this.log.debug('found header? ', Boolean(header)); + await this.removePanel(header); + } + + async customizePanel(parent?: WebElementWrapper) { + await this.openContextMenu(parent); + await this.testSubjects.click(CUSTOMIZE_PANEL_DATA_TEST_SUBJ); + } + + async replacePanelByTitle(title?: string) { + this.log.debug(`replacePanel(${title})`); + if (title) { + const panelOptions = await this.getPanelHeading(title); + await this.openContextMenu(panelOptions); + } else { await this.openContextMenu(); - const isActionVisible = await testSubjects.exists(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); - if (!isActionVisible) await this.clickContextMenuMoreItem(); - await testSubjects.click(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); - } - - async removePanel(parent?: WebElementWrapper) { - log.debug('removePanel'); - await this.openContextMenu(parent); - const isActionVisible = await testSubjects.exists(REMOVE_PANEL_DATA_TEST_SUBJ); - if (!isActionVisible) await this.clickContextMenuMoreItem(); - const isPanelActionVisible = await testSubjects.exists(REMOVE_PANEL_DATA_TEST_SUBJ); - if (!isPanelActionVisible) await this.clickContextMenuMoreItem(); - await testSubjects.click(REMOVE_PANEL_DATA_TEST_SUBJ); - } - - async removePanelByTitle(title: string) { - const header = await this.getPanelHeading(title); - log.debug('found header? ', Boolean(header)); - await this.removePanel(header); - } - - async customizePanel(parent?: WebElementWrapper) { - await this.openContextMenu(parent); - await testSubjects.click(CUSTOMIZE_PANEL_DATA_TEST_SUBJ); - } - - async replacePanelByTitle(title?: string) { - log.debug(`replacePanel(${title})`); - if (title) { - const panelOptions = await this.getPanelHeading(title); - await this.openContextMenu(panelOptions); - } else { - await this.openContextMenu(); - } - const actionExists = await testSubjects.exists(REPLACE_PANEL_DATA_TEST_SUBJ); - if (!actionExists) { - await this.clickContextMenuMoreItem(); - } - await testSubjects.click(REPLACE_PANEL_DATA_TEST_SUBJ); - } - - async clonePanelByTitle(title?: string) { - log.debug(`clonePanel(${title})`); - if (title) { - const panelOptions = await this.getPanelHeading(title); - await this.openContextMenu(panelOptions); - } else { - await this.openContextMenu(); - } - await testSubjects.click(CLONE_PANEL_DATA_TEST_SUBJ); - await PageObjects.dashboard.waitForRenderComplete(); - } - - async openCopyToModalByTitle(title?: string) { - log.debug(`copyPanelTo(${title})`); - if (title) { - const panelOptions = await this.getPanelHeading(title); - await this.openContextMenu(panelOptions); - } else { - await this.openContextMenu(); - } - const isActionVisible = await testSubjects.exists(COPY_PANEL_TO_DATA_TEST_SUBJ); - if (!isActionVisible) await this.clickContextMenuMoreItem(); - await testSubjects.click(COPY_PANEL_TO_DATA_TEST_SUBJ); - } - - async openInspectorByTitle(title: string) { - const header = await this.getPanelHeading(title); - await this.openInspector(header); - } - - async getSearchSessionIdByTitle(title: string) { - await this.openInspectorByTitle(title); - await inspector.openInspectorRequestsView(); - const searchSessionId = await ( - await testSubjects.find('inspectorRequestSearchSessionId') - ).getAttribute('data-search-session-id'); - await inspector.close(); - return searchSessionId; } - - async openInspector(parent?: WebElementWrapper) { - await this.openContextMenu(parent); - const exists = await testSubjects.exists(OPEN_INSPECTOR_TEST_SUBJ); - if (!exists) { - await this.clickContextMenuMoreItem(); - } - await testSubjects.click(OPEN_INSPECTOR_TEST_SUBJ); - } - - async unlinkFromLibary(parent?: WebElementWrapper) { - log.debug('unlinkFromLibrary'); - const libraryNotification = parent - ? await testSubjects.findDescendant(LIBRARY_NOTIFICATION_TEST_SUBJ, parent) - : await testSubjects.find(LIBRARY_NOTIFICATION_TEST_SUBJ); - await libraryNotification.click(); - await testSubjects.click('libraryNotificationUnlinkButton'); - } - - async saveToLibrary(newTitle: string, parent?: WebElementWrapper) { - log.debug('saveToLibrary'); - await this.openContextMenu(parent); - const exists = await testSubjects.exists(SAVE_TO_LIBRARY_TEST_SUBJ); - if (!exists) { - await this.clickContextMenuMoreItem(); - } - await testSubjects.click(SAVE_TO_LIBRARY_TEST_SUBJ); - await testSubjects.setValue('savedObjectTitle', newTitle, { - clearWithKeyboard: true, - }); - await testSubjects.click('confirmSaveSavedObjectButton'); - } - - async expectExistsRemovePanelAction() { - log.debug('expectExistsRemovePanelAction'); - await this.expectExistsPanelAction(REMOVE_PANEL_DATA_TEST_SUBJ); + const actionExists = await this.testSubjects.exists(REPLACE_PANEL_DATA_TEST_SUBJ); + if (!actionExists) { + await this.clickContextMenuMoreItem(); } + await this.testSubjects.click(REPLACE_PANEL_DATA_TEST_SUBJ); + } - async expectExistsPanelAction(testSubject: string) { - log.debug('expectExistsPanelAction', testSubject); + async clonePanelByTitle(title?: string) { + this.log.debug(`clonePanel(${title})`); + if (title) { + const panelOptions = await this.getPanelHeading(title); + await this.openContextMenu(panelOptions); + } else { await this.openContextMenu(); - if (await testSubjects.exists(CLONE_PANEL_DATA_TEST_SUBJ)) return; - if (await this.hasContextMenuMoreItem()) { - await this.clickContextMenuMoreItem(); - } - await testSubjects.existOrFail(CLONE_PANEL_DATA_TEST_SUBJ); - await this.toggleContextMenu(); } + await this.testSubjects.click(CLONE_PANEL_DATA_TEST_SUBJ); + await this.PageObjects.dashboard.waitForRenderComplete(); + } - async expectMissingPanelAction(testSubject: string) { - log.debug('expectMissingPanelAction', testSubject); + async openCopyToModalByTitle(title?: string) { + this.log.debug(`copyPanelTo(${title})`); + if (title) { + const panelOptions = await this.getPanelHeading(title); + await this.openContextMenu(panelOptions); + } else { await this.openContextMenu(); - await testSubjects.missingOrFail(testSubject); - if (await this.hasContextMenuMoreItem()) { - await this.clickContextMenuMoreItem(); - await testSubjects.missingOrFail(testSubject); - } - await this.toggleContextMenu(); - } - - async expectExistsEditPanelAction() { - log.debug('expectExistsEditPanelAction'); - await this.expectExistsPanelAction(EDIT_PANEL_DATA_TEST_SUBJ); - } - - async expectExistsReplacePanelAction() { - log.debug('expectExistsReplacePanelAction'); - await this.expectExistsPanelAction(REPLACE_PANEL_DATA_TEST_SUBJ); } - - async expectExistsClonePanelAction() { - log.debug('expectExistsClonePanelAction'); - await this.expectExistsPanelAction(CLONE_PANEL_DATA_TEST_SUBJ); - } - - async expectMissingEditPanelAction() { - log.debug('expectMissingEditPanelAction'); - await this.expectMissingPanelAction(EDIT_PANEL_DATA_TEST_SUBJ); - } - - async expectMissingReplacePanelAction() { - log.debug('expectMissingReplacePanelAction'); - await this.expectMissingPanelAction(REPLACE_PANEL_DATA_TEST_SUBJ); - } - - async expectMissingDuplicatePanelAction() { - log.debug('expectMissingDuplicatePanelAction'); - await this.expectMissingPanelAction(CLONE_PANEL_DATA_TEST_SUBJ); - } - - async expectMissingRemovePanelAction() { - log.debug('expectMissingRemovePanelAction'); - await this.expectMissingPanelAction(REMOVE_PANEL_DATA_TEST_SUBJ); - } - - async expectExistsToggleExpandAction() { - log.debug('expectExistsToggleExpandAction'); - await this.expectExistsPanelAction(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); - } - - async getPanelHeading(title: string) { - return await testSubjects.find(`embeddablePanelHeading-${title.replace(/\s/g, '')}`); + const isActionVisible = await this.testSubjects.exists(COPY_PANEL_TO_DATA_TEST_SUBJ); + if (!isActionVisible) await this.clickContextMenuMoreItem(); + await this.testSubjects.click(COPY_PANEL_TO_DATA_TEST_SUBJ); + } + + async openInspectorByTitle(title: string) { + const header = await this.getPanelHeading(title); + await this.openInspector(header); + } + + async getSearchSessionIdByTitle(title: string) { + await this.openInspectorByTitle(title); + await this.inspector.openInspectorRequestsView(); + const searchSessionId = await ( + await this.testSubjects.find('inspectorRequestSearchSessionId') + ).getAttribute('data-search-session-id'); + await this.inspector.close(); + return searchSessionId; + } + + async openInspector(parent?: WebElementWrapper) { + await this.openContextMenu(parent); + const exists = await this.testSubjects.exists(OPEN_INSPECTOR_TEST_SUBJ); + if (!exists) { + await this.clickContextMenuMoreItem(); } - - async clickHidePanelTitleToggle() { - await testSubjects.click('customizePanelHideTitle'); + await this.testSubjects.click(OPEN_INSPECTOR_TEST_SUBJ); + } + + async unlinkFromLibary(parent?: WebElementWrapper) { + this.log.debug('unlinkFromLibrary'); + const libraryNotification = parent + ? await this.testSubjects.findDescendant(LIBRARY_NOTIFICATION_TEST_SUBJ, parent) + : await this.testSubjects.find(LIBRARY_NOTIFICATION_TEST_SUBJ); + await libraryNotification.click(); + await this.testSubjects.click('libraryNotificationUnlinkButton'); + } + + async saveToLibrary(newTitle: string, parent?: WebElementWrapper) { + this.log.debug('saveToLibrary'); + await this.openContextMenu(parent); + const exists = await this.testSubjects.exists(SAVE_TO_LIBRARY_TEST_SUBJ); + if (!exists) { + await this.clickContextMenuMoreItem(); } - - async toggleHidePanelTitle(originalTitle?: string) { - log.debug(`hidePanelTitle(${originalTitle})`); - if (originalTitle) { - const panelOptions = await this.getPanelHeading(originalTitle); - await this.customizePanel(panelOptions); - } else { - await this.customizePanel(); - } - await this.clickHidePanelTitleToggle(); - await testSubjects.click('saveNewTitleButton'); + await this.testSubjects.click(SAVE_TO_LIBRARY_TEST_SUBJ); + await this.testSubjects.setValue('savedObjectTitle', newTitle, { + clearWithKeyboard: true, + }); + await this.testSubjects.click('confirmSaveSavedObjectButton'); + } + + async expectExistsRemovePanelAction() { + this.log.debug('expectExistsRemovePanelAction'); + await this.expectExistsPanelAction(REMOVE_PANEL_DATA_TEST_SUBJ); + } + + async expectExistsPanelAction(testSubject: string) { + this.log.debug('expectExistsPanelAction', testSubject); + await this.openContextMenu(); + if (await this.testSubjects.exists(CLONE_PANEL_DATA_TEST_SUBJ)) return; + if (await this.hasContextMenuMoreItem()) { + await this.clickContextMenuMoreItem(); } + await this.testSubjects.existOrFail(CLONE_PANEL_DATA_TEST_SUBJ); + await this.toggleContextMenu(); + } - /** - * - * @param customTitle - * @param originalTitle - optional to specify which panel to change the title on. - * @return {Promise} - */ - async setCustomPanelTitle(customTitle: string, originalTitle?: string) { - log.debug(`setCustomPanelTitle(${customTitle}, ${originalTitle})`); - if (originalTitle) { - const panelOptions = await this.getPanelHeading(originalTitle); - await this.customizePanel(panelOptions); - } else { - await this.customizePanel(); + async expectMissingPanelAction(testSubject: string) { + this.log.debug('expectMissingPanelAction', testSubject); + await this.openContextMenu(); + await this.testSubjects.missingOrFail(testSubject); + if (await this.hasContextMenuMoreItem()) { + await this.clickContextMenuMoreItem(); + await this.testSubjects.missingOrFail(testSubject); + } + await this.toggleContextMenu(); + } + + async expectExistsEditPanelAction() { + this.log.debug('expectExistsEditPanelAction'); + await this.expectExistsPanelAction(EDIT_PANEL_DATA_TEST_SUBJ); + } + + async expectExistsReplacePanelAction() { + this.log.debug('expectExistsReplacePanelAction'); + await this.expectExistsPanelAction(REPLACE_PANEL_DATA_TEST_SUBJ); + } + + async expectExistsClonePanelAction() { + this.log.debug('expectExistsClonePanelAction'); + await this.expectExistsPanelAction(CLONE_PANEL_DATA_TEST_SUBJ); + } + + async expectMissingEditPanelAction() { + this.log.debug('expectMissingEditPanelAction'); + await this.expectMissingPanelAction(EDIT_PANEL_DATA_TEST_SUBJ); + } + + async expectMissingReplacePanelAction() { + this.log.debug('expectMissingReplacePanelAction'); + await this.expectMissingPanelAction(REPLACE_PANEL_DATA_TEST_SUBJ); + } + + async expectMissingDuplicatePanelAction() { + this.log.debug('expectMissingDuplicatePanelAction'); + await this.expectMissingPanelAction(CLONE_PANEL_DATA_TEST_SUBJ); + } + + async expectMissingRemovePanelAction() { + this.log.debug('expectMissingRemovePanelAction'); + await this.expectMissingPanelAction(REMOVE_PANEL_DATA_TEST_SUBJ); + } + + async expectExistsToggleExpandAction() { + this.log.debug('expectExistsToggleExpandAction'); + await this.expectExistsPanelAction(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ); + } + + async getPanelHeading(title: string) { + return await this.testSubjects.find(`embeddablePanelHeading-${title.replace(/\s/g, '')}`); + } + + async clickHidePanelTitleToggle() { + await this.testSubjects.click('customizePanelHideTitle'); + } + + async toggleHidePanelTitle(originalTitle?: string) { + this.log.debug(`hidePanelTitle(${originalTitle})`); + if (originalTitle) { + const panelOptions = await this.getPanelHeading(originalTitle); + await this.customizePanel(panelOptions); + } else { + await this.customizePanel(); + } + await this.clickHidePanelTitleToggle(); + await this.testSubjects.click('saveNewTitleButton'); + } + + /** + * + * @param customTitle + * @param originalTitle - optional to specify which panel to change the title on. + * @return {Promise} + */ + async setCustomPanelTitle(customTitle: string, originalTitle?: string) { + this.log.debug(`setCustomPanelTitle(${customTitle}, ${originalTitle})`); + if (originalTitle) { + const panelOptions = await this.getPanelHeading(originalTitle); + await this.customizePanel(panelOptions); + } else { + await this.customizePanel(); + } + await this.testSubjects.setValue('customEmbeddablePanelTitleInput', customTitle); + await this.testSubjects.click('saveNewTitleButton'); + } + + async resetCustomPanelTitle(panel?: WebElementWrapper) { + this.log.debug('resetCustomPanelTitle'); + await this.customizePanel(panel); + await this.testSubjects.click('resetCustomEmbeddablePanelTitle'); + await this.testSubjects.click('saveNewTitleButton'); + await this.toggleContextMenu(panel); + } + + async getActionWebElementByText(text: string): Promise { + this.log.debug(`getActionWebElement: "${text}"`); + const menu = await this.testSubjects.find('multipleActionsContextMenu'); + const items = await menu.findAllByCssSelector('[data-test-subj*="embeddablePanelAction-"]'); + for (const item of items) { + const currentText = await item.getVisibleText(); + if (currentText === text) { + return item; } - await testSubjects.setValue('customEmbeddablePanelTitleInput', customTitle); - await testSubjects.click('saveNewTitleButton'); } - async resetCustomPanelTitle(panel?: WebElementWrapper) { - log.debug('resetCustomPanelTitle'); - await this.customizePanel(panel); - await testSubjects.click('resetCustomEmbeddablePanelTitle'); - await testSubjects.click('saveNewTitleButton'); - await this.toggleContextMenu(panel); - } - - async getActionWebElementByText(text: string): Promise { - log.debug(`getActionWebElement: "${text}"`); - const menu = await testSubjects.find('multipleActionsContextMenu'); - const items = await menu.findAllByCssSelector('[data-test-subj*="embeddablePanelAction-"]'); - for (const item of items) { - const currentText = await item.getVisibleText(); - if (currentText === text) { - return item; - } - } - - throw new Error(`No action matching text "${text}"`); - } - })(); + throw new Error(`No action matching text "${text}"`); + } } diff --git a/test/functional/services/dashboard/replace_panel.ts b/test/functional/services/dashboard/replace_panel.ts index 3b33b5cd4f6a6..8f8f680b839bf 100644 --- a/test/functional/services/dashboard/replace_panel.ts +++ b/test/functional/services/dashboard/replace_panel.ts @@ -6,89 +6,87 @@ * Side Public License, v 1. */ -import { FtrProviderContext } from '../../ftr_provider_context'; +import { FtrService } from '../../ftr_provider_context'; -export function DashboardReplacePanelProvider({ getService }: FtrProviderContext) { - const log = getService('log'); - const testSubjects = getService('testSubjects'); - const flyout = getService('flyout'); +export class DashboardReplacePanelService extends FtrService { + private readonly log = this.ctx.getService('log'); + private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly flyout = this.ctx.getService('flyout'); - return new (class DashboardReplacePanel { - async toggleFilterPopover() { - log.debug('DashboardReplacePanel.toggleFilter'); - await testSubjects.click('savedObjectFinderFilterButton'); - } + async toggleFilterPopover() { + this.log.debug('DashboardReplacePanel.toggleFilter'); + await this.testSubjects.click('savedObjectFinderFilterButton'); + } - async toggleFilter(type: string) { - log.debug(`DashboardReplacePanel.replaceToFilter(${type})`); - await this.waitForListLoading(); - await this.toggleFilterPopover(); - await testSubjects.click(`savedObjectFinderFilter-${type}`); - await this.toggleFilterPopover(); - } + async toggleFilter(type: string) { + this.log.debug(`DashboardReplacePanel.replaceToFilter(${type})`); + await this.waitForListLoading(); + await this.toggleFilterPopover(); + await this.testSubjects.click(`savedObjectFinderFilter-${type}`); + await this.toggleFilterPopover(); + } - async isReplacePanelOpen() { - log.debug('DashboardReplacePanel.isReplacePanelOpen'); - return await testSubjects.exists('dashboardReplacePanel'); - } + async isReplacePanelOpen() { + this.log.debug('DashboardReplacePanel.isReplacePanelOpen'); + return await this.testSubjects.exists('dashboardReplacePanel'); + } - async ensureReplacePanelIsShowing() { - log.debug('DashboardReplacePanel.ensureReplacePanelIsShowing'); - const isOpen = await this.isReplacePanelOpen(); - if (!isOpen) { - throw new Error('Replace panel is not open, trying again.'); - } + async ensureReplacePanelIsShowing() { + this.log.debug('DashboardReplacePanel.ensureReplacePanelIsShowing'); + const isOpen = await this.isReplacePanelOpen(); + if (!isOpen) { + throw new Error('Replace panel is not open, trying again.'); } + } - async waitForListLoading() { - await testSubjects.waitForDeleted('savedObjectFinderLoadingIndicator'); - } + async waitForListLoading() { + await this.testSubjects.waitForDeleted('savedObjectFinderLoadingIndicator'); + } - async closeReplacePanel() { - await flyout.ensureClosed('dashboardReplacePanel'); - } + async closeReplacePanel() { + await this.flyout.ensureClosed('dashboardReplacePanel'); + } - async replaceSavedSearch(searchName: string) { - return this.replaceEmbeddable(searchName, 'search'); - } + async replaceSavedSearch(searchName: string) { + return this.replaceEmbeddable(searchName, 'search'); + } - async replaceSavedSearches(searches: string[]) { - for (const name of searches) { - await this.replaceSavedSearch(name); - } + async replaceSavedSearches(searches: string[]) { + for (const name of searches) { + await this.replaceSavedSearch(name); } + } - async replaceVisualization(vizName: string) { - return this.replaceEmbeddable(vizName, 'visualization'); - } + async replaceVisualization(vizName: string) { + return this.replaceEmbeddable(vizName, 'visualization'); + } - async replaceEmbeddable(embeddableName: string, embeddableType?: string) { - log.debug( - `DashboardReplacePanel.replaceEmbeddable, name: ${embeddableName}, type: ${embeddableType}` - ); - await this.ensureReplacePanelIsShowing(); - if (embeddableType) { - await this.toggleFilter(embeddableType); - } - await this.filterEmbeddableNames(`"${embeddableName.replace('-', ' ')}"`); - await testSubjects.click(`savedObjectTitle${embeddableName.split(' ').join('-')}`); - await testSubjects.exists('addObjectToDashboardSuccess'); - await this.closeReplacePanel(); - return embeddableName; + async replaceEmbeddable(embeddableName: string, embeddableType?: string) { + this.log.debug( + `DashboardReplacePanel.replaceEmbeddable, name: ${embeddableName}, type: ${embeddableType}` + ); + await this.ensureReplacePanelIsShowing(); + if (embeddableType) { + await this.toggleFilter(embeddableType); } + await this.filterEmbeddableNames(`"${embeddableName.replace('-', ' ')}"`); + await this.testSubjects.click(`savedObjectTitle${embeddableName.split(' ').join('-')}`); + await this.testSubjects.exists('addObjectToDashboardSuccess'); + await this.closeReplacePanel(); + return embeddableName; + } - async filterEmbeddableNames(name: string) { - // The search input field may be disabled while the table is loading so wait for it - await this.waitForListLoading(); - await testSubjects.setValue('savedObjectFinderSearchInput', name); - await this.waitForListLoading(); - } + async filterEmbeddableNames(name: string) { + // The search input field may be disabled while the table is loading so wait for it + await this.waitForListLoading(); + await this.testSubjects.setValue('savedObjectFinderSearchInput', name); + await this.waitForListLoading(); + } - async panelReplaceLinkExists(name: string) { - log.debug(`DashboardReplacePanel.panelReplaceLinkExists(${name})`); - await this.ensureReplacePanelIsShowing(); - await this.filterEmbeddableNames(`"${name}"`); - return await testSubjects.exists(`savedObjectTitle${name.split(' ').join('-')}`); - } - })(); + async panelReplaceLinkExists(name: string) { + this.log.debug(`DashboardReplacePanel.panelReplaceLinkExists(${name})`); + await this.ensureReplacePanelIsShowing(); + await this.filterEmbeddableNames(`"${name}"`); + return await this.testSubjects.exists(`savedObjectTitle${name.split(' ').join('-')}`); + } } diff --git a/test/functional/services/dashboard/visualizations.ts b/test/functional/services/dashboard/visualizations.ts index 2bf7458ff9c5f..a6b88802d7b81 100644 --- a/test/functional/services/dashboard/visualizations.ts +++ b/test/functional/services/dashboard/visualizations.ts @@ -6,14 +6,14 @@ * Side Public License, v 1. */ -import { FtrProviderContext } from '../../ftr_provider_context'; +import { FtrService } from '../../ftr_provider_context'; -export function DashboardVisualizationProvider({ getService, getPageObjects }: FtrProviderContext) { - const log = getService('log'); - const queryBar = getService('queryBar'); - const testSubjects = getService('testSubjects'); - const dashboardAddPanel = getService('dashboardAddPanel'); - const PageObjects = getPageObjects([ +export class DashboardVisualizationsService extends FtrService { + private readonly log = this.ctx.getService('log'); + private readonly queryBar = this.ctx.getService('queryBar'); + private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly dashboardAddPanel = this.ctx.getService('dashboardAddPanel'); + private readonly PageObjects = this.ctx.getPageObjects([ 'dashboard', 'visualize', 'visEditor', @@ -22,108 +22,106 @@ export function DashboardVisualizationProvider({ getService, getPageObjects }: F 'timePicker', ]); - return new (class DashboardVisualizations { - async createAndAddTSVBVisualization(name: string) { - log.debug(`createAndAddTSVBVisualization(${name})`); - const inViewMode = await PageObjects.dashboard.getIsInViewMode(); - if (inViewMode) { - await PageObjects.dashboard.switchToEditMode(); - } - await dashboardAddPanel.clickEditorMenuButton(); - await dashboardAddPanel.clickAddNewEmbeddableLink('metrics'); - await PageObjects.visualize.clickVisualBuilder(); - await PageObjects.visualize.saveVisualizationExpectSuccess(name); + async createAndAddTSVBVisualization(name: string) { + this.log.debug(`createAndAddTSVBVisualization(${name})`); + const inViewMode = await this.PageObjects.dashboard.getIsInViewMode(); + if (inViewMode) { + await this.PageObjects.dashboard.switchToEditMode(); } + await this.dashboardAddPanel.clickEditorMenuButton(); + await this.dashboardAddPanel.clickAddNewEmbeddableLink('metrics'); + await this.PageObjects.visualize.clickVisualBuilder(); + await this.PageObjects.visualize.saveVisualizationExpectSuccess(name); + } - async createSavedSearch({ - name, - query, - fields, - }: { - name: string; - query?: string; - fields?: string[]; - }) { - log.debug(`createSavedSearch(${name})`); - await PageObjects.header.clickDiscover(true); - await PageObjects.timePicker.setHistoricalDataRange(); + async createSavedSearch({ + name, + query, + fields, + }: { + name: string; + query?: string; + fields?: string[]; + }) { + this.log.debug(`createSavedSearch(${name})`); + await this.PageObjects.header.clickDiscover(true); + await this.PageObjects.timePicker.setHistoricalDataRange(); - if (query) { - await queryBar.setQuery(query); - await queryBar.submitQuery(); - } + if (query) { + await this.queryBar.setQuery(query); + await this.queryBar.submitQuery(); + } - if (fields) { - for (let i = 0; i < fields.length; i++) { - await PageObjects.discover.clickFieldListItemAdd(fields[i]); - } + if (fields) { + for (let i = 0; i < fields.length; i++) { + await this.PageObjects.discover.clickFieldListItemAdd(fields[i]); } - - await PageObjects.discover.saveSearch(name); - await PageObjects.header.waitUntilLoadingHasFinished(); - await testSubjects.exists('saveSearchSuccess'); } - async createAndAddSavedSearch({ - name, - query, - fields, - }: { - name: string; - query?: string; - fields?: string[]; - }) { - log.debug(`createAndAddSavedSearch(${name})`); - await this.createSavedSearch({ name, query, fields }); + await this.PageObjects.discover.saveSearch(name); + await this.PageObjects.header.waitUntilLoadingHasFinished(); + await this.testSubjects.exists('saveSearchSuccess'); + } - await PageObjects.header.clickDashboard(); + async createAndAddSavedSearch({ + name, + query, + fields, + }: { + name: string; + query?: string; + fields?: string[]; + }) { + this.log.debug(`createAndAddSavedSearch(${name})`); + await this.createSavedSearch({ name, query, fields }); - const inViewMode = await PageObjects.dashboard.getIsInViewMode(); - if (inViewMode) { - await PageObjects.dashboard.switchToEditMode(); - } - await dashboardAddPanel.addSavedSearch(name); + await this.PageObjects.header.clickDashboard(); + + const inViewMode = await this.PageObjects.dashboard.getIsInViewMode(); + if (inViewMode) { + await this.PageObjects.dashboard.switchToEditMode(); } + await this.dashboardAddPanel.addSavedSearch(name); + } - async createAndAddMarkdown({ name, markdown }: { name: string; markdown: string }) { - log.debug(`createAndAddMarkdown(${markdown})`); - const inViewMode = await PageObjects.dashboard.getIsInViewMode(); - if (inViewMode) { - await PageObjects.dashboard.switchToEditMode(); - } - await dashboardAddPanel.clickMarkdownQuickButton(); - await PageObjects.visEditor.setMarkdownTxt(markdown); - await PageObjects.visEditor.clickGo(); - await PageObjects.visualize.saveVisualizationExpectSuccess(name, { - saveAsNew: false, - redirectToOrigin: true, - }); + async createAndAddMarkdown({ name, markdown }: { name: string; markdown: string }) { + this.log.debug(`createAndAddMarkdown(${markdown})`); + const inViewMode = await this.PageObjects.dashboard.getIsInViewMode(); + if (inViewMode) { + await this.PageObjects.dashboard.switchToEditMode(); } + await this.dashboardAddPanel.clickMarkdownQuickButton(); + await this.PageObjects.visEditor.setMarkdownTxt(markdown); + await this.PageObjects.visEditor.clickGo(); + await this.PageObjects.visualize.saveVisualizationExpectSuccess(name, { + saveAsNew: false, + redirectToOrigin: true, + }); + } - async createAndEmbedMetric(name: string) { - log.debug(`createAndEmbedMetric(${name})`); - const inViewMode = await PageObjects.dashboard.getIsInViewMode(); - if (inViewMode) { - await PageObjects.dashboard.switchToEditMode(); - } - await dashboardAddPanel.clickEditorMenuButton(); - await dashboardAddPanel.clickAggBasedVisualizations(); - await dashboardAddPanel.clickVisType('metric'); - await testSubjects.click('savedObjectTitlelogstash-*'); - await testSubjects.exists('visualizesaveAndReturnButton'); - await testSubjects.click('visualizesaveAndReturnButton'); + async createAndEmbedMetric(name: string) { + this.log.debug(`createAndEmbedMetric(${name})`); + const inViewMode = await this.PageObjects.dashboard.getIsInViewMode(); + if (inViewMode) { + await this.PageObjects.dashboard.switchToEditMode(); } + await this.dashboardAddPanel.clickEditorMenuButton(); + await this.dashboardAddPanel.clickAggBasedVisualizations(); + await this.dashboardAddPanel.clickVisType('metric'); + await this.testSubjects.click('savedObjectTitlelogstash-*'); + await this.testSubjects.exists('visualizesaveAndReturnButton'); + await this.testSubjects.click('visualizesaveAndReturnButton'); + } - async createAndEmbedMarkdown({ name, markdown }: { name: string; markdown: string }) { - log.debug(`createAndEmbedMarkdown(${markdown})`); - const inViewMode = await PageObjects.dashboard.getIsInViewMode(); - if (inViewMode) { - await PageObjects.dashboard.switchToEditMode(); - } - await dashboardAddPanel.clickMarkdownQuickButton(); - await PageObjects.visEditor.setMarkdownTxt(markdown); - await PageObjects.visEditor.clickGo(); - await testSubjects.click('visualizesaveAndReturnButton'); + async createAndEmbedMarkdown({ name, markdown }: { name: string; markdown: string }) { + this.log.debug(`createAndEmbedMarkdown(${markdown})`); + const inViewMode = await this.PageObjects.dashboard.getIsInViewMode(); + if (inViewMode) { + await this.PageObjects.dashboard.switchToEditMode(); } - })(); + await this.dashboardAddPanel.clickMarkdownQuickButton(); + await this.PageObjects.visEditor.setMarkdownTxt(markdown); + await this.PageObjects.visEditor.clickGo(); + await this.testSubjects.click('visualizesaveAndReturnButton'); + } } diff --git a/test/functional/services/index.ts b/test/functional/services/index.ts index 0dd7f20debcbd..d8dcdd9196839 100644 --- a/test/functional/services/index.ts +++ b/test/functional/services/index.ts @@ -19,11 +19,11 @@ import { } from './common'; import { ComboBoxProvider } from './combo_box'; import { - DashboardAddPanelProvider, - DashboardReplacePanelProvider, - DashboardExpectProvider, - DashboardPanelActionsProvider, - DashboardVisualizationProvider, + DashboardAddPanelService, + DashboardReplacePanelService, + DashboardExpectService, + DashboardPanelActionsService, + DashboardVisualizationsService, } from './dashboard'; import { DocTableProvider } from './doc_table'; import { EmbeddingProvider } from './embedding'; @@ -60,13 +60,13 @@ export const services = { docTable: DocTableProvider, screenshots: ScreenshotsProvider, snapshots: SnapshotsProvider, - dashboardVisualizations: DashboardVisualizationProvider, - dashboardExpect: DashboardExpectProvider, + dashboardVisualizations: DashboardVisualizationsService, + dashboardExpect: DashboardExpectService, failureDebugging: FailureDebuggingProvider, listingTable: ListingTableProvider, - dashboardAddPanel: DashboardAddPanelProvider, - dashboardReplacePanel: DashboardReplacePanelProvider, - dashboardPanelActions: DashboardPanelActionsProvider, + dashboardAddPanel: DashboardAddPanelService, + dashboardReplacePanel: DashboardReplacePanelService, + dashboardPanelActions: DashboardPanelActionsService, flyout: FlyoutProvider, comboBox: ComboBoxProvider, dataGrid: DataGridProvider,