diff --git a/src/web/components/SiteCreatedModal.test.tsx b/src/web/components/SiteCreatedModal.test.tsx new file mode 100644 index 0000000..65ad4be --- /dev/null +++ b/src/web/components/SiteCreatedModal.test.tsx @@ -0,0 +1,30 @@ +import { describe, expect, it, vi } from 'vitest'; +import { act, create } from 'react-test-renderer'; +import SiteCreatedModal from './SiteCreatedModal.js'; + +describe('SiteCreatedModal', () => { + it('routes native dialog cancel events through onClose cleanup', async () => { + const onChoice = vi.fn(); + const onClose = vi.fn(); + const root = create( + , + ); + + const dialog = root.root.findByType('dialog'); + expect(typeof dialog.props.onCancel).toBe('function'); + + const preventDefault = vi.fn(); + await act(async () => { + dialog.props.onCancel({ preventDefault }); + }); + + expect(preventDefault).toHaveBeenCalledTimes(1); + expect(onClose).toHaveBeenCalledTimes(1); + expect(onChoice).not.toHaveBeenCalled(); + }); +}); diff --git a/src/web/components/SiteCreatedModal.tsx b/src/web/components/SiteCreatedModal.tsx index d060468..d247e88 100644 --- a/src/web/components/SiteCreatedModal.tsx +++ b/src/web/components/SiteCreatedModal.tsx @@ -27,18 +27,14 @@ export default function SiteCreatedModal({ siteName, platform, onChoice, onClose }; }, []); - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Escape') { - e.preventDefault(); - onChoice('later'); - } - }; - return ( { + event.preventDefault(); + onClose(); + }} onClick={(e) => { if (e.target === dialogRef.current) { onChoice('later'); @@ -80,4 +76,4 @@ export default function SiteCreatedModal({ siteName, platform, onChoice, onClose ); -} \ No newline at end of file +}