| 1 | import { |
| 2 | EditorView, |
| 3 | InputBox, |
| 4 | TextEditor, |
| 5 | VSBrowser, |
| 6 | Workbench, |
| 7 | } from "vscode-extension-tester"; |
| 8 | |
| 9 | import { DEFAULT_TIMEOUT } from "../constants"; |
| 10 | import { TestUtils } from "../TestUtils"; |
| 11 | |
| 12 | export class GlobalActions { |
| 13 | static defaultFolder = "e2e/test-continue"; |
| 14 | public static defaultNewFilename = "test.py"; |
| 15 | |
| 16 | public static async openTestWorkspace() { |
| 17 | await VSBrowser.instance.openResources(GlobalActions.defaultFolder); |
| 18 | await new Workbench().executeCommand( |
| 19 | "Notifications: Clear All Notifications", |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | public static async clearAllNotifications() { |
| 24 | await new Workbench().executeCommand( |
| 25 | "Notifications: Clear All Notifications", |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | public static async createAndOpenNewTextFile(): Promise<{ |
| 30 | editor: TextEditor; |
| 31 | }> { |
| 32 | await new Workbench().executeCommand("Create: New File..."); |
| 33 | await ( |
| 34 | await InputBox.create(DEFAULT_TIMEOUT.MD) |
| 35 | ).selectQuickPick("Text File"); |
| 36 | const editor = (await new EditorView().openEditor( |
| 37 | "Untitled-1", |
| 38 | )) as TextEditor; |
| 39 | |
| 40 | return { editor }; |
| 41 | } |
| 42 | |
| 43 | public static async createAndSaveNewFile( |
| 44 | filename = GlobalActions.defaultNewFilename, |
| 45 | ): Promise<{ |
| 46 | editor: TextEditor; |
| 47 | }> { |
| 48 | let { editor } = await GlobalActions.createAndOpenNewTextFile(); |
| 49 | |
| 50 | await new Workbench().executeCommand("File: Save As..."); |
| 51 | const inputBox = await InputBox.create(DEFAULT_TIMEOUT.MD); |
| 52 | |
| 53 | // Get current path and replace filename |
| 54 | const currentPath = await inputBox.getText(); |
| 55 | const pathParts = currentPath.split(/[\/\\]/); |
| 56 | pathParts[pathParts.length - 1] = filename; |
| 57 | const newPath = pathParts.join("/"); |
| 58 | |
| 59 | await inputBox.setText(newPath); |
| 60 | |
| 61 | await inputBox.confirm(); |
| 62 | await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS); |
| 63 | |
| 64 | editor = (await new EditorView().openEditor(filename)) as TextEditor; |
| 65 | |
| 66 | return { editor }; |
| 67 | } |
| 68 | |
| 69 | public static async deleteFileFromFolder( |
| 70 | filename = GlobalActions.defaultNewFilename, |
| 71 | folder = GlobalActions.defaultFolder, |
| 72 | ): Promise<void> { |
| 73 | const fs = require("fs"); |
| 74 | const path = require("path"); |
| 75 | |
| 76 | const folderPath = path.join(process.cwd(), folder); |
| 77 | const filePath = path.join(folderPath, filename); |
| 78 | |
| 79 | try { |
| 80 | await fs.promises.unlink(filePath); |
| 81 | } catch (error) { |
| 82 | console.warn(`Failed to delete file ${filePath}:`, error); |
| 83 | } |
| 84 | } |
| 85 | } |