Open History to see the last commit
1import { renderToStaticMarkup } from "react-dom/server";
2import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
3
4const testState = vi.hoisted(() => ({
5 codeViewClassName: null as string | null,
6 codeViewOptions: null as Record<string, unknown> | null,
7}));
8
9vi.mock("@pierre/diffs/react", () => ({
10 CodeView: (props: { className: string; options: Record<string, unknown> }) => {
11 testState.codeViewClassName = props.className;
12 testState.codeViewOptions = props.options;
13 return null;
14 },
15}));
16
17import { StyledDiffCodeView } from "./StyledDiffCodeView";
18
19describe("StyledDiffCodeView", () => {
20 beforeEach(() => {
21 testState.codeViewClassName = null;
22 testState.codeViewOptions = null;
23 });
24
25 it("always pairs the shared diff styling with its virtualized geometry", () => {
26 const loadDiffFiles = vi.fn(async () => ({
27 oldFile: { name: "before.ts", contents: "before\n" },
28 newFile: { name: "after.ts", contents: "after\n" },
29 }));
30 renderToStaticMarkup(
31 <StyledDiffCodeView
32 className="min-h-0"
33 items={[]}
34 options={{ theme: "pierre-dark", stickyHeaders: true, loadDiffFiles }}
35 />,
36 );
37
38 expect(testState.codeViewClassName).toBe(
39 "diff-render-surface [--code-background:var(--background)] outline-none min-h-0",
40 );
41 expect(testState.codeViewOptions).toMatchObject({
42 theme: "pierre-dark",
43 stickyHeaders: true,
44 loadDiffFiles,
45 itemMetrics: {
46 diffHeaderHeight: 32,
47 hunkSeparatorHeight: 24,
48 paddingTop: 0,
49 paddingBottom: 8,
50 },
51 layout: { paddingTop: 0, paddingBottom: 0, gap: 0 },
52 });
53 expect(testState.codeViewOptions?.unsafeCSS).toEqual(
54 expect.stringContaining("[data-unmodified-lines]::before"),
55 );
56 expect(testState.codeViewOptions?.unsafeCSS).toEqual(
57 expect.stringContaining(")[data-expand-index]\n [data-unmodified-lines]"),
58 );
59 });
60});