map.test.ts

1.6 kB · typescript · 34 lines

1import { expect, test } from "bun:test";2import type { Site } from "../kit/ssg/build.ts";3import { sections, type Lists } from "./map.ts";45/* SITE */67const site = {8  root: "/repo/site",9  config: { git: { root: ".." } },10  routes: [{ route: "/git/research/wiki/a.md", urls: [{ route: "/git/research/wiki/a.md" }, { route: "/raw/research/wiki/a.md" }] }],11} as unknown as Site;1213const lists = (some: Partial<Lists>): Lists => ({ wiki: [], notes: [], claims: [], papers: [], lanes: [], posts: [], math: [], pages: [], ...some });1415const rows = (all: Lists, name: string) => sections(site, all).find((one) => one.name === name)!.rows;1617/* ROWS */1819test("a served source links its raw path and an unserved one its page", () => {20  const wiki = [21    { name: "A", lead: "first", file: "/repo/research/wiki/a.md", href: "/research/wiki/a/" },22    { name: "B", lead: "second", file: "/repo/research/wiki/b.md", href: "/research/wiki/b/" },23  ];24  expect(rows(lists({ wiki }), "Wiki, in prerequisite order")).toEqual([25    { name: "A", note: "first", href: "/raw/research/wiki/a.md" },26    { name: "B", note: "second", href: "/research/wiki/b/" },27  ]);28});2930test("a claim file is one row with its claim count and its newest date", () => {31  const md = "# C\n\n- 2026-01-02 [Proved] one\n- 2026-03-04 [Conjecture] two\n- 2026-02-03 [Verified] three\n";32  const claims = [{ title: "C", md, file: "/repo/research/claims/c.md", href: "/research/claims/c/" }];33  expect(rows(lists({ claims }), "Claims")).toEqual([{ name: "C", note: "3 claims, newest 2026-03-04", href: "/research/claims/c/" }]);34});