import { test } from 'node:test'; import assert from 'node:assert/strict'; const store = new Map(); (globalThis as { sessionStorage?: unknown }).sessionStorage = { getItem: (k: string) => store.get(k) ?? null, setItem: (k: string, v: string) => { store.set(k, v); }, removeItem: (k: string) => { store.delete(k); }, }; const m = await import('./expectedDevices'); test('[#121] parses the fork messages defensively', () => { assert.deepEqual( m.parseDeviceMissing({ missing: [ { kind: 'audioinput', expected: 'Arctis 7', fallback: 'Laptop Mic' }, { kind: 'audiooutput', expected: 'Arctis 7', fallback: null }, { kind: 'videoinput', expected: 'Cam' }, { kind: 'audioinput' }, ], }), [ { kind: 'audioinput', expected: 'Arctis 7', fallback: 'Laptop Mic' }, { kind: 'audiooutput', expected: 'Arctis 7', fallback: null }, ], ); assert.deepEqual(m.parseDeviceMissing(undefined), []); assert.deepEqual(m.parseDeviceMissing({ missing: 'x' }), []); assert.equal(m.parseDeviceLost({ kind: 'nope' }), undefined); }); test('[#121] wording', () => { assert.deepEqual( m.describeMissing({ kind: 'audioinput', expected: 'Arctis 7', fallback: 'Laptop Mic' }), { title: "Your usual microphone isn't connected", expected: 'Arctis 7', fallback: 'Laptop Mic', }, ); assert.equal( m.describeLost({ kind: 'audiooutput', expected: 'Arctis 7', fallback: null }), 'Arctis 7 disconnected — now using the default output.', ); }); test('[#121] "Join anyway" is remembered for the session, per device set', () => { store.clear(); const a = [{ kind: 'audioinput' as const, expected: 'Arctis 7', fallback: 'Laptop Mic' }]; const b = [{ kind: 'audiooutput' as const, expected: 'Arctis 7', fallback: null }]; assert.equal(m.isAcceptedThisSession(a), false); m.acceptForSession(a); assert.equal(m.isAcceptedThisSession(a), true); assert.equal(m.isAcceptedThisSession(b), false, 'a different device still asks'); assert.equal(m.isAcceptedThisSession([...a, ...b]), false, 'more missing still asks'); });