From c1fa03598f2c536a5eb6d501ba2271a3112849cf Mon Sep 17 00:00:00 2001 From: tornquist Date: Wed, 2 Sep 2026 21:08:12 +0000 Subject: [PATCH] test(desktop): cover nested live reply projection Co-authored-by: Codex Signed-off-by: tornquist --- .../channels/useLiveChannelUpdates.test.mjs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/desktop/src/features/channels/useLiveChannelUpdates.test.mjs b/desktop/src/features/channels/useLiveChannelUpdates.test.mjs index 0e3e5f9e6a..a496b2bb0d 100644 --- a/desktop/src/features/channels/useLiveChannelUpdates.test.mjs +++ b/desktop/src/features/channels/useLiveChannelUpdates.test.mjs @@ -33,6 +33,7 @@ after(() => dom.window.close()); const CHANNEL_ID = "channel-a"; const ROOT_ID = "a".repeat(64); +const PARENT_ID = "1".repeat(64); const EXISTING_REPLY_ID = "b".repeat(64); const NEW_REPLY_ID = "c".repeat(64); const TOP_LEVEL_ID = "d".repeat(64); @@ -134,6 +135,47 @@ test("non-broadcast replies stay out of channelMessagesKey and merge into an exi client.clear(); }); +test("nested non-broadcast replies use the root thread cache instead of the parent cache", async () => { + const client = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + client.setQueryData(channelMessagesKey(CHANNEL_ID), [rootEvent()]); + const parentReply = directReplyEvent(PARENT_ID, 101, [], "parent-reply"); + client.setQueryData(threadRepliesKey(CHANNEL_ID, ROOT_ID), [parentReply]); + + const { callback, unmount } = await mountLiveUpdates(client); + const nestedReply = event( + NEW_REPLY_ID, + 102, + [ + ["h", CHANNEL_ID], + ["e", ROOT_ID, "", "root"], + ["e", PARENT_ID, "", "reply"], + ], + "nested-reply", + ); + + callback(nestedReply); + + assert.deepEqual(client.getQueryData(channelMessagesKey(CHANNEL_ID)), [ + rootEvent(), + ]); + assert.deepEqual(client.getQueryData(threadRepliesKey(CHANNEL_ID, ROOT_ID)), [ + parentReply, + nestedReply, + ]); + assert.equal( + client.getQueryCache().find({ + queryKey: threadRepliesKey(CHANNEL_ID, PARENT_ID), + exact: true, + }), + undefined, + ); + + unmount(); + client.clear(); +}); + test("non-broadcast replies merge into an existing empty thread query", async () => { const client = new QueryClient({ defaultOptions: { queries: { retry: false } },