Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

MessagesTimeline.test.tsx

147 lines4.3 KB

1import { MessageId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { beforeAll, describe, expect, it, vi } from "vitest";
4​
5function matchMedia() {
6 return {
7 matches: false,
8 addEventListener: () => {},
9 removeEventListener: () => {},
10 };
12​
13beforeAll(() => {
14 const classList = {
15 add: () => {},
16 remove: () => {},
17 toggle: () => {},
18 contains: () => false,
19 };
20​
21 vi.stubGlobal("localStorage", {
22 getItem: () => null,
23 setItem: () => {},
24 removeItem: () => {},
25 clear: () => {},
26 });
27 vi.stubGlobal("window", {
28 matchMedia,
29 addEventListener: () => {},
30 removeEventListener: () => {},
31 desktopBridge: undefined,
32 });
33 vi.stubGlobal("document", {
34 documentElement: {
35 classList,
36 offsetHeight: 0,
37 },
38 });
39 vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
40 callback(0);
41 return 0;
42 });
43});
44​
45const ACTIVE_THREAD_ENVIRONMENT_ID = "environment-local" as never;
46​
47describe("MessagesTimeline", () => {
48 it("renders inline terminal labels with the composer chip UI", async () => {
49 const { MessagesTimeline } = await import("./MessagesTimeline");
50 const markup = renderToStaticMarkup(
51 <MessagesTimeline
52 hasMessages
53 isWorking={false}
54 activeTurnInProgress={false}
55 activeTurnStartedAt={null}
56 scrollContainer={null}
57 timelineEntries={[
58 {
59 id: "entry-1",
60 kind: "message",
61 createdAt: "2026-03-17T19:12:28.000Z",
62 message: {
63 id: MessageId.makeUnsafe("message-2"),
64 role: "user",
65 text: [
66 "yoo what's @terminal-1:1-5 mean",
67 "",
68 "<terminal_context>",
69 "- Terminal 1 lines 1-5:",
70 " 1 | julius@mac effect-http-ws-cli % bun i",
71 " 2 | bun install v1.3.9 (cf6cdbbb)",
72 "</terminal_context>",
73 ].join("\n"),
74 createdAt: "2026-03-17T19:12:28.000Z",
75 streaming: false,
76 },
77 },
78 ]}
79 completionDividerBeforeEntryId={null}
80 completionSummary={null}
81 turnDiffSummaryByAssistantMessageId={new Map()}
82 nowIso="2026-03-17T19:12:30.000Z"
83 expandedWorkGroups={{}}
84 onToggleWorkGroup={() => {}}
85 onOpenTurnDiff={() => {}}
86 revertTurnCountByUserMessageId={new Map()}
87 onRevertUserMessage={() => {}}
88 isRevertingCheckpoint={false}
89 onImageExpand={() => {}}
90 activeThreadEnvironmentId={ACTIVE_THREAD_ENVIRONMENT_ID}
91 markdownCwd={undefined}
92 resolvedTheme="light"
93 timestampFormat="locale"
94 workspaceRoot={undefined}
95 />,
96 );
97​
98 expect(markup).toContain("Terminal 1 lines 1-5");
99 expect(markup).toContain("lucide-terminal");
100 expect(markup).toContain("yoo what&#x27;s ");
101 }, 10_000);
102​
103 it("renders context compaction entries in the normal work log", async () => {
104 const { MessagesTimeline } = await import("./MessagesTimeline");
105 const markup = renderToStaticMarkup(
106 <MessagesTimeline
107 hasMessages
108 isWorking={false}
109 activeTurnInProgress={false}
110 activeTurnStartedAt={null}
111 scrollContainer={null}
112 timelineEntries={[
113 {
114 id: "entry-1",
115 kind: "work",
116 createdAt: "2026-03-17T19:12:28.000Z",
117 entry: {
118 id: "work-1",
119 createdAt: "2026-03-17T19:12:28.000Z",
120 label: "Context compacted",
121 tone: "info",
122 },
123 },
124 ]}
125 completionDividerBeforeEntryId={null}
126 completionSummary={null}
127 turnDiffSummaryByAssistantMessageId={new Map()}
128 nowIso="2026-03-17T19:12:30.000Z"
129 expandedWorkGroups={{}}
130 onToggleWorkGroup={() => {}}
131 onOpenTurnDiff={() => {}}
132 revertTurnCountByUserMessageId={new Map()}
133 onRevertUserMessage={() => {}}
134 isRevertingCheckpoint={false}
135 onImageExpand={() => {}}
136 activeThreadEnvironmentId={ACTIVE_THREAD_ENVIRONMENT_ID}
137 markdownCwd={undefined}
138 resolvedTheme="light"
139 timestampFormat="locale"
140 workspaceRoot={undefined}
141 />,
142 );
143​
144 expect(markup).toContain("Context compacted");
145 expect(markup).toContain("Work log");
146 });
147});