forked from bots-garden/ori
| ✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme | 1 | import { render, screen } from "@testing-library/react"; |
| 2 | import { describe, expect, it } from "vitest"; | |
| 3 | import type { ToolCall } from "../reducer"; | |
| 4 | import { ToolCallCard } from "./ToolCallCard"; | |
| 5 | ||
| 6 | function call(overrides: Partial<ToolCall>): ToolCall { | |
| 7 | return { | |
| 8 | toolCallId: "c1", | |
| 9 | title: "A tool call", | |
| 10 | toolKind: "other", | |
| 11 | status: "completed", | |
| 12 | contents: [], | |
| 13 | locations: [], | |
| 14 | ...overrides, | |
| 15 | }; | |
| 16 | } | |
| 17 | ||
| 18 | describe("ToolCallCard", () => { | |
| 19 | it("renders execute output verbatim in a monospace block", () => { | |
| 20 | const { container } = render( | |
| 21 | <ToolCallCard | |
| 22 | call={call({ | |
| 23 | toolKind: "execute", | |
| 24 | contents: [ | |
| 25 | { | |
| 26 | type: "content", | |
| 27 | content: { type: "text", text: "* main\n remote/origin" }, | |
| 28 | }, | |
| 29 | ], | |
| 30 | })} | |
| 31 | />, | |
| 32 | ); | |
| 33 | ||
| 34 | const output = container.querySelector("pre.tool-output"); | |
| 35 | expect(output).not.toBeNull(); | |
| 36 | // Verbatim: the "* " prefix must not have become a markdown list. | |
| 37 | expect(output?.textContent).toBe("* main\n remote/origin"); | |
| 38 | expect(container.querySelector("ul li")).toBeNull(); | |
| 39 | }); | |
| 40 | ||
| 41 | it("renders backticked commands in the title as monospace code", () => { | |
| 42 | const { container } = render( | |
| 43 | <ToolCallCard | |
| 44 | call={call({ toolKind: "execute", title: "Run `ls .memory/`" })} | |
| 45 | />, | |
| 46 | ); | |
| 47 | ||
| 48 | const code = container.querySelector(".tool-title code.inline-code"); | |
| 49 | expect(code?.textContent).toBe("ls .memory/"); | |
| 50 | }); | |
| 51 | ||
| 52 | it("renders non-execute text content as markdown", () => { | |
| 53 | const { container } = render( | |
| 54 | <ToolCallCard | |
| 55 | call={call({ | |
| 56 | toolKind: "read", | |
| 57 | contents: [ | |
| 58 | { | |
| 59 | type: "content", | |
| 60 | content: { type: "text", text: "**bold** result" }, | |
| 61 | }, | |
| 62 | ], | |
| 63 | })} | |
| 64 | />, | |
| 65 | ); | |
| 66 | ||
| 67 | expect(container.querySelector("pre.tool-output")).toBeNull(); | |
| 68 | expect(screen.getByText("bold")).toBeDefined(); | |
| 69 | }); | |
| 70 | }); |