add svg decoration render test for next edit

This commit is contained in:
Jacob Kim 2025-06-27 16:41:13 -07:00
parent bb0775882a
commit 4b642303de
3 changed files with 88 additions and 0 deletions

View file

@ -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<boolean> {
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;
}
}

View file

@ -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;
}
}
}

View file

@ -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);
});