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("diff-render-surface outline-none min-h-0");
39 expect(testState.codeViewOptions).toMatchObject({
40 theme: "pierre-dark",
41 stickyHeaders: true,
42 loadDiffFiles,
43 itemMetrics: {
44 diffHeaderHeight: 32,
45 hunkSeparatorHeight: 24,
46 paddingTop: 0,
47 paddingBottom: 8,
48 },
49 layout: { paddingTop: 0, paddingBottom: 0, gap: 0 },
50 });
51 expect(testState.codeViewOptions?.unsafeCSS).toEqual(
52 expect.stringContaining("[data-unmodified-lines]::before"),
53 );
54 expect(testState.codeViewOptions?.unsafeCSS).toEqual(
55 expect.stringContaining(")[data-expand-index]\n [data-unmodified-lines]"),
56 );
57 });
58});