Merge pull request #3432 from continuedev/tomasz/e2e-shortcuts

test: keyboard shortcuts
This commit is contained in:
Tomasz Stefaniak 2024-12-17 12:19:49 -08:00 • committed by GitHub
commit 5cead18fd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 149 additions and 18 deletions

View file

@ -1,8 +1,20 @@
import { expect } from "chai";
import { WebElement } from "vscode-extension-tester";
import {
Key,
WebElement,
waitForAttributeValue,
} from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "./constants";
export class TestUtils {
/**
* In many cases it might be more useful to use existing Selenium
* utilities. For example:
*
* await driver.wait(until.elementLocated(By.xpath(xpath)), 5000);
*
* There's also 'waitForAttributeValue'.
*/
public static async waitForSuccess<T>(
locatorFn: () => Promise<T>,
timeout: number = DEFAULT_TIMEOUT.MD,
@ -58,4 +70,12 @@ export class TestUtils {
llmResponse: `TEST_LLM_RESPONSE_${id}`,
};
}
public static get isMacOS(): boolean {
return process.platform === "darwin";
}
public static get osControlKey() {
return TestUtils.isMacOS ? Key.META : Key.CONTROL;
}
}

View file

@ -1,15 +1,12 @@
import {
Key,
WebDriver,
WebElement,
WebView,
Workbench,
} from "vscode-extension-tester";
import { Key, WebElement, WebView, Workbench } from "vscode-extension-tester";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
export class GUIActions {
public static switchToReactIframe = async (driver: WebDriver) => {
public static switchToReactIframe = async () => {
const view = new WebView();
const driver = view.getDriver();
const iframes = await GUISelectors.getAllIframes(driver);
let continueIFrame: WebElement | undefined = undefined;
for (let i = 0; i < iframes.length; i++) {
@ -38,6 +35,10 @@ export class GUIActions {
}
await driver.switchTo().frame(reactIFrame);
return {
view,
driver,
};
};
public static openGui = async () => {

View file

@ -0,0 +1,14 @@
import { WebDriver } from "vscode-extension-tester";
import { TestUtils } from "../TestUtils";
export class KeyboardShortcutsActions {
public static async executeFocusContinueInput(driver: WebDriver) {
return await driver
.actions()
.keyDown(TestUtils.osControlKey)
.sendKeys("l")
.keyUp(TestUtils.osControlKey)
.perform();
}
}

View file

@ -1,4 +1,4 @@
import { By, WebDriver, WebView } from "vscode-extension-tester";
import { By, until, WebDriver, WebView } from "vscode-extension-tester";
import { SelectorUtils } from "./SelectorUtils";
export class GUISelectors {
@ -14,7 +14,7 @@ export class GUISelectors {
view: WebView,
index: number,
) {
const elements = await view.findWebElements(By.className("tiptap"));
const elements = await this.getMessageInputFields(view);
return elements[index];
}
@ -66,4 +66,21 @@ export class GUISelectors {
public static getNewSessionNavButton(view: WebView) {
return SelectorUtils.getElementByAriaLabel(view, "New Session");
}
public static async getInputBoxCodeBlockAtIndex(
view: WebView,
index: number,
) {
const firstInputField = await this.getMessageInputFieldAtIndex(view, index);
const codeBlockElement = await firstInputField.findElement(
By.xpath(".//code"),
);
return codeBlockElement;
}
public static getContinueExtensionBadge(view: WebView) {
return SelectorUtils.getElementByAriaLabel(view, "Continue");
}
}

View file

@ -20,10 +20,7 @@ describe("GUI Test", () => {
await GUIActions.openGui();
view = new WebView();
driver = view.getDriver();
await GUIActions.switchToReactIframe(driver);
({ view, driver } = await GUIActions.switchToReactIframe());
await GUIActions.selectModelFromDropdown(view, "TEST LLM");
});
@ -212,7 +209,7 @@ describe("GUI Test", () => {
*/
await view.switchBack();
await (await GUISelectors.getHistoryNavButton(view)).click();
await GUIActions.switchToReactIframe(driver);
await GUIActions.switchToReactIframe();
await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
@ -222,7 +219,7 @@ describe("GUI Test", () => {
* END OF SWITCHING BACK AND FORTH
*/
await GUIActions.switchToReactIframe(driver);
await GUIActions.switchToReactIframe();
await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
await GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse);

View file

@ -0,0 +1,82 @@
import {
WebDriver,
VSBrowser,
EditorView,
InputBox,
TextEditor,
Workbench,
WebView,
} from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { GUIActions } from "../actions/GUI.actions";
import { expect } from "chai";
import { TestUtils } from "../TestUtils";
import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions";
describe("Cmd+L Shortcut Test", () => {
let driver: WebDriver;
let editor: TextEditor;
let view: WebView;
beforeEach(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
await TestUtils.waitForSuccess(async () => {
await new Workbench().executeCommand("Create: New File...");
await (
await InputBox.create(DEFAULT_TIMEOUT.MD)
).selectQuickPick("Text File");
});
driver = VSBrowser.instance.driver;
editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor;
});
afterEach(async function () {
this.timeout(DEFAULT_TIMEOUT.XL * 1000);
await view.switchBack();
await editor.clearText();
await TestUtils.waitForSuccess(
async () => (await GUISelectors.getContinueExtensionBadge(view)).click(),
DEFAULT_TIMEOUT.XS,
);
await new EditorView().closeAllEditors();
});
it("Should not create a code block when Cmd+L is pressed without text highlighted", async () => {
const text = "Hello, world!";
await editor.setText(text);
await KeyboardShortcutsActions.executeFocusContinueInput(driver);
({ view } = await GUIActions.switchToReactIframe());
await TestUtils.expectNoElement(async () => {
return GUISelectors.getInputBoxCodeBlockAtIndex(view, 0);
}, DEFAULT_TIMEOUT.XS);
}).timeout(DEFAULT_TIMEOUT.XL);
it("Should create a code block when Cmd+L is pressed with text highlighted", async () => {
const text = "Hello, world!";
await editor.setText(text);
await editor.selectText(text);
await KeyboardShortcutsActions.executeFocusContinueInput(driver);
({ view } = await GUIActions.switchToReactIframe());
const codeBlock = await TestUtils.waitForSuccess(() =>
GUISelectors.getInputBoxCodeBlockAtIndex(view, 0),
);
const codeblockContent = await codeBlock.getAttribute(
"data-codeblockcontent",
);
expect(codeblockContent).to.equal(text);
}).timeout(DEFAULT_TIMEOUT.XL);
});

View file

@ -629,7 +629,7 @@
"e2e:copy-vsix": "chmod +x ./e2e/get-latest-vsix.sh && bash ./e2e/get-latest-vsix.sh",
"e2e:install-vsix": "extest install-vsix -f ./e2e/vsix/continue.vsix --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:install-extensions": "extest install-from-marketplace ms-vscode-remote.remote-ssh --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage && extest install-from-marketplace ms-vscode-remote.remote-containers --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage && extest install-from-marketplace ms-vscode-remote.remote-wsl --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:test": "extest run-tests './e2e/_output/tests/*.test.js' --code_settings settings.json --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:test": "extest run-tests './e2e/_output/tests/KeyboardShortcuts.test.js' --code_settings settings.json --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage",
"e2e:clean": "rm -rf ./e2e/_output",
"e2e:all": "npm run e2e:build && npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:sign-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && npm run e2e:install-extensions && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean",
"e2e:quick": "npm run e2e:compile && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean",