import { describe, it, expect } from "vitest"; import { buildPdfOptions, PdfRenderOptions } from "../services/browser.js"; describe("buildPdfOptions", () => { it("returns sensible defaults when no options given", () => { const result = buildPdfOptions({}); expect(result).toEqual({ format: "A4", landscape: false, printBackground: true, margin: { top: "0", right: "0", bottom: "0", left: "0" }, }); }); it("passes through all provided options", () => { const opts: PdfRenderOptions = { format: "Letter", landscape: true, printBackground: false, margin: { top: "10mm", bottom: "10mm" }, scale: 1.5, pageRanges: "1-3", preferCSSPageSize: true, width: "210mm", height: "297mm", headerTemplate: "Header", footerTemplate: "Footer", displayHeaderFooter: true, }; const result = buildPdfOptions(opts); expect(result.format).toBe("Letter"); expect(result.landscape).toBe(true); expect(result.printBackground).toBe(false); expect(result.margin).toEqual({ top: "10mm", bottom: "10mm" }); expect(result.scale).toBe(1.5); expect(result.pageRanges).toBe("1-3"); expect(result.preferCSSPageSize).toBe(true); expect(result.width).toBe("210mm"); expect(result.height).toBe("297mm"); expect(result.headerTemplate).toBe("Header"); expect(result.footerTemplate).toBe("Footer"); expect(result.displayHeaderFooter).toBe(true); }); it("omits undefined optional fields from output", () => { const result = buildPdfOptions({ format: "A4" }); expect(result).not.toHaveProperty("scale"); expect(result).not.toHaveProperty("pageRanges"); expect(result).not.toHaveProperty("preferCSSPageSize"); expect(result).not.toHaveProperty("width"); expect(result).not.toHaveProperty("height"); expect(result).not.toHaveProperty("headerTemplate"); expect(result).not.toHaveProperty("footerTemplate"); }); it("handles printBackground false explicitly", () => { const result = buildPdfOptions({ printBackground: false }); expect(result.printBackground).toBe(false); }); it("defaults displayHeaderFooter to false only when explicitly set", () => { const r1 = buildPdfOptions({}); expect(r1).not.toHaveProperty("displayHeaderFooter"); const r2 = buildPdfOptions({ displayHeaderFooter: false }); expect(r2.displayHeaderFooter).toBe(false); }); });