diff --git a/extensions/vscode/e2e/actions/NextEdit.actions.ts b/extensions/vscode/e2e/actions/NextEdit.actions.ts new file mode 100644 index 000000000..b627ce957 --- /dev/null +++ b/extensions/vscode/e2e/actions/NextEdit.actions.ts @@ -0,0 +1,25 @@ +import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester"; + +import { DEFAULT_TIMEOUT } from "../constants"; +import { NextEditSelectors } from "../selectors/NextEdit.selectors"; +import { TestUtils } from "../TestUtils"; + +export class NextEditActions { + /** + * Force a Next Edit suggestion using command. + */ + public static async forceNextEdit(editor: TextEditor): Promise { + await editor.setText("def main():\n "); + await editor.moveCursor(2, 4); + + await new Workbench().executeCommand("Continue: Force Next Edit"); + await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.MD); + + const svgDecoration = await TestUtils.waitForSuccess( + () => NextEditSelectors.getSvgDecoration(VSBrowser.instance.driver), + DEFAULT_TIMEOUT.XL + ); + + return svgDecoration !== null; + } +} diff --git a/extensions/vscode/e2e/selectors/NextEdit.selectors.ts b/extensions/vscode/e2e/selectors/NextEdit.selectors.ts new file mode 100644 index 000000000..3fb6f0083 --- /dev/null +++ b/extensions/vscode/e2e/selectors/NextEdit.selectors.ts @@ -0,0 +1,19 @@ +import { By, WebDriver } from "vscode-extension-tester"; + +export class NextEditSelectors { + /** + * Get the SVG decoration element if present (for next edit). + */ + public static async getSvgDecoration(driver: WebDriver) { + try { + const decorations = await driver.findElement( + // By.xpath("//*[contains(@class, 'ced-') and matches(@class, 'ced-2-TextEditorDecorationType[0-9]+-4')]") + By.css("[class*='TextEditorDecorationType']") + ); + return decorations ?? null; + } catch (error) { + console.error("Error finding SVG decoration:", error); + return null; + } + } +} \ No newline at end of file diff --git a/extensions/vscode/e2e/tests/NextEdit.test.ts b/extensions/vscode/e2e/tests/NextEdit.test.ts new file mode 100644 index 000000000..6e048b935 --- /dev/null +++ b/extensions/vscode/e2e/tests/NextEdit.test.ts @@ -0,0 +1,44 @@ +import { expect } from "chai"; +import { EditorView, TextEditor } from "vscode-extension-tester"; + +import { GlobalActions } from "../actions/Global.actions"; +import { NextEditActions } from "../actions/NextEdit.actions"; +import { DEFAULT_TIMEOUT } from "../constants"; + +describe("Next Edit", () => { + let editor: TextEditor; + + beforeEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await GlobalActions.openTestWorkspace(); + ({ editor } = await GlobalActions.createAndOpenNewTextFile()); + }); + + afterEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + await editor.clearText(); + await new EditorView().closeAllEditors(); + }); + + it("Should enable Next Edit feature in settings", async () => { + expect(false).to.be.true; + }).timeout(DEFAULT_TIMEOUT.XL); + + it("Should check that autocomplete is disabled when next edit is enabled", async () => { + expect(false).to.be.true; + }).timeout(DEFAULT_TIMEOUT.XL); + + it("Should accept Next Edit suggestion with Tab", async () => { + expect(false).to.be.true; + }).timeout(DEFAULT_TIMEOUT.XL); + + it("Should reject Next Edit suggestion with Esc", async () => { + expect(false).to.be.true; + }).timeout(DEFAULT_TIMEOUT.XL); + + it.only("Should force a Next Edit", async () => { + const hasDecoration = await NextEditActions.forceNextEdit(editor); + expect(hasDecoration).to.be.true; + }).timeout(DEFAULT_TIMEOUT.XL); +}); \ No newline at end of file