|
1 | | -import { MessageId } from "@okcode/contracts"; |
| 1 | +import { MessageId, TurnId } from "@okcode/contracts"; |
2 | 2 | import type { ReactElement } from "react"; |
3 | 3 | import { renderToStaticMarkup } from "react-dom/server"; |
4 | 4 | import { beforeAll, describe, expect, it, vi } from "vitest"; |
@@ -201,4 +201,130 @@ describe("MessagesTimeline", () => { |
201 | 201 | expect(markup).toContain("Manage hotkeys"); |
202 | 202 | expect(markup).toContain("No shortcut assigned"); |
203 | 203 | }); |
| 204 | + |
| 205 | + it("renders an open diff action when a turn diff summary has files", async () => { |
| 206 | + const { MessagesTimeline } = await import("./MessagesTimeline"); |
| 207 | + const assistantMessageId = MessageId.makeUnsafe("assistant-1"); |
| 208 | + const markup = renderWithI18n( |
| 209 | + <MessagesTimeline |
| 210 | + threadId={"thread-1" as never} |
| 211 | + hasMessages |
| 212 | + isWorking={false} |
| 213 | + activeTurnInProgress={false} |
| 214 | + activeTurnStartedAt={null} |
| 215 | + scrollContainer={null} |
| 216 | + timelineEntries={[ |
| 217 | + { |
| 218 | + id: "entry-1", |
| 219 | + kind: "message", |
| 220 | + createdAt: "2026-03-17T19:12:28.000Z", |
| 221 | + message: { |
| 222 | + id: assistantMessageId, |
| 223 | + role: "assistant", |
| 224 | + text: "Updated the repo.", |
| 225 | + createdAt: "2026-03-17T19:12:28.000Z", |
| 226 | + completedAt: "2026-03-17T19:12:30.000Z", |
| 227 | + streaming: false, |
| 228 | + }, |
| 229 | + }, |
| 230 | + ]} |
| 231 | + completionDividerBeforeEntryId={null} |
| 232 | + completionSummary={null} |
| 233 | + turnDiffSummaryByAssistantMessageId={ |
| 234 | + new Map([ |
| 235 | + [ |
| 236 | + assistantMessageId, |
| 237 | + { |
| 238 | + turnId: TurnId.makeUnsafe("turn-1"), |
| 239 | + completedAt: "2026-03-17T19:12:30.000Z", |
| 240 | + files: [{ path: "src/index.ts", additions: 1, deletions: 0 }], |
| 241 | + }, |
| 242 | + ], |
| 243 | + ]) |
| 244 | + } |
| 245 | + nowIso="2026-03-17T19:12:30.000Z" |
| 246 | + expandedWorkGroups={{}} |
| 247 | + onToggleWorkGroup={() => {}} |
| 248 | + revertTurnCountByUserMessageId={new Map()} |
| 249 | + onRevertUserMessage={() => {}} |
| 250 | + isRevertingCheckpoint={false} |
| 251 | + onImageExpand={() => {}} |
| 252 | + markdownCwd={undefined} |
| 253 | + resolvedTheme="light" |
| 254 | + showReasoningContent={false} |
| 255 | + timestampFormat="locale" |
| 256 | + workspaceRoot={undefined} |
| 257 | + onRemoveQueuedMessage={() => {}} |
| 258 | + shortcutGuides={EMPTY_SHORTCUT_GUIDES} |
| 259 | + onOpenSettings={() => {}} |
| 260 | + onOpenTurnDiff={() => {}} |
| 261 | + />, |
| 262 | + ); |
| 263 | + |
| 264 | + expect(markup).toContain("Open diff"); |
| 265 | + expect(markup).toContain("Changed files (1)"); |
| 266 | + }); |
| 267 | + |
| 268 | + it("renders an open diff action when a turn diff exists but the file summary is empty", async () => { |
| 269 | + const { MessagesTimeline } = await import("./MessagesTimeline"); |
| 270 | + const assistantMessageId = MessageId.makeUnsafe("assistant-2"); |
| 271 | + const markup = renderWithI18n( |
| 272 | + <MessagesTimeline |
| 273 | + threadId={"thread-1" as never} |
| 274 | + hasMessages |
| 275 | + isWorking={false} |
| 276 | + activeTurnInProgress={false} |
| 277 | + activeTurnStartedAt={null} |
| 278 | + scrollContainer={null} |
| 279 | + timelineEntries={[ |
| 280 | + { |
| 281 | + id: "entry-1", |
| 282 | + kind: "message", |
| 283 | + createdAt: "2026-03-17T19:12:28.000Z", |
| 284 | + message: { |
| 285 | + id: assistantMessageId, |
| 286 | + role: "assistant", |
| 287 | + text: "Updated the repo.", |
| 288 | + createdAt: "2026-03-17T19:12:28.000Z", |
| 289 | + completedAt: "2026-03-17T19:12:30.000Z", |
| 290 | + streaming: false, |
| 291 | + }, |
| 292 | + }, |
| 293 | + ]} |
| 294 | + completionDividerBeforeEntryId={null} |
| 295 | + completionSummary={null} |
| 296 | + turnDiffSummaryByAssistantMessageId={ |
| 297 | + new Map([ |
| 298 | + [ |
| 299 | + assistantMessageId, |
| 300 | + { |
| 301 | + turnId: TurnId.makeUnsafe("turn-2"), |
| 302 | + completedAt: "2026-03-17T19:12:30.000Z", |
| 303 | + files: [], |
| 304 | + }, |
| 305 | + ], |
| 306 | + ]) |
| 307 | + } |
| 308 | + nowIso="2026-03-17T19:12:30.000Z" |
| 309 | + expandedWorkGroups={{}} |
| 310 | + onToggleWorkGroup={() => {}} |
| 311 | + revertTurnCountByUserMessageId={new Map()} |
| 312 | + onRevertUserMessage={() => {}} |
| 313 | + isRevertingCheckpoint={false} |
| 314 | + onImageExpand={() => {}} |
| 315 | + markdownCwd={undefined} |
| 316 | + resolvedTheme="light" |
| 317 | + showReasoningContent={false} |
| 318 | + timestampFormat="locale" |
| 319 | + workspaceRoot={undefined} |
| 320 | + onRemoveQueuedMessage={() => {}} |
| 321 | + shortcutGuides={EMPTY_SHORTCUT_GUIDES} |
| 322 | + onOpenSettings={() => {}} |
| 323 | + onOpenTurnDiff={() => {}} |
| 324 | + />, |
| 325 | + ); |
| 326 | + |
| 327 | + expect(markup).toContain("Open diff"); |
| 328 | + expect(markup).toContain("Diff available"); |
| 329 | + }); |
204 | 330 | }); |
0 commit comments