37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { slugify, deriveSlug, deriveDate, pageFilename } from "./slug";
|
|
|
|
describe("slugify", () => {
|
|
test("lowercases, drops apostrophes, hyphenates", () => {
|
|
expect(slugify("On Making a Game")).toBe("on-making-a-game");
|
|
expect(slugify("It's a Test!")).toBe("its-a-test");
|
|
expect(slugify(" Spaced out ")).toBe("spaced-out");
|
|
});
|
|
});
|
|
|
|
describe("deriveSlug", () => {
|
|
test("prefers title, falls back to filename", () => {
|
|
expect(deriveSlug({ title: "Hello World", filename: "note" })).toBe("hello-world");
|
|
expect(deriveSlug({ title: " ", filename: "My Note" })).toBe("my-note");
|
|
});
|
|
});
|
|
|
|
describe("deriveDate", () => {
|
|
const now = new Date("2026-06-19T12:00:00Z");
|
|
test("uses frontmatter Date or string, else now", () => {
|
|
expect(deriveDate({ frontmatterDate: new Date("2026-02-06T00:00:00Z"), })).toBe("2026-02-06");
|
|
expect(deriveDate({ frontmatterDate: "2026-02-18 09:00" })).toBe("2026-02-18");
|
|
expect(deriveDate({ frontmatterDate: "unparsable" })).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("postFilename", () => {
|
|
test("joins date and slug", () => {
|
|
expect(pageFilename({ date: "2026-06-19", slug: "hello" })).toBe("2026-06-19-hello.md");
|
|
});
|
|
|
|
test("renders correctly without date", () => {
|
|
expect(pageFilename({ slug: "hello-without-date" })).toBe("hello-without-date.md");
|
|
});
|
|
});
|