import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import JSZip from "jszip"; import { patchDetector } from "./patch-detector"; const MOCK_XML = ` Hello World Hello {{name}}, how are you? {{paragraph_replace}} {{table}} {{table_heading_1}} Item: {{item_1}} {{image_test}} Thank you `; // cspell:disable const MOCK_XML_2 = ` {{ s chool_ n ame}} {{ a ddr ess }} {{ `; // cspell:enable describe("patch-detector", () => { describe("patchDetector", () => { describe("document.xml and [Content_Types].xml", () => { beforeEach(() => { vi.spyOn(JSZip, "loadAsync").mockReturnValue( new Promise((resolve) => { const zip = new JSZip(); zip.file("word/document.xml", MOCK_XML); zip.file("[Content_Types].xml", ``); resolve(zip); }), ); }); afterEach(() => { vi.restoreAllMocks(); }); it("should patch the document", async () => { const output = await patchDetector({ data: Buffer.from(""), }); expect(output).toMatchObject(["name", "paragraph_replace", "table", "image_test", "table_heading_1", "item_1"]); }); }); }); describe("patchDetector", () => { describe("document.xml and [Content_Types].xml", () => { beforeEach(() => { vi.spyOn(JSZip, "loadAsync").mockReturnValue( new Promise((resolve) => { const zip = new JSZip(); zip.file("word/document.xml", MOCK_XML_2); zip.file("[Content_Types].xml", ``); resolve(zip); }), ); }); afterEach(() => { vi.restoreAllMocks(); }); it("should patch the document", async () => { const output = await patchDetector({ data: Buffer.from(""), }); expect(output).toMatchObject(["school_name", "address"]); }); }); }); });