/** RFC-0022 §3: `Chart` drawn as SVG on the server, with a legend and its numbers as a table. */ import { createHash } from "node:crypto"; import type { SurfaceSection } from "@cloudhal/core-contracts"; import { checkSurface, createCatalog } from "@cloudhal/core-ts/surfaces"; import { describe, expect, it } from "vitest"; import { CHART_SCRIPT, chartInner } from "../src/chart.ts"; import { renderSurface } from "../src/surfaces.ts"; const months = [ { month: "Jan", readers: 1200, subscribers: 300 }, { month: "Feb", readers: 1850, subscribers: 410 }, { month: "Mar", readers: 2400, subscribers: 520 }, ]; const labels = { data: "Show the data" }; const spec = (extra: Record = {}) => ({ kind: "bar", title: "Readers", data: months, x: "month", series: [ { field: "readers", label: "Readers" }, { field: "subscribers", label: "Subscribers" }, ], ...extra, }); describe("Chart", () => { it("draws grouped bars on nice ticks, with a legend and a data table", () => { const html = chartInner(spec(), "en", labels); expect(html.match(/3,000"); expect(html).toContain("Feb, Readers: 1,850"); expect(html).toContain('