返回 CodeWhale
install-code-block.test.tsx
根目录 / web / components / install-code-block.test.tsx
1 import { readFileSync } from "node:fs";
2 import { renderToStaticMarkup } from "react-dom/server";
3 import { describe, expect, it } from "vitest";
4 import { InstallCodeBlock } from "./install-code-block";
5 import { siteCss } from "@/lib/site-css";
6
7 const webRoot = new URL("../", import.meta.url);
8 const readWeb = (relativePath: string) => readFileSync(new URL(relativePath, webRoot), "utf8");
9
10 describe("InstallCodeBlock", () => {
11 it("renders a single-line piped install command without splitting the pipe segment", () => {
12 const cmd = "curl -fsSL https://codewhale.net/install.sh | sh";
13 const html = renderToStaticMarkup(<InstallCodeBlock cmd={cmd} />);
14 expect(html).toContain('class="code-block code-block-single"');
15 expect(html).toContain(cmd);
16 expect(html).not.toContain("code-seg-pipe");
17 expect(html).toContain("Copy");
18 });
19
20 it("keeps single-line install commands non-wrapping and horizontally scrollable on narrow viewports", () => {
21 const css = siteCss();
22 const mobileBlock = css.slice(css.lastIndexOf("@media (max-width: 35rem)"));
23 expect(mobileBlock).toContain(".code pre.code-block-single");
24 expect(mobileBlock).toContain("white-space: pre;");
25 expect(mobileBlock).toContain("overflow-x: auto;");
26 expect(mobileBlock).toContain("overflow-wrap: normal;");
27 expect(mobileBlock).toContain("text-indent: 0;");
28 });
29
30 it("keys transient copy and route state to prop or pathname identity across interactive surfaces", () => {
31 expect(readWeb("components/install-code-block.tsx")).toContain("const copied = copiedCmd === cmd;");
32 expect(readWeb("components/docs-preview/page-actions.tsx")).toContain("const copied = copiedHref === markdownHref;");
33 expect(readWeb("components/ratatui/explorer.tsx")).toContain("const status = result && result.text === text ? result.kind : \"idle\";");
34 expect(readWeb("components/docs-preview/toc.tsx")).toContain("const active = headings.some((heading) => heading.id === current)");
35 expect(readWeb("components/mobile-menu.tsx")).toContain("const open = openPathname !== null && openPathname === pathname;");
36 expect(readWeb("components/locale-switcher.tsx")).toContain("const { search, hash } = window.location;");
37 });
38 });
39
39 lines Plain Text