/** * Rendering tests: renderTile turns a TileView into markup, shell wraps the grid * in the page. Pure string work — no server, no network, no subprocess. */ import { assert, assertEquals, assertExists, assertStringIncludes, } from "@std/assert"; import type { Status, TileView } from "./types.ts"; import { FAVICON_CRY_AFTER_MS, formatViewerTimes, renderTile, shell, } from "./render.ts"; import { humanSpan, STATUS_DOT } from "./lib.ts"; import { STATUS_EDGE, STATUS_WASH, TEXTURE_ALPHA, TEXTURE_WIDTH, } from "./palette.ts"; import { FAVICON_VERSION } from "./favicon.ts"; import { followUpdates, liveUpdateStream } from "./stream-client.ts"; import { reconcileTiles } from "./tiles-client.ts"; import { TILE_LABEL_RULE } from "./chart-layout.ts"; const TEST_VERSION = "1".repeat(40); function view(over: Partial = {}): TileView { return { status: "good", ...over }; } Deno.test("renderTile: status drives the tile class, the dot color and the headline color", () => { const dots: Record = { good: "green", warn: "amber", bad: "red", unknown: "gray", }; for (const [status, dot] of Object.entries(dots) as [Status, string][]) { const html = renderTile("labs ci", view({ status, value: "passing" })); assertStringIncludes(html, `class="tile ${status}"`); assertStringIncludes(html, ``); assertStringIncludes(html, `

passing

`); } }); Deno.test("renderTile: no href -> a plain div, not a link", () => { const html = renderTile("labs ci", view()); assert(html.startsWith(`
`), html); assert(html.endsWith("
")); assert(!html.includes(" { assertStringIncludes( renderTile("labs ci", view()), `
`, ); assertStringIncludes( renderTile("labs ci duration", view({ href: "/ci" })), ``, ); }); Deno.test("renderTile: an http href is an anchor that opens a new tab; a local one stays in place", () => { const external = renderTile("labs ci", view({ href: "https://github.com/o/r/actions" })); assertStringIncludes( external, ``, ); const local = renderTile("labs ci", view({ href: "/bench" })); assertStringIncludes(local, ``); assert( !local.includes("target="), "a drill-down on this server replaces the page", ); }); Deno.test("renderTile: a link tile whose chart holds links links its text alone", () => { const html = renderTile("labs ci trust", view({ value: "99.0%", href: "/repos?name=labs", hint: "repository ↗", extra: `
`, })); // The tile's link closes before the chart opens, so the chart's link is not // inside another. assertEquals( html, ``, ); const external = renderTile("labs ci trust", view({ href: "https://github.com/o/r", extra: ``, })); assertStringIncludes( external, ``, ); // A chart without links stays inside the tile's link. const plain = renderTile("labs ci duration", view({ href: "/bench", extra: ``, })); assert(plain.startsWith(` { assertStringIncludes( renderTile("labs ci", view(), true), `class="tile good wide"`, ); assertStringIncludes( renderTile("labs ci", view({ href: "/x" }), true), `class="tile good link wide"`, ); assert(!renderTile("labs ci", view()).includes("wide")); }); Deno.test("renderTile: an absent value/sub/hint/aside renders nothing rather than an empty element", () => { const html = renderTile("labs ci", view()); assertEquals( html, `

labs ci

`, ); }); Deno.test("renderTile: label and sub are escaped — a hostile label cannot inject markup", () => { const html = renderTile( ``, view({ sub: `a & b "quoted"