Elffuss BraidHub

kikocis/continue public

main · 4.4 KiBRawPermalink
1import {
2 By,
3 EditorView,
4 InputBox,
5 TextEditor,
6 VSBrowser,
7 Workbench,
8} from "vscode-extension-tester";
9
10import { DEFAULT_TIMEOUT } from "../constants";
11import { TestUtils } from "../TestUtils";
12
13export class GlobalActions {
14 static defaultFolder = "e2e/test-continue";
15 public static defaultNewFilename = "test.py";
16
17 public static async openTestWorkspace() {
18 await VSBrowser.instance.openResources(GlobalActions.defaultFolder);
19 await new Workbench().executeCommand(
20 "Notifications: Clear All Notifications",
21 );
22 }
23
24 public static async clearAllNotifications() {
25 await new Workbench().executeCommand(
26 "Notifications: Clear All Notifications",
27 );
28 }
29
30 public static async createAndOpenNewTextFile(): Promise<{
31 editor: TextEditor;
32 }> {
33 await new Workbench().executeCommand("Create: New File...");
34 await (
35 await InputBox.create(DEFAULT_TIMEOUT.MD)
36 ).selectQuickPick("Text File");
37 const editor = (await new EditorView().openEditor(
38 "Untitled-1",
39 )) as TextEditor;
40
41 return { editor };
42 }
43
44 public static async createAndSaveNewFile(
45 filename = GlobalActions.defaultNewFilename,
46 ): Promise<{
47 editor: TextEditor;
48 }> {
49 let { editor } = await GlobalActions.createAndOpenNewTextFile();
50
51 await new Workbench().executeCommand("File: Save As...");
52 const inputBox = await InputBox.create(DEFAULT_TIMEOUT.MD);
53
54 // Get current path and replace filename
55 const currentPath = await inputBox.getText();
56 const pathParts = currentPath.split(/[\/\\]/);
57 pathParts[pathParts.length - 1] = filename;
58 const newPath = pathParts.join("/");
59
60 await inputBox.setText(newPath);
61
62 await inputBox.confirm();
63 await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);
64
65 editor = (await new EditorView().openEditor(filename)) as TextEditor;
66
67 return { editor };
68 }
69
70 public static async deleteFileFromFolder(
71 filename = GlobalActions.defaultNewFilename,
72 folder = GlobalActions.defaultFolder,
73 ): Promise<void> {
74 const fs = require("fs");
75 const path = require("path");
76
77 const folderPath = path.join(process.cwd(), folder);
78 const filePath = path.join(folderPath, filename);
79
80 try {
81 await fs.promises.unlink(filePath);
82 } catch (error) {
83 console.warn(`Failed to delete file ${filePath}:`, error);
84 }
85 }
86
87 static async setNextEditEnabled(enabled: boolean) {
88 const workbench = new Workbench();
89
90 await workbench.openCommandPrompt();
91 process.env.CONTINUE_E2E_NON_NEXT_EDIT_TEST = "true";
92
93 // Initial wait and clear
94 await TestUtils.waitForTimeout(1000);
95 await GlobalActions.clearAllNotifications();
96
97 const statusBar = await workbench.getStatusBar();
98
99 // Robust element finding with text validation
100 const continueItem = await TestUtils.waitForSuccess(async () => {
101 // Clear any new notifications
102 try {
103 await GlobalActions.clearAllNotifications();
104 } catch (e) {
105 // Ignore
106 }
107
108 const element = await statusBar.findElement(
109 By.xpath("//*[contains(text(), 'Continue')]"),
110 );
111
112 // Validate we can get text
113 const text = await element.getText();
114 if (!text || text.trim() === "") {
115 // Try alternative methods
116 const textContent = await element.getAttribute("textContent");
117 if (!textContent || textContent.trim() === "") {
118 throw new Error("Text not yet available");
119 }
120 }
121
122 return element;
123 }, DEFAULT_TIMEOUT.MD);
124
125 // Get text with retry
126 const text = await TestUtils.waitForSuccess(async () => {
127 const itemText = await continueItem.getText();
128 if (!itemText || itemText.trim() === "") {
129 // Fallback to textContent
130 const textContent = await continueItem.getAttribute("textContent");
131 if (textContent && textContent.trim() !== "") {
132 return textContent;
133 }
134 throw new Error("Text content not yet available");
135 }
136 return itemText;
137 }, DEFAULT_TIMEOUT.MD);
138
139 console.log("Final text:", text);
140
141 const hasNE = text.includes("(NE)");
142 console.log("hasNE:", hasNE);
143
144 if (hasNE !== enabled) {
145 await workbench.executeCommand("Continue: Toggle Next Edit");
146 // Clear any resulting notifications
147 await TestUtils.waitForTimeout(500);
148 await GlobalActions.clearAllNotifications();
149 }
150 }
151
152 static async disableNextEdit() {
153 await this.setNextEditEnabled(false);
154 }
155}