Files
writer-work-flow/apps/web/lib/review/chapterNav.test.ts
2026-06-29 12:06:04 +02:00

46 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { reviewChapterHref, reviewChapterOptions } from "./chapterNav";
import type { ChapterEntry } from "@/lib/workbench/chapter";
describe("reviewChapterHref", () => {
it("builds the review route for a chapter number", () => {
expect(reviewChapterHref("proj-1", 3)).toBe(
"/projects/proj-1/review?chapter=3",
);
});
it("always targets the review page (not write)", () => {
expect(reviewChapterHref("p", 1)).toContain("/review?chapter=1");
});
});
describe("reviewChapterOptions", () => {
const chapters: ChapterEntry[] = [
{ no: 1, title: "开篇" },
{ no: 2 },
{ no: 3, title: "转折" },
];
it("merges outline chapters with the current chapter, sorted ascending", () => {
const opts = reviewChapterOptions(chapters, 2);
expect(opts.map((o) => o.no)).toEqual([1, 2, 3]);
});
it("includes the current chapter even when it is outside the outline", () => {
const opts = reviewChapterOptions(chapters, 9);
expect(opts.map((o) => o.no)).toEqual([1, 2, 3, 9]);
});
it("labels each option with chapter number and optional title", () => {
const opts = reviewChapterOptions(chapters, 1);
expect(opts[0]).toEqual({ no: 1, label: "第 1 章 · 开篇" });
expect(opts[1]).toEqual({ no: 2, label: "第 2 章" });
});
it("returns just the current chapter when there is no outline", () => {
const opts = reviewChapterOptions([], 4);
expect(opts).toEqual([{ no: 4, label: "第 4 章" }]);
});
});