From 5e02564b503549e3226fe75a171e2b9cb204c23b Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 19 Dec 2024 15:19:38 -0600 Subject: [PATCH 1/3] open changes test and reorg --- .../action-bar/editor-action-bar.test.ts | 133 +++++++++++------- 1 file changed, 85 insertions(+), 48 deletions(-) diff --git a/test/e2e/areas/action-bar/editor-action-bar.test.ts b/test/e2e/areas/action-bar/editor-action-bar.test.ts index 633256ea09d..3bb4fb55934 100644 --- a/test/e2e/areas/action-bar/editor-action-bar.test.ts +++ b/test/e2e/areas/action-bar/editor-action-bar.test.ts @@ -3,8 +3,10 @@ * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. *--------------------------------------------------------------------------------------------*/ +import { Page } from '@playwright/test'; import { test, expect, tags } from '../_test.setup'; import path = require('path'); +import { Application } from '../../../automation'; test.use({ suiteId: __filename @@ -25,81 +27,45 @@ test.describe('Editor Action Bar', { tag: [tags.R_MARKDOWN] }, async function ({ app, page }) { await openFile(app, 'workspaces/basic-rmd-file/basicRmd.rmd'); - - await test.step('verify "preview" button renders html', async () => { - await page.getByLabel('Preview', { exact: true }).click(); - const viewerFrame = app.workbench.positronViewer.getViewerFrame().frameLocator('iframe'); - await expect(viewerFrame.getByRole('heading', { name: 'Getting startedAnchor' })).toBeVisible({ timeout: 30000 }); - }); - + await verifyPreviewRendersHtml(app, 'Getting startedAnchor'); await verifySplitEditor(page, 'basicRmd.rmd'); await verifyOpenInNewWindow(page, 'This post examines the features'); }); - test('Quarto Document [C1080700]', { tag: [tags.QUARTO] }, async function ({ app, page }) { await openFile(app, 'workspaces/quarto_basic/quarto_basic.qmd'); - - await test.step('verify "preview" button renders html', async () => { - await page.getByLabel('Preview', { exact: true }).click(); - const viewerFrame = app.workbench.positronViewer.getViewerFrame().frameLocator('iframe'); - await expect(viewerFrame.locator('h1')).toHaveText('Diamond sizes', { timeout: 30000 }); - }); - + await verifyPreviewRendersHtml(app, 'Diamond sizes'); + await verifyOpenChanges(page); await verifySplitEditor(page, 'quarto_basic.qmd'); await verifyOpenInNewWindow(page, 'Diamond sizes'); }); test('HTML Document [C1080701]', { tag: [tags.HTML] }, async function ({ app, page }) { await openFile(app, 'workspaces/dash-py-example/data/OilandGasMetadata.html'); - - await test.step('verify "open in viewer" button renders html', async () => { - await page.getByLabel('Open in Viewer').nth(1).click(); - const viewerFrame = page.locator('iframe.webview').contentFrame().locator('#active-frame').contentFrame(); - const cellLocator = app.web - ? viewerFrame.frameLocator('iframe').getByRole('cell', { name: 'Oil, Gas, and Other Regulated' }) - : viewerFrame.getByRole('cell', { name: 'Oil, Gas, and Other Regulated' }); - - await expect(cellLocator).toBeVisible({ timeout: 30000 }); - }); - + await verifyOpenViewerRendersHtml(app); await verifySplitEditor(page, 'OilandGasMetadata.html'); await verifyOpenInNewWindow(page, ' Oil & Gas Wells - Metadata'); - }); test('Jupyter Notebook [C1080702]', { tag: [tags.NOTEBOOK], annotation: [{ type: 'info', description: 'electron test unable to interact with dropdown native menu' }], }, async function ({ app, page }) { - await test.step('open jupyter notebook', async () => { - await app.workbench.positronQuickaccess.openDataFile( - path.join(app.workspacePathOrFolder, 'workspaces', 'large_r_notebook', 'spotify.ipynb') - ); - }); + await openNotebook(app, 'workspaces/large_r_notebook/spotify.ipynb'); + + await verifySplitEditor(page, 'spotify.ipynb'); if (app.web) { - await test.step('verify "customize notebook: toggle line numbers" adjusts settings (web only)', async () => { - await verifyLineNumbersVisibility(page, false); - await clickCustomizeNotebookMenuItem(page, 'Toggle Notebook Line Numbers'); - await verifyLineNumbersVisibility(page, true); - }); - - await test.step('verify "customize notebook: toggle breadcrumbs" adjusts settings (web only)', async () => { - const breadcrumbs = page.locator('.monaco-breadcrumbs'); - - await expect(breadcrumbs).toBeVisible(); - await clickCustomizeNotebookMenuItem(page, 'Toggle Breadcrumbs'); - await expect(breadcrumbs).not.toBeVisible(); - }); + await verifyToggleLineNumbers(page); + await verifyToggleBreadcrumb(page); } - - await verifySplitEditor(page, 'spotify.ipynb'); }); }); + +// Helper functions async function openFile(app, filePath: string) { const fileName = path.basename(filePath); await test.step(`open file: ${fileName}`, async () => { @@ -107,8 +73,16 @@ async function openFile(app, filePath: string) { }); } +async function openNotebook(app: Application, filePath: string) { + await test.step('open jupyter notebook', async () => { + await app.workbench.positronQuickaccess.openDataFile( + path.join(app.workspacePathOrFolder, filePath) + ); + }); +} + async function verifySplitEditor(page, tabName: string) { - await test.step(`verify "split editor" button opens another tab`, async () => { + await test.step(`verify "split editor" opens another tab`, async () => { // Split editor right await page.getByLabel('Split Editor Right', { exact: true }).click(); await expect(page.getByRole('tab', { name: tabName })).toHaveCount(2); @@ -152,3 +126,66 @@ async function verifyLineNumbersVisibility(page, isVisible: boolean) { isVisible ? await lineNumbers.toBeVisible() : await lineNumbers.not.toBeVisible(); } } + +async function verifyOpenChanges(page: Page) { + await test.step('verify "open changes" shows diff', async () => { + + + // make change & save + await page.getByText('date', { exact: true }).click(); + await page.keyboard.press('X'); + await bindPlatformHotkey(page, 'S'); + + // click open changes & verify + await page.getByLabel('Open Changes').nth(1).click(); + await expect(page.getByLabel('Revert Block')).toBeVisible(); + await expect(page.getByLabel('Stage Block')).toBeVisible(); + await page.getByRole('tab', { name: 'quarto_basic.qmd (Working' }).getByLabel('Close').click(); + + // undo changes & save + await bindPlatformHotkey(page, 'Z'); + await bindPlatformHotkey(page, 'S'); + }); +} + +async function bindPlatformHotkey(page: Page, key: string) { + await page.keyboard.press(process.platform === 'darwin' ? `Meta+${key}` : `Control+${key}`); +} + +async function verifyOpenViewerRendersHtml(app: Application) { + await test.step('verify "open in viewer" renders html', async () => { + await app.code.driver.page.getByLabel('Open in Viewer').nth(1).click(); + const viewerFrame = app.code.driver.page.locator('iframe.webview').contentFrame().locator('#active-frame').contentFrame(); + const cellLocator = app.web + ? viewerFrame.frameLocator('iframe').getByRole('cell', { name: 'Oil, Gas, and Other Regulated' }) + : viewerFrame.getByRole('cell', { name: 'Oil, Gas, and Other Regulated' }); + + await expect(cellLocator).toBeVisible({ timeout: 30000 }); + }); +} + +async function verifyPreviewRendersHtml(app: Application, heading: string) { + await test.step('verify "preview" renders html', async () => { + await app.code.driver.page.getByLabel('Preview', { exact: true }).click(); + const viewerFrame = app.workbench.positronViewer.getViewerFrame().frameLocator('iframe'); + await expect(viewerFrame.getByRole('heading', { name: heading })).toBeVisible({ timeout: 30000 }); + }); +} + +async function verifyToggleLineNumbers(page: Page) { + await test.step('verify "customize notebook > toggle line numbers" (web only)', async () => { + await verifyLineNumbersVisibility(page, false); + await clickCustomizeNotebookMenuItem(page, 'Toggle Notebook Line Numbers'); + await verifyLineNumbersVisibility(page, true); + }); +} + +async function verifyToggleBreadcrumb(page: Page) { + await test.step('verify "customize notebook > toggle breadcrumbs" (web only)', async () => { + const breadcrumbs = page.locator('.monaco-breadcrumbs'); + + await expect(breadcrumbs).toBeVisible(); + await clickCustomizeNotebookMenuItem(page, 'Toggle Breadcrumbs'); + await expect(breadcrumbs).not.toBeVisible(); + }); +} From 2c3ef0b8c9f4929da5aec69fe8fe724e2492b8fc Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 19 Dec 2024 15:20:58 -0600 Subject: [PATCH 2/3] update tags --- test/e2e/areas/action-bar/editor-action-bar.test.ts | 3 +-- test/e2e/helpers/test-tags.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/e2e/areas/action-bar/editor-action-bar.test.ts b/test/e2e/areas/action-bar/editor-action-bar.test.ts index 3bb4fb55934..5c116d4adbd 100644 --- a/test/e2e/areas/action-bar/editor-action-bar.test.ts +++ b/test/e2e/areas/action-bar/editor-action-bar.test.ts @@ -13,7 +13,7 @@ test.use({ }); test.describe('Editor Action Bar', { - tag: [tags.WEB, tags.ACTION_BAR, tags.EDITOR] + tag: [tags.WEB, tags.EDITOR_ACTION_BAR, tags.EDITOR] }, () => { test.beforeAll(async function ({ userSettings }) { await userSettings.set([['editor.actionBar.enabled', 'true']], false); @@ -54,7 +54,6 @@ test.describe('Editor Action Bar', { annotation: [{ type: 'info', description: 'electron test unable to interact with dropdown native menu' }], }, async function ({ app, page }) { await openNotebook(app, 'workspaces/large_r_notebook/spotify.ipynb'); - await verifySplitEditor(page, 'spotify.ipynb'); if (app.web) { diff --git a/test/e2e/helpers/test-tags.ts b/test/e2e/helpers/test-tags.ts index 150ee6c2f2f..148717c36e2 100644 --- a/test/e2e/helpers/test-tags.ts +++ b/test/e2e/helpers/test-tags.ts @@ -13,7 +13,7 @@ * which are not currently configured to run in PR workflows. */ export enum TestTags { - ACTION_BAR = '@action-bar', + EDITOR_ACTION_BAR = '@editor-action-bar', APPS = '@apps', CONNECTIONS = '@connections', CONSOLE = '@console', From 0d9f078feb01e339e47c16986cd85776649c6e08 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 19 Dec 2024 15:22:14 -0600 Subject: [PATCH 3/3] nit --- test/e2e/areas/action-bar/editor-action-bar.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/areas/action-bar/editor-action-bar.test.ts b/test/e2e/areas/action-bar/editor-action-bar.test.ts index 5c116d4adbd..f0802ca0a11 100644 --- a/test/e2e/areas/action-bar/editor-action-bar.test.ts +++ b/test/e2e/areas/action-bar/editor-action-bar.test.ts @@ -3,10 +3,11 @@ * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. *--------------------------------------------------------------------------------------------*/ -import { Page } from '@playwright/test'; import { test, expect, tags } from '../_test.setup'; -import path = require('path'); import { Application } from '../../../automation'; +import { Page } from '@playwright/test'; +import path = require('path'); + test.use({ suiteId: __filename @@ -15,6 +16,7 @@ test.use({ test.describe('Editor Action Bar', { tag: [tags.WEB, tags.EDITOR_ACTION_BAR, tags.EDITOR] }, () => { + test.beforeAll(async function ({ userSettings }) { await userSettings.set([['editor.actionBar.enabled', 'true']], false); });