From a8fa694beb1e9d734b4f0f69e04f208b8607c19f Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Tue, 17 Dec 2024 06:30:02 -0600 Subject: [PATCH] update add quickinput pom --- .../src/positron/positronQuickInput.ts | 75 +++++++++++++++++++ test/automation/src/workbench.ts | 3 + .../r-pkg-development.test.ts | 6 +- .../areas/test-explorer/test-explorer.test.ts | 6 +- test/e2e/areas/welcome/welcome.test.ts | 4 +- 5 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 test/automation/src/positron/positronQuickInput.ts diff --git a/test/automation/src/positron/positronQuickInput.ts b/test/automation/src/positron/positronQuickInput.ts new file mode 100644 index 00000000000..7c273dcd7a2 --- /dev/null +++ b/test/automation/src/positron/positronQuickInput.ts @@ -0,0 +1,75 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2024 Posit Software, PBC. All rights reserved. + * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. + *--------------------------------------------------------------------------------------------*/ + +import { expect } from '@playwright/test'; +import { Code } from '../code'; + +export class PositronQuickInput { + + private static QUICK_INPUT = '.quick-input-widget'; + private static QUICK_INPUT_INPUT = `${PositronQuickInput.QUICK_INPUT} .quick-input-box input`; + private static QUICK_INPUT_ROW = `${PositronQuickInput.QUICK_INPUT} .quick-input-list .monaco-list-row`; + private static QUICK_INPUT_FOCUSED_ELEMENT = `${PositronQuickInput.QUICK_INPUT_ROW}.focused .monaco-highlighted-label`; + // Note: this only grabs the label and not the description or detail + private static QUICK_INPUT_ENTRY_LABEL = `${this.QUICK_INPUT_ROW} .quick-input-list-row > .monaco-icon-label .label-name`; + private static QUICK_INPUT_ENTRY_LABEL_SPAN = `${this.QUICK_INPUT_ROW} .monaco-highlighted-label`; + private static QUICKINPUT_OK_BUTTON = '.quick-input-widget .quick-input-action a:has-text("OK")'; + + constructor(private code: Code) { } + + async waitForQuickInputOpened(): Promise { + await expect(this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_INPUT)).toBeVisible(); + } + + async type(value: string): Promise { + await this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_INPUT).fill(value); + } + + async waitForQuickInputElementFocused(): Promise { + await expect(this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_FOCUSED_ELEMENT)).toBeFocused(); + } + + async waitForQuickInputElementText(): Promise { + await expect(this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_ENTRY_LABEL_SPAN)).not.toHaveText(''); + return await this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_ENTRY_LABEL_SPAN).textContent() || ''; + } + + async closeQuickInput(): Promise { + await this.code.driver.page.keyboard.press('Escape'); + await this.waitForQuickInputClosed(); + } + + async waitForQuickInputElements(accept: (names: string[]) => boolean): Promise { + const locator = this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_ENTRY_LABEL); + + await expect(async () => { + const names = await locator.allTextContents(); + return accept(names); + }).toPass(); + } + + async waitForQuickInputClosed(): Promise { + await expect(this.code.driver.page.locator(PositronQuickInput.QUICK_INPUT_INPUT)).not.toBeVisible(); + } + + async selectQuickInputElement(index: number, keepOpen?: boolean): Promise { + await this.waitForQuickInputOpened(); + for (let from = 0; from < index; from++) { + await this.code.driver.page.keyboard.press('down'); + } + await this.code.driver.page.keyboard.press('enter'); + if (!keepOpen) { + await this.waitForQuickInputClosed(); + } + } + + async selectQuickInputElementContaining(text: string): Promise { + await this.code.driver.page.locator(`${PositronQuickInput.QUICK_INPUT_ROW}[aria-label*="${text}"]`).first().click({ timeout: 10000 }); + } + + async clickOkOnQuickInput(): Promise { + await this.code.driver.page.locator(PositronQuickInput.QUICKINPUT_OK_BUTTON).click(); + } +} diff --git a/test/automation/src/workbench.ts b/test/automation/src/workbench.ts index b82d7bb9341..dca6e77717a 100644 --- a/test/automation/src/workbench.ts +++ b/test/automation/src/workbench.ts @@ -47,6 +47,7 @@ import { PositronTestExplorer } from './positron/positronTestExplorer'; import { PositronQuickAccess } from './positron/positronQuickaccess'; import { PositronOutline } from './positron/positronOutline'; import { PositronClipboard } from './positron/positronClipboard'; +import { PositronQuickInput } from './positron/positronQuickInput'; // --- End Positron --- export interface Commands { @@ -98,6 +99,7 @@ export class Workbench { readonly positronQuickaccess: PositronQuickAccess; readonly positronOutline: PositronOutline; readonly positronClipboard: PositronClipboard; + readonly positronQuickInput: PositronQuickInput; // --- End Positron --- constructor(code: Code) { @@ -144,6 +146,7 @@ export class Workbench { this.positronQuickaccess = new PositronQuickAccess(this.quickinput, this.quickaccess); this.positronOutline = new PositronOutline(code, this.quickaccess); this.positronClipboard = new PositronClipboard(code); + this.positronQuickInput = new PositronQuickInput(code); // --- End Positron --- } } diff --git a/test/e2e/areas/r-pkg-development/r-pkg-development.test.ts b/test/e2e/areas/r-pkg-development/r-pkg-development.test.ts index 15bd91c3c94..0bd59823222 100644 --- a/test/e2e/areas/r-pkg-development/r-pkg-development.test.ts +++ b/test/e2e/areas/r-pkg-development/r-pkg-development.test.ts @@ -31,9 +31,9 @@ test.describe('R Package Development', { tag: [tags.WEB, tags.R_PKG_DEVELOPMENT] // Navigate to https://github.com/posit-dev/qa-example-content/tree/main/workspaces/r_testing // This is an R package embedded in qa-example-content await app.workbench.quickaccess.runCommand('workbench.action.files.openFolder', { keepOpen: true }); - await app.workbench.quickinput.waitForQuickInputOpened(); - await app.workbench.quickinput.type(path.join(app.workspacePathOrFolder, 'workspaces', 'r_testing')); - await app.workbench.quickinput.clickOkOnQuickInput(); + await app.workbench.positronQuickInput.waitForQuickInputOpened(); + await app.workbench.positronQuickInput.type(path.join(app.workspacePathOrFolder, 'workspaces', 'r_testing')); + await app.workbench.positronQuickInput.clickOkOnQuickInput(); // Wait for the console to be ready await app.workbench.positronConsole.waitForReady('>', 45000); diff --git a/test/e2e/areas/test-explorer/test-explorer.test.ts b/test/e2e/areas/test-explorer/test-explorer.test.ts index 40fb43499fd..56537568243 100644 --- a/test/e2e/areas/test-explorer/test-explorer.test.ts +++ b/test/e2e/areas/test-explorer/test-explorer.test.ts @@ -33,10 +33,10 @@ test.describe('Test Explorer', { tag: [tags.TEST_EXPLORER] }, () => { // Navigate to https://github.com/posit-dev/qa-example-content/tree/main/workspaces/r_testing // This is an R package embedded in qa-example-content await app.workbench.quickaccess.runCommand('workbench.action.files.openFolder', { keepOpen: true }); - await app.workbench.quickinput.waitForQuickInputOpened(); - await app.workbench.quickinput.type(path.join(app.workspacePathOrFolder, 'workspaces', 'r_testing')); + await app.workbench.positronQuickInput.waitForQuickInputOpened(); + await app.workbench.positronQuickInput.type(path.join(app.workspacePathOrFolder, 'workspaces', 'r_testing')); // Had to add a positron class, because Microsoft did not have this: - await app.workbench.quickinput.clickOkOnQuickInput(); + await app.workbench.positronQuickInput.clickOkOnQuickInput(); // Wait for the console to be ready await app.workbench.positronConsole.waitForReady('>', 10000); diff --git a/test/e2e/areas/welcome/welcome.test.ts b/test/e2e/areas/welcome/welcome.test.ts index e717ff82a54..a66b26f9f95 100644 --- a/test/e2e/areas/welcome/welcome.test.ts +++ b/test/e2e/areas/welcome/welcome.test.ts @@ -72,7 +72,7 @@ test.describe('Welcome Page', { tag: [tags.WELCOME] }, () => { await app.workbench.positronWelcome.newFileButton.click(); - await app.workbench.quickinput.selectQuickInputElementContaining('Python File'); + await app.workbench.positronQuickInput.selectQuickInputElementContaining('Python File'); await expect(app.workbench.editors.activeEditor.locator(app.workbench.editors.editorIcon)).toHaveClass(/python-lang-file-icon/); @@ -111,7 +111,7 @@ test.describe('Welcome Page', { tag: [tags.WELCOME] }, () => { test('Create a new R file from the Welcome page [C684755]', async function ({ app, r }) { await app.workbench.positronWelcome.newFileButton.click(); - await app.workbench.quickinput.selectQuickInputElementContaining('R File'); + await app.workbench.positronQuickInput.selectQuickInputElementContaining('R File'); await expect(app.workbench.editors.activeEditor.locator(app.workbench.editors.editorIcon)).toHaveClass(/r-lang-file-icon/); });