The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | import { act, render } from "../../../test/render"; |
| 4 | import "../../index.css"; |
| 5 | |
| 6 | import { ensureClientSettingsHydrated, persistClientSettingsPatch } from "../../hooks/useSettings"; |
| 7 | import { MarkdownCodeBlock } from "./MarkdownCodeBlock"; |
| 8 | |
| 9 | const setWordWrap = (wordWrap: boolean) => |
| 10 | act(() => persistClientSettingsPatch({ wordWrap }, async () => {})); |
| 11 | |
| 12 | it("follows a changed word wrap default while mounted", async () => { |
| 13 | await ensureClientSettingsHydrated(); |
| 14 | await setWordWrap(false); |
| 15 | await using screen = await render( |
| 16 | <MarkdownCodeBlock |
| 17 | code="a long line" |
| 18 | language="text" |
| 19 | fenceTitle={null} |
| 20 | theme="light" |
| 21 | isStreaming={false} |
| 22 | > |
| 23 | <pre> |
| 24 | <code>a long line</code> |
| 25 | </pre> |
| 26 | </MarkdownCodeBlock>, |
| 27 | { router: false }, // The code block reads no route state. |
| 28 | ); |
| 29 | const block = () => screen.container.querySelector(".chat-markdown-codeblock"); |
| 30 | expect(block()?.getAttribute("data-wrap")).toBe("false"); |
| 31 | |
| 32 | await setWordWrap(true); |
| 33 | await expect.element(screen.getByRole("button", { name: "Disable line wrap" })).toBeVisible(); |
| 34 | expect(block()?.getAttribute("data-wrap")).toBe("true"); |
| 35 | }); |
| 36 | |
| 37 | it("copies a fenced command without the fence's closing newline", async () => { |
| 38 | await ensureClientSettingsHydrated(); |
| 39 | await using screen = await render( |
| 40 | <MarkdownCodeBlock |
| 41 | code={"sudo pacman -S patchelf\n"} |
| 42 | language="bash" |
| 43 | fenceTitle={null} |
| 44 | theme="light" |
| 45 | isStreaming={false} |
| 46 | > |
| 47 | <pre> |
| 48 | <code>sudo pacman -S patchelf</code> |
| 49 | </pre> |
| 50 | </MarkdownCodeBlock>, |
| 51 | { router: false }, // The code block reads no route state. |
| 52 | ); |
| 53 | using write = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined); |
| 54 | await screen.getByRole("button", { name: "Copy code" }).click(); |
| 55 | await vi.waitFor(() => expect(write).toHaveBeenCalledWith("sudo pacman -S patchelf")); |
| 56 | }); |