File size: 1,789 Bytes
1187b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { render, screen } from "@testing-library/react";
import { createRef } from "react";
import { describe, expect, it } from "vitest";
import ChatTranscript from "./ChatTranscript";

describe("ChatTranscript", () => {
  it("renders transcript as an accessible log", () => {
    const bottomRef = createRef<HTMLDivElement>();
    render(
      <ChatTranscript
        turns={[{ role: "assistant", created_at: "2026-02-07T12:00:00Z", content: "Hello" }]}
        busy={false}
        bottomRef={bottomRef}
        renderMessage={(turn) => (turn as { content: string }).content}
      />
    );

    expect(screen.getByRole("log", { name: "Conversation transcript" })).toBeInTheDocument();
    expect(screen.getByLabelText("Assistant message")).toBeInTheDocument();
  });

  it("shows status region while busy", () => {
    const bottomRef = createRef<HTMLDivElement>();
    render(
      <ChatTranscript
        turns={[]}
        busy
        bottomRef={bottomRef}
        busyLabel="Thinking..."
        renderMessage={() => null}
      />
    );

    expect(screen.getByRole("status", { name: "Assistant is responding" })).toBeInTheDocument();
    expect(screen.getByText("Thinking...")).toBeInTheDocument();
  });

  it("renders toolbar with jump-to-latest action", () => {
    const bottomRef = createRef<HTMLDivElement>();
    render(
      <ChatTranscript
        turns={[
          { role: "user", content: "Hi" },
          { role: "assistant", content: "Hello" },
        ]}
        busy={false}
        bottomRef={bottomRef}
        renderMessage={(turn) => (turn as { content: string }).content}
      />
    );

    expect(screen.getByText("2 messages")).toBeInTheDocument();
    expect(screen.getByRole("button", { name: "Jump to latest" })).toBeInTheDocument();
  });
});