Files
ServerKit/frontend/src/utils/__tests__/singleFlight.test.mjs
T
Juan Denis b156e2dce1 Keep the 2FA setup modal open until cancelled
Overlay click and Escape closed the setup modal and dropped the user
onto the Change password form. Add a Modal closeOnDismiss prop (default
unchanged) and use it for the setup modal; Cancel and the header X still
close it.

Guard Enable with a ref-based single-flight lock in both the settings
tab and the setup wizard so a double-click cannot fire two requests, and
show a hint after a failed confirm that the code may belong to an older
QR. Add the string to every locale.
2026-11-26 02:38:47 -05:00

35 lines
1.2 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createSingleFlight } from '../singleFlight.js';
import { dismissGuards } from '../../components/ui/dismissGuards.js';
test('single flight refuses a second call before the first settles', async () => {
const run = createSingleFlight();
let calls = 0;
let release;
const first = run(() => { calls += 1; return new Promise((r) => { release = r; }); });
assert.equal(await run(() => { calls += 1; }), undefined);
release('done');
assert.equal(await first, 'done');
assert.equal(calls, 1);
await run(() => { calls += 1; });
assert.equal(calls, 2);
});
test('single flight unlocks after a failure', async () => {
const run = createSingleFlight();
await assert.rejects(run(() => { throw new Error('x'); }));
assert.equal(await run(() => 'ok'), 'ok');
});
test('dismiss guards only block overlay and Escape when asked', () => {
assert.deepEqual(dismissGuards(), {});
const g = dismissGuards(false);
for (const key of ['onPointerDownOutside', 'onInteractOutside', 'onEscapeKeyDown']) {
let prevented = false;
g[key]({ preventDefault: () => { prevented = true; } });
assert.ok(prevented, key);
}
});