testCollectionsOfMdxPages
tcmts.content.test.testCollectionsOfMdxPages · #432jmtfr · function
import { collection } from "#codebase/tcmts/content";
import type { StandardSchema } from "#codebase/tcmts/content";
import { expect } from "vitest";
export const testCollectionsOfMdxPages = () => {
const schema: StandardSchema<{ title: string }> = {
"~standard": {
version: 1,
vendor: "test",
validate: (v) => {
const o = (v ?? {}) as { title?: unknown };
return typeof o.title === "string"
? { value: { title: o.title } }
: { issues: [{ message: "a title" }] };
},
},
};
// a page, as a namespace of files holds it: its component, with its text
const hello = Object.assign((_props: { components?: object }) => "rendered", {
text: "---\ntitle: Hello\n---\n\n# Hi\n",
});
const pages = collection({ hello }, { schema });
const entry = pages.get("hello")!;
expect(entry.data.title).toBe("Hello");
expect(entry.body).toBe("# Hi\n");
expect(entry.Content).toBe(hello);
expect(entry.Content({})).toBe("rendered");
expect(pages.check("hello", "---\ntitle: 3\n---\n")).toEqual(["a title"]);
// Markdown files have none
expect(collection({ a: "---\ntitle: A\n---\n" }, { schema }).get("a")!.Content).toBeUndefined();
}
uses