import { createElement } from "react" import { renderToStaticMarkup } from "react-dom/server" import { expect, test } from "vitest" import { HtmlView } from "./HtmlView.tsx" import { toHtmlContent, toSafeHtml, toSafeHtmlColour, } from "./safeHtml.ts" test("the reader renders safe HTML on the server without a DOM or editor runtime", () => { expect(typeof window).toBe("undefined") const html = renderToStaticMarkup( createElement(HtmlView, { label: "Server notes", value: '
Stored & safe
Read', }), ) expect(html).toContain("Stored & safe") expect(html).toContain('role="document"') expect(html).not.toMatch( /onclick|', ), ).toBe( "Keep & read.

')
})
test("retains only document colour and alignment; CSS cannot load resources or escape the surface", () => {
expect(
toSafeHtml(
'Notes
', ), ).toBe( 'Notes
', ) expect( toSafeHtml( 'Notes', ), ).toBe("Notes") expect( toSafeHtmlColour("red;position:fixed"), ).toBeUndefined() expect(toSafeHtmlColour("url(/tracker)")).toBeUndefined() }) test("an HTML5 parse, rather than regex replacement, contains malformed foreign content", () => { const safe = toSafeHtml( '