Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import { expect } from "chai";
2import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester";
3
4import { DEFAULT_TIMEOUT } from "../constants";
5import { NextEditSelectors } from "../selectors/NextEdit.selectors";
6import { TestUtils } from "../TestUtils";
7
8export class NextEditActions {
9 /**
10 * Test accepting a Next Edit suggestion with Tab.
11 */
12 public static async acceptNextEditSuggestion(editor: TextEditor) {
13 const hasDecoration = await NextEditActions.forceNextEdit(editor);
14 expect(hasDecoration).to.be.true;
15
16 await new Workbench().executeCommand(
17 "Continue: Accept Next Edit Suggestion",
18 );
19
20 // Check if HELLO is written into the editor.
21 const editorText = await editor.getTextAtLine(2);
22
23 return editorText === "HELLO";
24 }
25
26 /**
27 * Test rejecting a Next Edit suggestion with Esc.
28 */
29 public static async rejectNextEditSuggestion(editor: TextEditor) {
30 const hasDecoration = await NextEditActions.forceNextEdit(editor);
31 expect(hasDecoration).to.be.true;
32
33 await new Workbench().executeCommand("Continue: Hide Next Edit Suggestion");
34
35 // Check if the editor text didn't change.
36 const editorText = await editor.getText();
37
38 return editorText === "def main():\n s";
39 }
40
41 /**
42 * Force a Next Edit suggestion using command.
43 */
44 public static async forceNextEdit(editor: TextEditor): Promise<boolean> {
45 console.log("Starting forceNextEdit...");
46 await editor.setText("def main():\n s");
47 console.log("Text set in editor");
48 await editor.moveCursor(2, 4);
49 console.log("Cursor moved to position 2, 4");
50
51 await new Workbench().executeCommand("Continue: Force Next Edit");
52 console.log("Executed 'Force Next Edit' command");
53
54 // console.log("Waiting for SVG decoration to appear...");
55 // await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.MD);
56 // console.log("Wait completed, looking for decoration...");
57 console.log("Looking for decoration...");
58
59 const svgDecoration = await TestUtils.waitForSuccess(
60 () => NextEditSelectors.getSvgDecoration(VSBrowser.instance.driver),
61 DEFAULT_TIMEOUT.XL,
62 );
63
64 const result = svgDecoration !== null;
65 console.log("SVG decoration search result:", result);
66 return result;
67 }
68
69 public static async reload(): Promise<void> {
70 await new Workbench().executeCommand("workbench.action.reloadWindow");
71 }
72}