|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { after, before, test } from "node:test"; |
| 3 | +import { JSDOM } from "jsdom"; |
| 4 | + |
| 5 | +const dom = new JSDOM("<!doctype html><html><body></body></html>", { |
| 6 | + url: "http://localhost", |
| 7 | +}); |
| 8 | +before(() => { |
| 9 | + Object.assign(globalThis, { |
| 10 | + document: dom.window.document, |
| 11 | + HTMLElement: dom.window.HTMLElement, |
| 12 | + IS_REACT_ACT_ENVIRONMENT: true, |
| 13 | + window: dom.window, |
| 14 | + }); |
| 15 | +}); |
| 16 | +after(() => dom.window.close()); |
| 17 | + |
| 18 | +test("timeline intent keeps an ordinary reply out of the thread panel", async () => { |
| 19 | + const { cleanup, renderHook } = await import("@testing-library/react"); |
| 20 | + const { useChannelRouteTarget } = await import("./useChannelRouteTarget.ts"); |
| 21 | + const calls = []; |
| 22 | + const root = { |
| 23 | + id: "root", |
| 24 | + parentId: null, |
| 25 | + rootId: null, |
| 26 | + tags: [], |
| 27 | + }; |
| 28 | + const reply = { |
| 29 | + id: "reply", |
| 30 | + parentId: "root", |
| 31 | + rootId: "root", |
| 32 | + tags: [ |
| 33 | + ["e", "root", "", "root"], |
| 34 | + ["e", "root", "", "reply"], |
| 35 | + ], |
| 36 | + }; |
| 37 | + |
| 38 | + const hook = renderHook(() => |
| 39 | + useChannelRouteTarget({ |
| 40 | + activeChannel: { id: "channel", channelType: "stream" }, |
| 41 | + activeChannelId: "channel", |
| 42 | + closeAgentSession: () => calls.push("close-agent"), |
| 43 | + requireThreadEditResolution: () => { |
| 44 | + calls.push("resolve-edit"); |
| 45 | + return true; |
| 46 | + }, |
| 47 | + setEditTargetId: () => calls.push("edit"), |
| 48 | + setExpandedThreadReplyIds: () => calls.push("expand"), |
| 49 | + setOpenThreadHeadId: () => calls.push("open-thread"), |
| 50 | + setProfilePanelPubkey: () => calls.push("profile"), |
| 51 | + setThreadReplyTargetId: () => calls.push("reply-target"), |
| 52 | + setThreadScrollTargetId: () => calls.push("scroll"), |
| 53 | + targetMessageId: "reply", |
| 54 | + targetMessageView: "timeline", |
| 55 | + timelineMessages: [root, reply], |
| 56 | + }), |
| 57 | + ); |
| 58 | + |
| 59 | + assert.equal(hook.result.current, "root"); |
| 60 | + assert.deepEqual(calls, []); |
| 61 | + hook.unmount(); |
| 62 | + cleanup(); |
| 63 | +}); |
| 64 | + |
| 65 | +test("timeline intent preserves the exact id of a broadcast reply row", async () => { |
| 66 | + const { cleanup, renderHook } = await import("@testing-library/react"); |
| 67 | + const { useChannelRouteTarget } = await import("./useChannelRouteTarget.ts"); |
| 68 | + const broadcast = { |
| 69 | + id: "broadcast-reply", |
| 70 | + parentId: "root", |
| 71 | + rootId: "root", |
| 72 | + tags: [ |
| 73 | + ["e", "root", "", "root"], |
| 74 | + ["e", "root", "", "reply"], |
| 75 | + ["broadcast", "1"], |
| 76 | + ], |
| 77 | + }; |
| 78 | + |
| 79 | + const hook = renderHook(() => |
| 80 | + useChannelRouteTarget({ |
| 81 | + activeChannel: { id: "channel", channelType: "stream" }, |
| 82 | + activeChannelId: "channel", |
| 83 | + closeAgentSession: () => {}, |
| 84 | + requireThreadEditResolution: () => true, |
| 85 | + setEditTargetId: () => {}, |
| 86 | + setExpandedThreadReplyIds: () => {}, |
| 87 | + setOpenThreadHeadId: () => {}, |
| 88 | + setProfilePanelPubkey: () => {}, |
| 89 | + setThreadReplyTargetId: () => {}, |
| 90 | + setThreadScrollTargetId: () => {}, |
| 91 | + targetMessageId: "broadcast-reply", |
| 92 | + targetMessageView: "timeline", |
| 93 | + timelineMessages: [broadcast], |
| 94 | + }), |
| 95 | + ); |
| 96 | + |
| 97 | + assert.equal(hook.result.current, "broadcast-reply"); |
| 98 | + hook.unmount(); |
| 99 | + cleanup(); |
| 100 | +}); |
0 commit comments