import { describe, expect, test } from "bun:test"; import { buildPrintCss, PRINT_BASE_CSS } from "./print-css"; describe("PRINT_BASE_CSS", () => { test("preserves background colors via print-color-adjust", () => { expect(PRINT_BASE_CSS).toContain("-webkit-print-color-adjust: exact"); expect(PRINT_BASE_CSS).toContain("print-color-adjust: exact"); }); test("sets orphans/widows defaults for editorial pagination", () => { expect(PRINT_BASE_CSS).toContain("orphans: 3"); expect(PRINT_BASE_CSS).toContain("widows: 3"); }); test("exposes page-break utility classes", () => { expect(PRINT_BASE_CSS).toContain(".break-before"); expect(PRINT_BASE_CSS).toContain("break-before: page"); expect(PRINT_BASE_CSS).toContain(".break-after"); expect(PRINT_BASE_CSS).toContain("break-after: page"); expect(PRINT_BASE_CSS).toContain(".break-inside-avoid"); expect(PRINT_BASE_CSS).toContain("break-inside: avoid"); }); test("keeps headings attached to following content", () => { expect(PRINT_BASE_CSS).toContain("break-after: avoid"); }); test("is size-agnostic (no @page rule)", () => { expect(PRINT_BASE_CSS).not.toContain("@page"); }); }); describe("buildPrintCss", () => { test("defaults to Letter with 0.5in margins", () => { const css = buildPrintCss(); expect(css).toContain("@page"); expect(css).toContain("size: letter"); expect(css).toContain("margin: 0.5in"); // base rules are appended expect(css).toContain("print-color-adjust: exact"); }); test("maps A4 paper size", () => { const css = buildPrintCss({ paperSize: "A4" }); expect(css).toContain("size: A4"); }); test("accepts a single string margin for all sides", () => { const css = buildPrintCss({ margin: "1cm" }); expect(css).toContain("margin: 1cm"); }); test("expands per-side margins, defaulting missing sides to 0", () => { const css = buildPrintCss({ margin: { top: "1in", bottom: "0.75in" } }); expect(css).toContain("margin: 1in 0 0.75in 0"); }); });