import { createDocumentFragmentFromContent, htmlJoin, htmlReplace, htmlTrim, } from "@mail/utils/common/html"; import { describe, expect, test } from "@odoo/hoot"; import { markup } from "@odoo/owl"; const Markup = markup().constructor; describe.current.tags("headless"); test("createDocumentFragmentFromContent escapes text", () => { const doc = createDocumentFragmentFromContent("
test
"); expect(doc.body.innerHTML).toEqual("<p>test</p>"); }); test("createDocumentFragmentFromContent keeps html markup", () => { const doc = createDocumentFragmentFromContent(markup("test
")); expect(doc.body.innerHTML).toEqual("test
"); }); test("htmlJoin keeps html markup and escapes text", () => { const res = htmlJoin(markup("test
"), "test
"); expect(res.toString()).toBe("test
<p>test</p>"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with text/text/text replaces with escaped text", () => { const res = htmlReplace("test
", "test
", "test"); expect(res.toString()).toBe("<span>test</span>"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with text/text/html replaces with html markup", () => { const res = htmlReplace("test
", "test
", markup("test")); expect(res.toString()).toBe("test"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with text/html does not find", () => { const res = htmlReplace("test
", markup("test
"), "never found"); expect(res.toString()).toBe("<p>test</p>"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with html/html/html replaces with html markup", () => { const res = htmlReplace( markup("test
"), markup("test
"), markup("test") ); expect(res.toString()).toBe("test"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with html/html/text replaces with escaped text", () => { const res = htmlReplace(markup("test
"), markup("test
"), "test"); expect(res.toString()).toBe("<span>test</span>"); expect(res).toBeInstanceOf(Markup); }); test("htmlReplace with html/text does not find", () => { const res = htmlReplace(markup("test
"), "test
", "never found"); expect(res.toString()).toBe("test
"); expect(res).toBeInstanceOf(Markup); }); test("htmlTrim escapes text", () => { const res = htmlTrim("test
"); expect(res.toString()).toBe("<p>test</p>"); expect(res).toBeInstanceOf(Markup); }); test("htmlTrim keeps html markup", () => { const res = htmlTrim(markup("test
")); expect(res.toString()).toBe("test
"); expect(res).toBeInstanceOf(Markup); });