# test.build/core/converters/record.page.converter.test.ts

> 122 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-converters-record-page-converter-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/converters/record.page.converter.test.ts.txt

Listed in [test.build/core/converters](https://banes-lab.com/api/source/testing/test.build/core/converters.md), after [test.build/core/converters/record.converter.test.ts](https://banes-lab.com/source/testing/test.build/core/converters/record.converter.test.ts.md) and before [test.build/core/converters/reference.converter.test.ts](https://banes-lab.com/source/testing/test.build/core/converters/reference.converter.test.ts.md).

## Contained in

- [test.build/core/converters](https://banes-lab.com/anatomy/testing/folder-testing-test-build-core-converters.md)

## Source

```typescript
import type { Identity, Link } from "@banes-lab/build-scripts/types/catalog.types.ts";
import type { RecordData, RecordPageInput } from "@banes-lab/build-scripts/types/record.types.ts";
import { describe, expect, it } from "vitest";
import {
    distinctPages,
    pageLinkOf,
    recordPathOf,
    recordSubjectOf,
} from "@banes-lab/build-scripts/core/converters/record.page.converter.ts";
import type { ReferenceRecord } from "@banes-lab/web/types/reference.types.js";

const SITE = "https://example.test";

const identity: Identity = {
    address: { json: "/json/records/lexicon/cache", markdown: "/records/lexicon/cache.md" },
    href: "/ontology/lexicon#lexicon-cache",
    kind: "term",
    ref: "lexicon:cache",
    summary: "A store that answers again without the work.",
    title: "Cache",
};

const record: ReferenceRecord = {
    code: null,
    kind: "term",
    layer: null,
    name: "Cache",
    relations: [],
    summary: "A store that answers again without the work.",
};

const linkTo = function linkTo(label: string, id: string): Link {
    return { href: null, json: null, label, markdown: `${SITE}/records/lexicon/${id}.md`, ref: `lexicon:${id}` };
};

const DATA: RecordData = {
    href: `${SITE}/ontology/lexicon#lexicon-cache`,
    kind: "term",
    layer: null,
    name: "Cache",
    ref: "lexicon:cache",
    relations: [],
    siblings: { next: null, previous: linkTo("Buffer", "buffer") },
    summary: "A store that answers again without the work.",
    up: { href: null, json: null, label: "Lexicon records", markdown: null, ref: null },
};

const inputOf = function inputOf(changes: Partial<RecordPageInput>): RecordPageInput {
    return {
        aliases: [],
        data: DATA,
        identity,
        layer: null,
        record,
        relations: [],
        site: SITE,
        tabLabel: () => "Lexicon",
        ...changes,
    };
};

describe("pageLinkOf", () => {
    it("points a record's link at its page, and keeps any other link's href", () => {
        expect(pageLinkOf(SITE, linkTo("Cache", "cache"))).toStrictEqual({ label: "Cache", path: `${SITE}/records/lexicon/cache` });
        const chapter = { href: `${SITE}/pag/guide#a`, json: null, label: "Guide", markdown: `${SITE}/pag/guide/a.md`, ref: null };
        expect(pageLinkOf(SITE, chapter)).toStrictEqual({ label: "Guide", path: `${SITE}/pag/guide#a` });
    });
});

describe("recordPathOf", () => {
    it("takes the page path from the record's Markdown leaf, and refuses an identity with no record leaf", () => {
        expect(recordPathOf(identity)).toBe("/records/lexicon/cache");
        expect(() => recordPathOf({ ...identity, address: { json: "/json/x", markdown: null } })).toThrow("lexicon:cache");
    });
});

describe("recordSubjectOf", () => {
    it("builds the page subject with its collection tab, title, alternates, relations, facts and placement", () => {
        const principle = { ...DATA, closure: `${SITE}/json/records/lexicon/cache/closure`, severity: "mandatory" };
        const subject = recordSubjectOf(
            inputOf({
                aliases: ["store"],
                data: principle,
                relations: [{ links: [], relation: "requires" }],
                tabLabel: (path) => (path === "/ontology/lexicon" ? "Lexicon" : "?"),
            }),
        );
        expect(subject.collection).toStrictEqual({ label: "Lexicon", path: "/ontology/lexicon" });
        expect(subject.section).toBe("lexicon-cache");
        expect(subject.path).toBe("/records/lexicon/cache");
        expect(subject.alternates.markdown).toBe("/records/lexicon/cache.md");
        expect(subject.title).toBe("Cache — Lexicon — Bane's Lab");
        expect(subject.aliases).toStrictEqual(["store"]);
        expect(subject.relations).toStrictEqual([{ links: [], relation: "requires" }]);
        expect(subject.facts.map((fact) => [fact.label, fact.value.label])).toStrictEqual([
            ["Record", "lexicon:cache"],
            ["Severity", "mandatory"],
            ["Canonical", "Lexicon"],
            ["Closure", "Dependencies in load order"],
        ]);
        expect(subject.placement).toStrictEqual({
            next: null,
            previous: { label: "Buffer", path: `${SITE}/records/lexicon/buffer` },
            up: { label: "Lexicon records", path: null },
        });
    });

    it("describes a record with no summary by its kind and collection, and places none without a listing", () => {
        const subject = recordSubjectOf(
            inputOf({ data: { ...DATA, up: null }, record: { ...record, kind: "anti-pattern", summary: null } }),
        );
        expect(subject.description).toBe("Cache is an anti pattern in the Lexicon collection.");
        expect(subject.placement).toBeNull();
    });
});

describe("distinctPages", () => {
    it("gives a shared title the record's kind and a shared description its kind and collection, and keeps a unique one", () => {
        const subjectOf = (kind: string, summary: string): ReturnType<typeof recordSubjectOf> =>
            recordSubjectOf(inputOf({ record: { ...record, kind, summary }, tabLabel: () => "Reasoning" }));
        const leafOf = (page: ReturnType<typeof recordSubjectOf>) => ({ data: {}, identity, markdown: null, page });
        const [lens, node, alone] = distinctPages([
            leafOf(subjectOf("lens", "How does it act?")),
            leafOf(subjectOf("node", "How does it act?")),
            leafOf({ ...subjectOf("lens", "Unique."), name: "Other", title: "Other — Reasoning — Bane's Lab" }),
        ]);
        expect(lens?.page.title).toBe("Cache — lens — Reasoning — Bane's Lab");
        expect(node?.page.title).toBe("Cache — node — Reasoning — Bane's Lab");
        expect(node?.page.description).toBe("Cache is a node in the Reasoning collection. How does it act?");
        expect(alone?.page.title).toBe("Other — Reasoning — Bane's Lab");
        expect(alone?.page.description).toBe("Unique.");
    });
});
```
