Skip to content

Commit d3f9d18

Browse files
wenytang-msCopilot
andcommitted
fix: use context menus for rename/delete, skip native dialog test
- Rename/delete commands have 'when: false' in command palette, so executeCommand cannot find them. Use right-click context menu instead, matching the approach used in the old UI test suite. - Skip 'create with no build tools' test because scaffoldSimpleProject() opens a native OS file dialog that Playwright cannot automate. - Add selectContextMenuItem() helper to VscodeOperator. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4c0f706 commit d3f9d18

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

test/e2e/tests/fileOperations.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,14 @@ test.describe("File Operations", () => {
6969
// Expand to AppToRename
7070
await JavaOperator.expandTreePath(page, "my-app", "src/main/java", "com.mycompany.app");
7171

72-
// Select AppToRename in the tree (clicking opens the file in editor,
73-
// which steals keyboard focus, so we use command palette for rename).
72+
// Right-click AppToRename and select "Rename" from context menu.
73+
// The command java.view.package.renameFile is hidden from the command
74+
// palette (when: false), so context menu is the only UI path.
7475
const appToRename = page.getByRole(VSCode.TREE_ITEM_ROLE, { name: "AppToRename" }).first();
7576
await appToRename.click();
7677
await page.waitForTimeout(Timeout.CLICK);
7778

78-
// Invoke rename via command palette (keyboard F2 requires tree focus
79-
// but clicking the tree item shifts focus to the editor).
80-
await VscodeOperator.executeCommand(page, "Java: Rename");
81-
await page.waitForTimeout(Timeout.CLICK);
79+
await VscodeOperator.selectContextMenuItem(page, appToRename, "Rename");
8280

8381
// The extension shows a showInputBox (quick-input) for the new name
8482
await VscodeOperator.fillQuickInput(page, "AppRenamed");
@@ -99,14 +97,14 @@ test.describe("File Operations", () => {
9997
await JavaOperator.collapseFileExplorer(page);
10098
await JavaOperator.expandTreePath(page, "my-app", "src/main/java", "com.mycompany.app");
10199

102-
// Select AppToDelete (clicking opens the file, shifting focus to editor)
100+
// Right-click AppToDelete and select "Delete" from context menu.
101+
// The command java.view.package.moveFileToTrash is hidden from the
102+
// command palette (when: false), so context menu is the only UI path.
103103
const appToDelete = page.getByRole(VSCode.TREE_ITEM_ROLE, { name: "AppToDelete" }).first();
104104
await appToDelete.click();
105105
await page.waitForTimeout(Timeout.CLICK);
106106

107-
// Invoke delete via command palette (Delete key requires tree focus)
108-
await VscodeOperator.executeCommand(page, "Java: Delete");
109-
await page.waitForTimeout(Timeout.CLICK);
107+
await VscodeOperator.selectContextMenuItem(page, appToDelete, /^Delete/);
110108

111109
// Confirm deletion in dialog
112110
try {

test/e2e/tests/libraries.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ test.describe("Libraries & Project Creation", () => {
4242

4343
test.use({ testProjectDir: "invisible" });
4444

45-
test("java.project.create with no build tools", async ({ page }) => {
45+
test.skip("java.project.create with no build tools", async ({ page }) => {
46+
// Skip: after selecting "No build tools", scaffoldSimpleProject()
47+
// calls vscode.window.showOpenDialog() which opens a native OS file
48+
// dialog that Playwright cannot automate. This test requires
49+
// Electron dialog mocking support.
4650
await VscodeOperator.dismissModalDialog(page);
4751
await JavaOperator.openFile(page, "App.java");
4852
await JavaOperator.waitForJavaLSReady(page);

test/e2e/utils/vscodeOperator.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,24 @@ export default class VscodeOperator {
162162
await page.waitForTimeout(Timeout.CLICK);
163163
}
164164

165+
// -----------------------------------------------------------------------
166+
// Context menus
167+
// -----------------------------------------------------------------------
168+
169+
/**
170+
* Right-clicks an element and selects an item from the context menu.
171+
* Uses text matching to find the menu item.
172+
*/
173+
static async selectContextMenuItem(page: Page, target: ReturnType<Page["locator"]>, menuItemLabel: string | RegExp): Promise<void> {
174+
await target.click({ button: "right" });
175+
const menu = page.locator(".monaco-menu-container");
176+
await menu.waitFor({ state: "visible", timeout: 5_000 });
177+
const item = menu.locator(".action-item").filter({ hasText: menuItemLabel });
178+
await item.first().waitFor({ state: "visible", timeout: 5_000 });
179+
await item.first().click();
180+
await page.waitForTimeout(Timeout.CLICK);
181+
}
182+
165183
// -----------------------------------------------------------------------
166184
// Dialogs
167185
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)