import { sealClass, sealImageCss, sealMarkup } from "./seal-markup.util"; /** * These three helpers are the single image-vs-text branch shared by every * EDR document's round seal, so a regression here silently unstamps invoices, * warehouse release papers and handover papers at once. */ describe("seal markup helpers", () => { const STAMP = "data:image/png;base64,QUJD"; describe("sealMarkup", () => { it("renders the stamp image when one is configured", () => { expect(sealMarkup(STAMP, ["EDR", "Warehouse"])).toBe( `Company stamp`, ); }); it("falls back to text rings when no stamp is configured", () => { expect(sealMarkup(null, ["EDR", "Warehouse", "Cleared"])).toBe( "EDR
Warehouse
Cleared
", ); }); it("treats undefined as unset", () => { expect(sealMarkup(undefined, "EDR")).toBe("EDR"); }); it("accepts a bare string as a single line", () => { expect(sealMarkup(null, "EDR")).toBe("EDR"); }); it("escapes text lines so document data cannot inject markup", () => { expect(sealMarkup(null, [''])).toBe( "<script>alert("x")</script>", ); }); it("escapes the image src so it cannot break out of the attribute", () => { expect(sealMarkup('data:image/png;base64,A" onerror="x', "EDR")).toBe( 'Company stamp', ); }); }); describe("sealClass", () => { it("adds the image modifier only when stamped", () => { expect(sealClass(STAMP)).toBe("seal seal-image"); expect(sealClass(null)).toBe("seal"); }); it("honours a document's own seal selector", () => { expect(sealClass(STAMP, "sig-stamp-box")).toBe( "sig-stamp-box sig-stamp-box-image", ); expect(sealClass(null, "sig-stamp-box")).toBe("sig-stamp-box"); }); }); describe("sealImageCss", () => { it("neutralizes the drawn ring and rotation for a real stamp image", () => { const css = sealImageCss(); expect(css).toContain(".seal.seal-image { border: none;"); expect(css).toContain("transform: none;"); // The ::before pseudo-element draws the inner ring of the text seal. expect(css).toContain(".seal.seal-image::before { content: none; }"); expect(css).toContain(".seal img { max-width: 100%;"); }); it("scopes every rule to the given selector", () => { const css = sealImageCss("sig-stamp-box"); expect(css).not.toContain(".seal"); expect(css).toContain(".sig-stamp-box.sig-stamp-box-image"); expect(css).toContain(".sig-stamp-box img"); }); }); });