Skip to content

Commit 73a5342

Browse files
wenytang-msCopilot
andcommitted
fix: find OK button by label in showMessageBox, handle Refactor Preview
On Linux the button order in dialog.showMessageBox differs from Windows, so response:0 selects 'Show Preview' instead of 'OK'. Fix by scanning the buttons array for the 'OK' label. Also handle the Refactor Preview panel (Apply/Discard) as a fallback in case the dialog still enters preview mode. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bc0741b commit 73a5342

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

test/e2e/fixtures/baseTest.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,26 @@ export const test = base.extend<TestFixtures>({
106106
// Auto-dismiss Electron native dialogs (e.g. redhat.java refactoring
107107
// confirmation "wants to make refactoring changes"). These dialogs are
108108
// outside the renderer DOM and cannot be handled via Playwright Page API.
109-
// Monkey-patch dialog.showMessageBox in the main process to auto-click OK.
109+
// Monkey-patch dialog.showMessageBox in the main process to find and
110+
// click the "OK" button by label, falling back to the first button.
110111
await electronApp.evaluate(({ dialog }) => {
111-
dialog.showMessageBox = async () => ({ response: 0, checkboxChecked: true });
112-
dialog.showMessageBoxSync = () => 0;
112+
const origShowMessageBox = dialog.showMessageBox;
113+
dialog.showMessageBox = async (_win: any, opts: any) => {
114+
// opts may be the first arg if called without a window
115+
const options = opts || _win;
116+
const buttons: string[] = options?.buttons || [];
117+
// Find "OK" button index; fall back to first button
118+
let idx = buttons.findIndex((b: string) => /^OK$/i.test(b));
119+
if (idx < 0) idx = 0;
120+
return { response: idx, checkboxChecked: true };
121+
};
122+
dialog.showMessageBoxSync = (_win: any, opts: any) => {
123+
const options = opts || _win;
124+
const buttons: string[] = options?.buttons || [];
125+
let idx = buttons.findIndex((b: string) => /^OK$/i.test(b));
126+
if (idx < 0) idx = 0;
127+
return idx;
128+
};
113129
});
114130

115131
// Dismiss any startup notifications/dialogs before handing off to tests

test/e2e/tests/fileOperations.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ test.describe("File Operations", () => {
8787
// Dialog may not appear in all cases
8888
}
8989

90+
// On Linux, if the refactoring dialog resolved to "Show Preview",
91+
// VS Code shows a Refactor Preview panel with "Apply" / "Discard"
92+
// buttons. Click "Apply" to complete the rename.
93+
try {
94+
const applyBtn = page.getByRole(VSCode.BUTTON_ROLE, { name: "Apply" });
95+
if (await applyBtn.isVisible({ timeout: 3_000 }).catch(() => false)) {
96+
await applyBtn.click();
97+
await page.waitForTimeout(Timeout.CLICK);
98+
}
99+
} catch {
100+
// No refactor preview
101+
}
102+
90103
// Editor should open with renamed file
91104
const tabFound = await VscodeOperator.waitForEditorTab(page, "AppRenamed.java");
92105
expect(tabFound).toBeTruthy();

0 commit comments

Comments
 (0)