test: lotus decorations, call caps, crypto, featureCheck, typing, markdown (+34)
Subagent batch (no bugs found) + markdown: - lotus/avatarDecorations (8): decorationUrl, CDN shape, ALL_DECORATIONS flattening, data invariants (unique category ids + slugs, slug charset). - plugins/call/utils (7): getCallCapabilities — static caps + room/user/device scoped state-keys. - utils/matrix-crypto (3): verifiedDevice via a stubbed CryptoApi. - utils/featureCheck (3): checkIndexedDBSupport success/error/throw paths. - state/typingMembers (8): add/dedup-by-latest-ts/per-room-scope/delete reducer via a jotai store (enableMapSet, mirroring app startup). - plugins/markdown/utils (5): inline + block escape/unescape round-trips. Full suite now 231 tests, all passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { test, afterEach } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { checkIndexedDBSupport } from './featureCheck';
|
||||
|
||||
// `checkIndexedDBSupport` resolves by talking to the global `indexedDB`. There
|
||||
// is no real IndexedDB in this Node test environment, so each case installs a
|
||||
// minimal stub on `globalThis.indexedDB` and restores it afterwards.
|
||||
type OpenRequest = {
|
||||
onsuccess?: () => void;
|
||||
onerror?: () => void;
|
||||
};
|
||||
|
||||
const originalIndexedDB = (globalThis as { indexedDB?: unknown }).indexedDB;
|
||||
|
||||
afterEach(() => {
|
||||
(globalThis as { indexedDB?: unknown }).indexedDB = originalIndexedDB;
|
||||
});
|
||||
|
||||
const installIndexedDB = (impl: unknown) => {
|
||||
(globalThis as { indexedDB?: unknown }).indexedDB = impl;
|
||||
};
|
||||
|
||||
test('resolves true when the open request fires onsuccess', async () => {
|
||||
let deleted = false;
|
||||
installIndexedDB({
|
||||
open: (): OpenRequest => {
|
||||
const req: OpenRequest = {};
|
||||
// fire async, mimicking the real event loop
|
||||
queueMicrotask(() => req.onsuccess?.());
|
||||
return req;
|
||||
},
|
||||
deleteDatabase: () => {
|
||||
deleted = true;
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(await checkIndexedDBSupport(), true);
|
||||
assert.equal(deleted, true);
|
||||
});
|
||||
|
||||
test('resolves false when the open request fires onerror', async () => {
|
||||
installIndexedDB({
|
||||
open: (): OpenRequest => {
|
||||
const req: OpenRequest = {};
|
||||
queueMicrotask(() => req.onerror?.());
|
||||
return req;
|
||||
},
|
||||
deleteDatabase: () => {},
|
||||
});
|
||||
|
||||
assert.equal(await checkIndexedDBSupport(), false);
|
||||
});
|
||||
|
||||
test('resolves false when indexedDB.open throws synchronously', async () => {
|
||||
installIndexedDB({
|
||||
open: () => {
|
||||
throw new Error('blocked');
|
||||
},
|
||||
deleteDatabase: () => {},
|
||||
});
|
||||
|
||||
assert.equal(await checkIndexedDBSupport(), false);
|
||||
});
|
||||
Reference in New Issue
Block a user