Merge pull request #3681 from continuedev/pe/edit-e2e-tests

test(e2e): edit flow
This commit is contained in:
Patrick Erichsen 2025-01-10 15:38:51 -08:00 • committed by GitHub
commit fda7dca5af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 227 additions and 31 deletions

View file

@ -6,6 +6,7 @@
},
"plugins": ["@typescript-eslint", "import"],
"rules": {
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",

View file

@ -5,6 +5,6 @@
},
"extends": ["../../.eslintrc.shared.json"],
"rules": {
"@typescript-eslint/naming-convention": "warn"
"@typescript-eslint/naming-convention": "off"
}
}

View file

@ -1,9 +1,6 @@
import { expect } from "chai";
import {
Key,
WebElement,
waitForAttributeValue,
} from "vscode-extension-tester";
import { Key } from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "./constants";
export class TestUtils {

View file

@ -1,8 +1,9 @@
import { TextEditor } from "vscode-extension-tester";
import { TestUtils } from "../TestUtils";
import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors";
import { expect } from "chai";
import { TextEditor } from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors";
import { TestUtils } from "../TestUtils";
export class AutocompleteActions {
public static async testCompletions(editor: TextEditor) {

View file

@ -0,0 +1,40 @@
import { TextEditor, WebView } from "vscode-extension-tester";
import { EditSelectors } from "../selectors/Edit.selectors";
import { TestUtils } from "../TestUtils";
export class EditActions {
static async invokeEditShortcut(editor: TextEditor) {
editor
.getDriver()
.actions()
.keyDown(TestUtils.osControlKey)
.sendKeys("i")
.keyUp(TestUtils.osControlKey)
.perform();
}
static async acceptEditInGUI(view: WebView): Promise<void> {
await TestUtils.waitForSuccess(async () =>
(await EditSelectors.getEditAcceptButton(view)).click(),
);
await view.switchBack();
}
static async rejectEditInGUI(view: WebView): Promise<void> {
await TestUtils.waitForSuccess(async () =>
(await EditSelectors.getEditRejectButton(view)).click(),
);
await view.switchBack();
}
static async acceptEditWithCodeLens(editor: TextEditor): Promise<void> {
const acceptCodeLens = await editor.getCodeLens("Accept");
await acceptCodeLens?.click();
}
static async rejectEditWithCodeLens(editor: TextEditor): Promise<void> {
const rejectCodeLens = await editor.getCodeLens("Reject");
await rejectCodeLens?.click();
}
}

View file

@ -6,9 +6,10 @@ import {
WebView,
Workbench,
} from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
import { DEFAULT_TIMEOUT } from "../constants";
export class GUIActions {
public static moveContinueToSidebar = async (driver: WebDriver) => {

View file

@ -1,7 +1,29 @@
import { VSBrowser, WebView } from "vscode-extension-tester";
import {
EditorView,
InputBox,
TextEditor,
VSBrowser,
Workbench,
} from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
export class GlobalActions {
public static async openTestWorkspace() {
return VSBrowser.instance.openResources("e2e/test-continue");
}
public static async createAndOpenNewTextFile(): Promise<{
editor: TextEditor;
}> {
await new Workbench().executeCommand("Create: New File...");
await (
await InputBox.create(DEFAULT_TIMEOUT.MD)
).selectQuickPick("Text File");
const editor = (await new EditorView().openEditor(
"Untitled-1",
)) as TextEditor;
return { editor };
}
}

View file

@ -1,6 +1,4 @@
import { TextEditor, WebDriver, WebView } from "vscode-extension-tester";
import { TestUtils } from "../TestUtils";
import { TextEditor } from "vscode-extension-tester";
export class KeyboardShortcutsActions {
/**

View file

@ -0,0 +1,13 @@
import { WebView } from "vscode-extension-tester";
import { SelectorUtils } from "./SelectorUtils";
export class EditSelectors {
public static getEditAcceptButton(view: WebView) {
return SelectorUtils.getElementByDataTestId(view, "edit-accept-button");
}
public static getEditRejectButton(view: WebView) {
return SelectorUtils.getElementByDataTestId(view, "edit-reject-button");
}
}

View file

@ -1,4 +1,5 @@
import { By, until, WebDriver, WebView } from "vscode-extension-tester";
import { By, WebDriver, WebView } from "vscode-extension-tester";
import { SelectorUtils } from "./SelectorUtils";
export class GUISelectors {

View file

@ -1,13 +1,8 @@
import {
EditorView,
TextEditor,
InputBox,
Workbench,
} from "vscode-extension-tester";
import { EditorView, TextEditor } from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
import { GlobalActions } from "../actions/Global.actions";
import { AutocompleteActions } from "../actions/Autocomplete.actions";
import { GlobalActions } from "../actions/Global.actions";
import { DEFAULT_TIMEOUT } from "../constants";
describe("Autocomplete", () => {
let editor: TextEditor;
@ -16,11 +11,7 @@ describe("Autocomplete", () => {
this.timeout(DEFAULT_TIMEOUT.XL);
await GlobalActions.openTestWorkspace();
await new Workbench().executeCommand("Create: New File...");
await (
await InputBox.create(DEFAULT_TIMEOUT.MD)
).selectQuickPick("Text File");
editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor;
({ editor } = await GlobalActions.createAndOpenNewTextFile());
});
afterEach(async function () {

View file

@ -0,0 +1,125 @@
import {
EditorView,
WebView,
WebDriver,
Key,
VSBrowser,
InputBox,
TextEditor,
Workbench,
} from "vscode-extension-tester";
import { EditActions } from "../actions/Edit.actions";
import { GlobalActions } from "../actions/Global.actions";
import { GUIActions } from "../actions/GUI.actions";
import { DEFAULT_TIMEOUT } from "../constants";
import { EditSelectors } from "../selectors/Edit.selectors";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
describe("Edit Test", () => {
let view: WebView;
let editor: TextEditor;
let originalEditorText = "Hello world!";
let { userMessage, llmResponse } = TestUtils.generateTestMessagePair();
before(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
await GlobalActions.openTestWorkspace();
({ editor } = await GlobalActions.createAndOpenNewTextFile());
});
beforeEach(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
await GUIActions.toggleGui();
await editor.typeTextAt(1, 1, originalEditorText);
await editor.selectText(originalEditorText);
await EditActions.invokeEditShortcut(editor);
({ view } = await GUIActions.switchToReactIframe());
await GUIActions.sendMessage({
view,
message: userMessage,
inputFieldIndex: 0,
});
await view.switchBack();
await TestUtils.waitForSuccess(async () => {
const editorText = await editor.getText();
return editorText.includes(llmResponse);
});
});
afterEach(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
await editor.clearText();
});
it("Accepts an Edit in the GUI", async () => {
({ view } = await GUIActions.switchToReactIframe());
await EditActions.acceptEditInGUI(view);
await view.switchBack();
const editorText = await editor.getText();
await TestUtils.waitForSuccess(
async () =>
!editorText.includes(originalEditorText) &&
editorText.includes(llmResponse),
DEFAULT_TIMEOUT.SM,
);
}).timeout(DEFAULT_TIMEOUT.XL);
it("Rejects an Edit in the GUI", async () => {
({ view } = await GUIActions.switchToReactIframe());
await EditActions.rejectEditInGUI(view);
await view.switchBack();
const editorText = await editor.getText();
await TestUtils.waitForSuccess(
async () =>
editorText.includes(originalEditorText) &&
!editorText.includes(llmResponse),
DEFAULT_TIMEOUT.SM,
);
}).timeout(DEFAULT_TIMEOUT.XL);
it("Accepts an Edit using CodeLens buttons", async () => {
const acceptCodeLens = await editor.getCodeLens("Accept");
await acceptCodeLens?.click();
const editorText = await editor.getText();
await TestUtils.waitForSuccess(
async () =>
!editorText.includes(originalEditorText) &&
editorText.includes(llmResponse),
DEFAULT_TIMEOUT.SM,
);
}).timeout(DEFAULT_TIMEOUT.XL);
it("Rejects an Edit using CodeLens buttons", async () => {
const rejectCodeLens = await editor.getCodeLens("Reject");
await rejectCodeLens?.click();
const editorText = await editor.getText();
await TestUtils.waitForSuccess(
async () =>
!editorText.includes(originalEditorText) &&
editorText.includes(llmResponse),
DEFAULT_TIMEOUT.SM,
);
}).timeout(DEFAULT_TIMEOUT.XL);
});

View file

@ -1,3 +1,4 @@
import { expect } from "chai";
import {
EditorView,
WebView,
@ -7,12 +8,12 @@ import {
VSBrowser,
until,
} from "vscode-extension-tester";
import { expect } from "chai";
import { GlobalActions } from "../actions/Global.actions";
import { GUIActions } from "../actions/GUI.actions";
import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
import { DEFAULT_TIMEOUT } from "../constants";
import { GlobalActions } from "../actions/Global.actions";
describe("GUI Test", () => {
let view: WebView;

View file

@ -11,6 +11,9 @@
// "plugin:@typescript-eslint/recommended-requiring-type-checking"
// "plugin:react/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": "off"
},
"overrides": [
{
"files": ["src/**/*.{js,ts,jsx,tsx}"]

View file

@ -38,6 +38,7 @@ export default function AcceptRejectAllButtons({
<button
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
onClick={() => handleAcceptOrReject("rejectDiff")}
data-testid="edit-reject-button"
>
<XMarkIcon className="mr-1 h-4 w-4 text-red-600" />
{isSingleRangeEdit ? (
@ -53,6 +54,7 @@ export default function AcceptRejectAllButtons({
<button
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
onClick={() => handleAcceptOrReject("acceptDiff")}
data-testid="edit-accept-button"
>
<CheckIcon className="mr-1 h-4 w-4 text-green-600" />
{isSingleRangeEdit ? (