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 { InlineText } from "./InlineText"; | |
| 4 | ||
| 5 | describe("InlineText", () => { | |
| 6 | it("wraps backtick spans in monospace code elements", () => { | |
| 7 | const { container } = render(<InlineText text="Run `ls .memory/` now" />); | |
| 8 | ||
| 9 | const code = container.querySelector("code.inline-code"); | |
| 10 | expect(code?.textContent).toBe("ls .memory/"); | |
| 11 | expect(container.textContent).toBe("Run ls .memory/ now"); | |
| 12 | }); | |
| 13 | ||
| 14 | it("handles several code spans", () => { | |
| 15 | const { container } = render(<InlineText text="`a` puis `b`" />); | |
| 16 | const codes = container.querySelectorAll("code.inline-code"); | |
| 17 | expect(codes).toHaveLength(2); | |
| 18 | expect(codes[0].textContent).toBe("a"); | |
| 19 | expect(codes[1].textContent).toBe("b"); | |
| 20 | }); | |
| 21 | ||
| 22 | it("renders plain text untouched", () => { | |
| 23 | const { container } = render(<InlineText text="no code here" />); | |
| 24 | expect(container.querySelector("code")).toBeNull(); | |
| 25 | expect(screen.getByText("no code here")).toBeDefined(); | |
| 26 | }); | |
| 27 | ||
| 28 | it("leaves an unpaired backtick's tail as plain text", () => { | |
| 29 | const { container } = render(<InlineText text="odd `tick" />); | |
| 30 | // "tick" follows an unclosed backtick: rendered as a code span is | |
| 31 | // acceptable, but the full text must survive. | |
| 32 | expect(container.textContent).toBe("odd tick"); | |
| 33 | }); | |
| 34 | }); |