mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 22:46:32 +00:00
fix(client): work through the findings from the coverage pass
214 items came out of writing the tests. Real defects are corrected, dead code is removed rather than covered, and the tests that pinned the old behaviour move with them. Also drops two agent coverage scratch files that slipped into the coverage PR and adds the ignore rule that keeps them out.
This commit is contained in:
@@ -76,6 +76,21 @@ describe('ConfirmDialog', () => {
|
||||
expect(onClose).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-009: a rejecting async onConfirm does not escape as an unhandled rejection', async () => {
|
||||
const unhandled = vi.fn();
|
||||
process.on('unhandledRejection', unhandled);
|
||||
const failing = vi.fn(() => Promise.reject(new Error('delete failed')));
|
||||
|
||||
render(<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={failing} />);
|
||||
fireEvent.click(screen.getByRole('button', { name: /delete/i }));
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
|
||||
expect(failing).toHaveBeenCalledOnce();
|
||||
expect(onClose).toHaveBeenCalledOnce();
|
||||
expect(unhandled).not.toHaveBeenCalled();
|
||||
process.off('unhandledRejection', unhandled);
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-008: clicking backdrop calls onClose', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} message="msg" />);
|
||||
|
||||
@@ -14,6 +14,16 @@ interface ConfirmDialogProps {
|
||||
danger?: boolean
|
||||
}
|
||||
|
||||
// Callers commonly pass an async handler that reports its own failure and then
|
||||
// rethrows. The dialog has already closed at that point, so the rejection would
|
||||
// escape as an unhandled promise — absorb it here.
|
||||
function runConfirm(onConfirm: () => void): void {
|
||||
const result = onConfirm() as unknown
|
||||
if (result && typeof (result as PromiseLike<unknown>).then === 'function') {
|
||||
void Promise.resolve(result).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
export default function ConfirmDialog({
|
||||
isOpen,
|
||||
onClose,
|
||||
@@ -73,7 +83,7 @@ export default function ConfirmDialog({
|
||||
{cancelLabel || t('common.cancel')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { onConfirm(); onClose() }}
|
||||
onClick={() => { runConfirm(onConfirm); onClose() }}
|
||||
className={`px-4 py-2 text-sm font-medium rounded-lg transition-colors text-white ${
|
||||
danger ? 'bg-red-600 hover:bg-red-700' : 'bg-blue-600 hover:bg-blue-700'
|
||||
}`}
|
||||
|
||||
Reference in New Issue
Block a user