// @vitest-environment happy-dom import { describe, expect, it } from "vitest"; import { htmlToParagraphs } from "./html-to-docx"; describe("htmlToParagraphs", () => { it("returns [] for empty / whitespace-only input", () => { expect(htmlToParagraphs("")).toEqual([]); expect(htmlToParagraphs(" \n ")).toEqual([]); }); it("returns at least one paragraph for a simple

element", () => { const result = htmlToParagraphs("

Hello world

"); expect(result.length).toBeGreaterThanOrEqual(1); }); it("converts plain text nodes at the body root into a paragraph", () => { const result = htmlToParagraphs("Just some plain text"); expect(result.length).toBe(1); }); it("emits separate paragraphs for multiple top-level blocks", () => { const result = htmlToParagraphs("

One

Two

Three

"); expect(result.length).toBeGreaterThanOrEqual(3); }); it("treats

..

as block-level paragraphs (one per heading)", () => { const result = htmlToParagraphs("

A

B

C

"); expect(result.length).toBe(3); }); it("renders nested , , , inline styling without throwing", () => { const result = htmlToParagraphs("

Bold italic under strike

"); expect(result.length).toBe(1); }); it("renders links and lists without throwing", () => { const html = '

link

  • One
  • Two
'; const result = htmlToParagraphs(html); expect(result.length).toBeGreaterThanOrEqual(2); }); it("accepts custom font + size config without throwing", () => { const result = htmlToParagraphs("

Hello

", { font: "Roboto", size: 22, color: "111111", linkColor: "0563C1", }); expect(result.length).toBe(1); }); it("ignores HTML comments and script/style tags at the root", () => { // Comments at root and script tags don't add paragraph output. const result = htmlToParagraphs("

Hello

"); expect(result.length).toBeGreaterThanOrEqual(1); }); it("applies default yellow shading for without background-color", () => { const result = htmlToParagraphs("

highlighted

"); const json = JSON.stringify(result[0]); // TextRun with shading should contain "FFFF00" in serialized output expect(json).toContain("FFFF00"); }); it("reads custom background-color from style for shading fill", () => { const result = htmlToParagraphs('

green

'); const json = JSON.stringify(result[0]); expect(json).toContain("CCFFCC"); }); });