test.build/core/converters/section.page.converter.test.ts
test.build/core/converters/section.page.converter.test.ts is a file in Codebase Testing. 57 lines of code and 0 definitions.
import { describe, expect, it } from "vitest";
import { distinctSections, sectionSubjectOf } from "@banes-lab/build-scripts/core/converters/section.page.converter.ts";
const SEED = {
intro: "The core words.",
kind: null,
name: "Core Vocabulary",
page: "ontology",
part: 1,
parts: 1,
records: 2,
rows: [0, 2] as const,
section: "core-vocabulary",
tab: "principles",
tabPath: "/ontology",
tabTitle: "Principles",
};
describe("sectionSubjectOf", () => {
it("places a section page under its tab and points its alternates at the section leaf of its tab", () => {
const subject = sectionSubjectOf(SEED);
expect(subject.path).toBe("/ontology/principles/core-vocabulary");
expect(subject.alternates).toStrictEqual({
json: "/json/ontology/principles/core-vocabulary",
markdown: "/ontology/principles/core-vocabulary.md",
});
expect(subject.title).toBe("Core Vocabulary — Principles — Bane's Lab");
expect(subject.description).toBe("The 2 records of the Core Vocabulary section in Principles.");
expect(subject.parts).toStrictEqual([{ label: "Part 1 of 1", path: subject.path }]);
});
it("names the section in a title that another page already holds, and keeps the rest plain", () => {
const [held, free] = distinctSections(
[SEED, { ...SEED, name: "Other", section: "other" }],
new Set(["Core Vocabulary — Principles — Bane's Lab"]),
);
expect(held?.title).toBe("Core Vocabulary — section — Principles — Bane's Lab");
expect(free?.title).toBe("Other — Principles — Bane's Lab");
const [keywords, productions] = distinctSections(
[
{ ...SEED, kind: "keywords", section: "pag-keywords-flow" },
{ ...SEED, kind: "productions", section: "pag-productions-flow" },
],
new Set(),
);
expect(keywords?.title).toBe("Core Vocabulary — keywords — Principles — Bane's Lab");
expect(productions?.title).toBe("Core Vocabulary — productions — Principles — Bane's Lab");
});
it("numbers a later part of a section in its path, title and description, and links every part", () => {
const subject = sectionSubjectOf({ ...SEED, part: 2, parts: 3, rows: [1, 2] });
expect(subject.path).toBe("/ontology/principles/core-vocabulary~2");
expect(subject.title).toBe("Part 2 of 3 — Core Vocabulary — Principles — Bane's Lab");
expect(subject.description.startsWith("Part 2 of 3")).toBe(true);
expect(subject.parts.map((link) => link.path)).toStrictEqual([
"/ontology/principles/core-vocabulary",
"/ontology/principles/core-vocabulary~2",
"/ontology/principles/core-vocabulary~3",
]);
});
});