一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
37 行
1.3 KiB
TypeScript
37 行
1.3 KiB
TypeScript
import { ElectronApplication } from '@playwright/test';
|
|
import { BaseWindow, MessageBoxOptions } from 'electron';
|
|
|
|
const setMessageBoxResponse = (electronApp: ElectronApplication, responseMatch: RegExp) => {
|
|
return electronApp.evaluate(async ({ dialog }, responseMatch) => {
|
|
type DialogArgsType = [ BaseWindow, MessageBoxOptions ]|[MessageBoxOptions];
|
|
|
|
const getMatchingButton = (dialogArgs: DialogArgsType) => {
|
|
const matchingButton = (options: MessageBoxOptions) => {
|
|
const buttons = options.buttons ?? ['OK'];
|
|
|
|
for (let i = 0; i < buttons.length; i++) {
|
|
if (buttons[i].match(responseMatch)) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
throw new Error('No matching button found');
|
|
};
|
|
|
|
if (dialogArgs.length === 1) {
|
|
return matchingButton(dialogArgs[0]);
|
|
} else {
|
|
return matchingButton(dialogArgs[1]);
|
|
}
|
|
};
|
|
dialog.showMessageBoxSync = (...args: DialogArgsType) => getMatchingButton(args);
|
|
dialog.showMessageBox = async (...args: DialogArgsType) => ({
|
|
response: getMatchingButton(args),
|
|
checkboxChecked: false,
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Mock return; cast prevents breakage when Electron's MessageBoxReturnValue shape evolves
|
|
} as any);
|
|
}, responseMatch);
|
|
};
|
|
|
|
export default setMessageBoxResponse;
|