recent-notes/test/component.test.ts
saberzero1 2e9753c996
feat: exclude unlisted pages from recent notes
Respect the file.data.unlisted convention. Pages marked unlisted are
filtered out of the recent notes list before any user-supplied opts.filter
runs, so they cannot be accidentally surfaced by a permissive custom
filter.

Extracts the filter into a named filterListedPages() helper and exports
it for reuse and testing. Adds 3 unit tests covering unlisted exclusion,
passthrough when nothing is unlisted, and empty-input handling.
2026-04-11 13:50:16 +02:00

36 lines
1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { RecentNotes, filterListedPages } from "../src/index";
describe("RecentNotes", () => {
it("is exported as a function", () => {
expect(typeof RecentNotes).toBe("function");
});
it("returns a component with css property", () => {
const component = RecentNotes();
expect(typeof component).toBe("function");
expect(typeof component.css).toBe("string");
});
});
describe("filterListedPages", () => {
it("excludes pages marked unlisted: true", () => {
const pages = [
{ slug: "a" },
{ slug: "b", unlisted: true },
{ slug: "c" },
{ slug: "d", unlisted: false },
];
const result = filterListedPages(pages);
expect(result.map((p) => p.slug)).toEqual(["a", "c", "d"]);
});
it("returns pages unchanged when none are unlisted", () => {
const pages = [{ slug: "a" }, { slug: "b" }];
expect(filterListedPages(pages)).toEqual(pages);
});
it("handles empty input", () => {
expect(filterListedPages([])).toEqual([]);
});
});