1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Web: Fix tapping outside alert/confirm dialogs doesn't dismiss them correctly (#12144)

This commit is contained in:
Henry Heino
2025-04-24 00:50:35 -07:00
committed by GitHub
parent 6bb289338e
commit 807bcdcf95
4 changed files with 24 additions and 4 deletions

View File

@@ -1,14 +1,15 @@
import { MessageBoxType } from '@joplin/lib/shim';
import { DialogControl } from '../components/DialogManager';
import { PromptButtonSpec } from '../components/DialogManager/types';
import makeShowMessageBox from './makeShowMessageBox';
type OnPrompt = (buttons: PromptButtonSpec[])=> void;
type OnPrompt = (buttons: PromptButtonSpec[], onDismiss: ()=> void)=> void;
const makeMockDialogControl = (onPrompt: OnPrompt): DialogControl => {
return {
info: jest.fn(),
error: jest.fn(),
prompt: jest.fn((_title, _message, buttons) => {
onPrompt(buttons);
prompt: jest.fn((_title, _message, buttons, options) => {
onPrompt(buttons, options.onDismiss);
}),
showMenu: jest.fn(),
};
@@ -24,4 +25,16 @@ describe('makeShowMessageBox', () => {
const okButtonIndex = 0;
expect(await showMessageBox('test')).toBe(okButtonIndex);
});
test('should resolve to the index of the cancel button when cancelled', async () => {
const dialogControl = makeMockDialogControl((_buttons, onDismiss) => {
// Cancel
onDismiss();
});
const showMessageBox = makeShowMessageBox({ current: dialogControl });
expect(await showMessageBox('test')).toBe(1); // Cancel button index
// Should resolve to -1 when there is no cancel button
expect(await showMessageBox('test', { type: MessageBoxType.Error })).toBe(-1);
});
});