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

MessagesTimeline.test.tsx

143 lines4.1 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​
45describe("MessagesTimeline", () => {
46 it("renders inline terminal labels with the composer chip UI", async () => {
47 const { MessagesTimeline } = await import("./MessagesTimeline");
48 const markup = renderToStaticMarkup(
49 <MessagesTimeline
50 hasMessages
51 isWorking={false}
52 activeTurnInProgress={false}
53 activeTurnStartedAt={null}
54 scrollContainer={null}
55 timelineEntries={[
56 {
57 id: "entry-1",
58 kind: "message",
59 createdAt: "2026-03-17T19:12:28.000Z",
60 message: {
61 id: MessageId.makeUnsafe("message-2"),
62 role: "user",
63 text: [
64 "yoo what's @terminal-1:1-5 mean",
65 "",
66 "<terminal_context>",
67 "- Terminal 1 lines 1-5:",
68 " 1 | julius@mac effect-http-ws-cli % bun i",
69 " 2 | bun install v1.3.9 (cf6cdbbb)",
70 "</terminal_context>",
71 ].join("\n"),
72 createdAt: "2026-03-17T19:12:28.000Z",
73 streaming: false,
74 },
75 },
76 ]}
77 completionDividerBeforeEntryId={null}
78 completionSummary={null}
79 turnDiffSummaryByAssistantMessageId={new Map()}
80 nowIso="2026-03-17T19:12:30.000Z"
81 expandedWorkGroups={{}}
82 onToggleWorkGroup={() => {}}
83 onOpenTurnDiff={() => {}}
84 revertTurnCountByUserMessageId={new Map()}
85 onRevertUserMessage={() => {}}
86 isRevertingCheckpoint={false}
87 onImageExpand={() => {}}
88 markdownCwd={undefined}
89 resolvedTheme="light"
90 timestampFormat="locale"
91 workspaceRoot={undefined}
92 />,
93 );
94​
95 expect(markup).toContain("Terminal 1 lines 1-5");
96 expect(markup).toContain("lucide-terminal");
97 expect(markup).toContain("yoo what&#x27;s ");
98 });
99​
100 it("renders context compaction entries in the normal work log", async () => {
101 const { MessagesTimeline } = await import("./MessagesTimeline");
102 const markup = renderToStaticMarkup(
103 <MessagesTimeline
104 hasMessages
105 isWorking={false}
106 activeTurnInProgress={false}
107 activeTurnStartedAt={null}
108 scrollContainer={null}
109 timelineEntries={[
110 {
111 id: "entry-1",
112 kind: "work",
113 createdAt: "2026-03-17T19:12:28.000Z",
114 entry: {
115 id: "work-1",
116 createdAt: "2026-03-17T19:12:28.000Z",
117 label: "Context compacted",
118 tone: "info",
119 },
120 },
121 ]}
122 completionDividerBeforeEntryId={null}
123 completionSummary={null}
124 turnDiffSummaryByAssistantMessageId={new Map()}
125 nowIso="2026-03-17T19:12:30.000Z"
126 expandedWorkGroups={{}}
127 onToggleWorkGroup={() => {}}
128 onOpenTurnDiff={() => {}}
129 revertTurnCountByUserMessageId={new Map()}
130 onRevertUserMessage={() => {}}
131 isRevertingCheckpoint={false}
132 onImageExpand={() => {}}
133 markdownCwd={undefined}
134 resolvedTheme="light"
135 timestampFormat="locale"
136 workspaceRoot={undefined}
137 />,
138 );
139​
140 expect(markup).toContain("Context compacted");
141 expect(markup).toContain("Work log");
142 });
143});