diff --git a/extension/src/test/e2e/extension.test.ts b/extension/src/test/e2e/extension.test.ts index 62c976e6e2..9c7cf4f920 100644 --- a/extension/src/test/e2e/extension.test.ts +++ b/extension/src/test/e2e/extension.test.ts @@ -1,13 +1,17 @@ import { join } from 'path' import { closeAllEditors, + createCustomPlot, deleteAllExistingExperiments, + deleteCustomPlot, dismissAllNotifications, + expectAllPlotsToBeFilled, findDecorationTooltip, findScmTreeItems, getDVCActivityBarIcon, getLabel, runModifiedExperiment, + waitForAllPlotsToRender, waitForDvcToFinish, waitForViewContainerToLoad } from './util.js' @@ -21,8 +25,14 @@ before('should finish loading the extension', async function () { return dismissAllNotifications() }) -after(function () { +after(async function () { this.timeout(60000) + + try { + await deleteCustomPlot() + } catch {} + await dismissAllNotifications() + return waitForDvcToFinish() }) @@ -130,32 +140,56 @@ describe('Experiments Table Webview', function () { }) describe('Plots Webview', function () { + const webview = new PlotsWebview('plots') + + // eslint-disable-next-line jest/expect-expect it('should load the plots webview with non-empty plots', async function () { this.timeout(60000) - const webview = new PlotsWebview('plots') const workbench = await browser.getWorkbench() await workbench.openCommandPrompt() await browser.keys([...'DVC: Show Plots', 'ArrowDown', 'Enter']) await waitForDvcToFinish() + await webview.focus() + + await waitForAllPlotsToRender(webview, 5) + + await expectAllPlotsToBeFilled(webview) + + await webview.unfocus() + await closeAllEditors() + }) + + // eslint-disable-next-line jest/expect-expect + it('should create and delete a custom plot', async function () { + this.timeout(60000) + await createCustomPlot() + const workbench = await browser.getWorkbench() + await workbench.openCommandPrompt() + await workbench.executeCommand('DVC: Show Plots') + await waitForDvcToFinish() await webview.focus() - await browser.waitUntil( - async () => { - return (await webview.vegaVisualization$$.length) === 5 - }, - { timeout: 30000 } - ) + await waitForAllPlotsToRender(webview, 6) + + await expectAllPlotsToBeFilled(webview) + + await webview.unfocus() + await closeAllEditors() - const plots = await webview.vegaVisualization$$ + await deleteCustomPlot() + await workbench.executeCommand('DVC: Show Plots') - for (const plot of plots) { - const plotNotEmpty = await webview.plotNotEmpty(plot) - expect(plotNotEmpty).toBe(true) - } + await waitForDvcToFinish() + await webview.focus() + + await waitForAllPlotsToRender(webview, 5) + + await expectAllPlotsToBeFilled(webview) await webview.unfocus() + await closeAllEditors() }) }) diff --git a/extension/src/test/e2e/util.ts b/extension/src/test/e2e/util.ts index fa9dd650f0..a3f007f839 100644 --- a/extension/src/test/e2e/util.ts +++ b/extension/src/test/e2e/util.ts @@ -1,5 +1,6 @@ import { Key } from 'webdriverio' import { ViewControl } from 'wdio-vscode-service' +import { PlotsWebview } from './pageObjects/plotsWebview' const findProgressBars = () => $$('.monaco-progress-container') @@ -153,6 +154,46 @@ export const closeAllEditors = async (): Promise => { return editorView.closeAllEditors() } +export const createCustomPlot = async (): Promise => { + const workbench = await browser.getWorkbench() + const addCustomPlot = await workbench.executeCommand('DVC: Add Custom Plot') + await browser.waitUntil(() => addCustomPlot.elem.isDisplayed()) + await browser.keys('Enter') + await browser.waitUntil(() => addCustomPlot.elem.isDisplayed()) + return browser.keys('Enter') +} + +export const deleteCustomPlot = async (): Promise => { + const workbench = await browser.getWorkbench() + const removeCustomPlot = await workbench.executeCommand( + 'DVC: Remove Custom Plot(s)' + ) + await browser.waitUntil(() => removeCustomPlot.elem.isDisplayed()) + await browser.keys('ArrowDown') + await browser.keys('Space') + return browser.keys('Enter') +} + +export const waitForAllPlotsToRender = ( + webview: PlotsWebview, + plotsAmount: number +): Promise => { + return browser.waitUntil( + async () => { + return (await webview.vegaVisualization$$.length) === plotsAmount + }, + { timeout: 30000 } + ) +} + +export const expectAllPlotsToBeFilled = async (webview: PlotsWebview) => { + const plots = await webview.vegaVisualization$$ + for (const plot of plots) { + const plotNotEmpty = await webview.plotNotEmpty(plot) + expect(plotNotEmpty).toBe(true) + } +} + export const findScmTreeItems = async () => { const workspace = await browser.getWorkbench() const activityBar = workspace.getActivityBar()