import { render, screen } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import type { ToolCall } from "../reducer"; import { ToolCallCard, contentText, toolContentText } from "./ToolCallCard"; function call(overrides: Partial): ToolCall { return { toolCallId: "c1", title: "A tool call", toolKind: "other", status: "completed", contents: [], locations: [], ...overrides, }; } describe("ToolCallCard", () => { it("renders execute output verbatim in a monospace block", () => { const { container } = render( , ); const output = container.querySelector("pre.tool-output"); expect(output).not.toBeNull(); // Verbatim: the "* " prefix must not have become a markdown list. expect(output?.textContent).toBe("* main\n remote/origin"); expect(container.querySelector("ul li")).toBeNull(); }); it("renders backticked commands in the title as monospace code", () => { const { container } = render( , ); const code = container.querySelector(".tool-title code.inline-code"); expect(code?.textContent).toBe("ls .memory/"); }); it("renders non-execute text content as markdown", () => { const { container } = render( , ); expect(container.querySelector("pre.tool-output")).toBeNull(); expect(screen.getByText("bold")).toBeDefined(); }); }); describe("toolContentText", () => { it("returns the text of content blocks", () => { expect( contentText({ type: "content", content: { type: "text", text: "hi" } }), ).toBe("hi"); }); it("flattens a diff into labelled path, old and new sections", () => { expect( contentText({ type: "diff", path: "a.go", oldText: "x", newText: "y" }), ).toBe("Path: a.go\n\nOld:\nx\n\nNew:\ny"); }); it("omits diff sections that are absent", () => { expect(contentText({ type: "diff", path: "a.go", newText: "y" })).toBe( "Path: a.go\n\nNew:\ny", ); }); it("ignores terminal blocks and joins the rest with blank lines", () => { expect( toolContentText([ { type: "terminal", terminalId: "t1" }, { type: "content", content: { type: "text", text: "one" } }, { type: "content", content: { type: "text", text: "" } }, { type: "content", content: { type: "text", text: "two" } }, ]), ).toBe("one\n\ntwo"); }); it("hides the copy button when the call has no textual content", () => { render( , ); expect(screen.queryByLabelText("Copy tool output")).toBeNull(); }); });