mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 12:22:28 +00:00
Add comment thread and modal regression tests
This commit is contained in:
1 parent
42ef3ddd46
commit
3e27f06a13
2 files changed
+185
No files matched your search
@@ -187,6 +187,39 @@ test("CommentThreadService surfaces cache write failures", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("CommentThreadService persists caches safely during teardown failures", async () => {
|
||||
const warnings = [];
|
||||
const service = new CommentThreadService({
|
||||
fetchVideoComments: async () => [
|
||||
createComment({ id: "persist-me", pubkey: "pk-cache", createdAt: 1 }),
|
||||
],
|
||||
subscribeVideoComments: () => () => {},
|
||||
logger: {
|
||||
warn: (...args) => warnings.push(args),
|
||||
dev: { warn: (...args) => warnings.push(args) },
|
||||
user: { warn: (...args) => warnings.push(args) },
|
||||
},
|
||||
});
|
||||
|
||||
await service.loadThread({ video: createBaseVideo() });
|
||||
|
||||
globalThis.localStorage.setItem = () => {
|
||||
throw new Error("storage blocked");
|
||||
};
|
||||
|
||||
assert.doesNotThrow(() => service.teardown());
|
||||
assert.equal(
|
||||
warnings.some((args) =>
|
||||
args.some?.((value) =>
|
||||
typeof value === "string" &&
|
||||
value.includes("Failed to write comment cache for video123"),
|
||||
),
|
||||
),
|
||||
true,
|
||||
"teardown should warn when persistence fails but still reset state",
|
||||
);
|
||||
});
|
||||
|
||||
test("CommentThreadService logs cache usage and fallback decisions", async () => {
|
||||
const initialFlag = FEATURE_IMPROVED_COMMENT_FETCHING;
|
||||
const devLogs = [];
|
||||
@@ -416,6 +449,51 @@ test("CommentThreadService normalizes mixed-case pubkeys during hydration", asyn
|
||||
);
|
||||
});
|
||||
|
||||
test("CommentThreadService deduplicates mixed-case event ids and pubkeys", async () => {
|
||||
const hydrationRequests = [];
|
||||
const service = new CommentThreadService({
|
||||
fetchVideoComments: async () => [],
|
||||
subscribeVideoComments: () => () => {},
|
||||
batchFetchProfiles: async (pubkeys) => {
|
||||
hydrationRequests.push([...pubkeys]);
|
||||
},
|
||||
hydrationDebounceMs: 0,
|
||||
});
|
||||
|
||||
await service.loadThread({ video: createBaseVideo() });
|
||||
|
||||
const mixedCaseEvent = createComment({
|
||||
id: "CoMmEnT-123", // intentionally mixed case
|
||||
pubkey: "PuBkEy-123",
|
||||
createdAt: 10,
|
||||
});
|
||||
const lowerCaseEvent = createComment({
|
||||
id: "comment-123",
|
||||
pubkey: "pubkey-123",
|
||||
createdAt: 20,
|
||||
});
|
||||
|
||||
service.processIncomingEvent(mixedCaseEvent);
|
||||
service.processIncomingEvent(lowerCaseEvent);
|
||||
await service.flushProfileQueue();
|
||||
|
||||
assert.deepEqual(
|
||||
service.getCommentIdsForParent(null),
|
||||
["comment-123"],
|
||||
"mixed-case duplicates should collapse to a single normalized id",
|
||||
);
|
||||
assert.equal(
|
||||
service.getCommentEvent("COMMENT-123")?.created_at,
|
||||
20,
|
||||
"newer updates should replace existing mixed-case entries",
|
||||
);
|
||||
assert.deepEqual(
|
||||
hydrationRequests,
|
||||
[["pubkey-123"]],
|
||||
"hydration should only request the normalized pubkey once",
|
||||
);
|
||||
});
|
||||
|
||||
test("CommentThreadService retries profile hydration before succeeding", async () => {
|
||||
const profiles = new Map();
|
||||
const hydrationCalls = [];
|
||||
|
||||
Reference in new issue
Block a user