// Sibling test for c51_render_layout.ts (Layer 1, render). The page // chrome plus the `escape` HTML-escaper. End-to-end coverage at every // route that renders HTML; this sibling pins the pure helpers. import { describe, test, expect } from "bun:test"; import { escape, renderPage, renderNotFound, htmlResponse } from "./b51_render_layout.ts"; describe("c51_render_layout — escape (HTML entity escaping)", () => { test("escapes ampersand, lt, gt, double-quote", () => { expect(escape("&")).toBe("&"); expect(escape("<")).toBe("<"); expect(escape(">")).toBe(">"); expect(escape('"')).toBe("""); }); test("escapes ampersand FIRST so we don't double-escape", () => { // Naive ordering ("<&" → "<&" then & → "<&") would // produce "<&" if the order were wrong. expect(escape("<&>")).toBe("<&>"); }); test("passes plain text through unchanged", () => { expect(escape("hello world")).toBe("hello world"); }); }); describe("c51_render_layout — renderPage", () => { test("renders a complete HTML document with the supplied title", async () => { const html = await renderPage({ title: "Hello", description: "Test page", bodyMarkdown: "# Hi\n\nbody", ogPath: "https://tdd.md/test", }); expect(html).toContain(""); expect(html).toContain("
hi
"); expect(r.status).toBe(200); expect(r.headers.get("content-type")).toMatch(/text\/html/); expect(await r.text()).toBe("hi
"); }); test("htmlResponse honours the optional status arg", () => { const r = htmlResponse("nope
", 404); expect(r.status).toBe(404); }); });