import { describe, expect, test } from "bun:test"; import { resolveMargin, toPdfOptions } from "./options"; describe("resolveMargin", () => { test("defaults to 0.5in on all sides when undefined", () => { expect(resolveMargin(undefined)).toEqual({ top: "0.5in", right: "0.5in", bottom: "0.5in", left: "0.5in", }); }); test("applies a single string to all sides", () => { expect(resolveMargin("2cm")).toEqual({ top: "2cm", right: "2cm", bottom: "2cm", left: "2cm", }); }); test("uses per-side values, defaulting missing sides to 0", () => { expect(resolveMargin({ top: "1in", left: "0.25in" })).toEqual({ top: "1in", right: "0", bottom: "0", left: "0.25in", }); }); }); describe("toPdfOptions", () => { test("defaults: Letter, 0.5in margins, backgrounds on, preferCSSPageSize", () => { expect(toPdfOptions()).toEqual({ format: "Letter", margin: { top: "0.5in", right: "0.5in", bottom: "0.5in", left: "0.5in", }, printBackground: true, preferCSSPageSize: true, }); }); test("maps A4 paper size to format", () => { expect(toPdfOptions({ paperSize: "A4" }).format).toBe("A4"); }); test("respects printBackground: false", () => { expect(toPdfOptions({ printBackground: false }).printBackground).toBe( false, ); }); test("passes through a custom margin", () => { expect(toPdfOptions({ margin: "0" }).margin).toEqual({ top: "0", right: "0", bottom: "0", left: "0", }); }); test("always enables preferCSSPageSize so @page rules win", () => { expect( toPdfOptions({ paperSize: "A4", margin: "1in" }).preferCSSPageSize, ).toBe(true); }); });