Skip to content

Build your personal knowledge base with Trilium Notes

test(client): cover the element-like inputs SanitizedHtml now takes

Claude2b9c2976dd19
diff --git a/apps/client/src/widgets/react/RawHtml.spec.tsx b/apps/client/src/widgets/react/RawHtml.spec.tsx
index 0e905c9e5d..1d93c16e2c 100644
--- a/apps/client/src/widgets/react/RawHtml.spec.tsx
+++ b/apps/client/src/widgets/react/RawHtml.spec.tsx
@@ -2,7 +2,7 @@ import { render } from "preact";
import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
-import RawHtml, { HighlightedText, RawHtmlBlock } from "./RawHtml";
+import RawHtml, { getHtml, HighlightedText, RawHtmlBlock, SanitizedHtml } from "./RawHtml";
let container: HTMLDivElement;
@@ -49,6 +49,27 @@ describe("RawHtml", () => {
});
});
+describe("element-like input", () => {
+ it("reads a string, an element or a jQuery wrapper as the same markup", () => {
+ const element = document.createElement("b");
+ element.textContent = "bold";
+
+ for (const html of [ "<b>bold</b>", element, $(element) ]) {
+ expect(getHtml(html).__html).toBe("<b>bold</b>");
+
+ // Text rather than markup: happy-dom's traversal drops elements under DOMPurify (see
+ // confirm.spec.tsx, which checks the sanitizing under jsdom).
+ render(<SanitizedHtml className="message" html={html} />, container);
+ expect(container.querySelector(".message")?.textContent).toBe("bold");
+ }
+
+ render(<SanitizedHtml className="message" />, container);
+ const empty = container.querySelector(".message");
+ expect(empty).not.toBeNull();
+ expect(empty?.textContent).toBe("");
+ });
+});
+
describe("HighlightedText", () => {
it("renders the text as text, never as markup", () => {
act(() => render(