import { describe, expect, it } from "vitest"; import type { ReviewHistoryItem } from "@/lib/api/types"; import { latestReview, normalizeConflicts } from "./history"; const item = ( conflicts: Record[], ): ReviewHistoryItem => ({ id: "00000000-0000-0000-0000-000000000001", project_id: "00000000-0000-0000-0000-000000000002", chapter_no: 128, conflicts, }); describe("normalizeConflicts", () => { it("tightens loose dicts into ReviewConflict, preserving order", () => { const out = normalizeConflicts( item([ { type: "设定违例", where: "第4段", refs: ["第30章"], suggestion: "统一血脉", }, { type: "时间线倒错", where: "第8段", refs: [], suggestion: "调整" }, ]), ); expect(out).toEqual([ { type: "设定违例", where: "第4段", refs: ["第30章"], suggestion: "统一血脉" }, { type: "时间线倒错", where: "第8段", refs: [], suggestion: "调整" }, ]); }); it("fills safe defaults for missing/wrong-typed fields", () => { const out = normalizeConflicts(item([{ where: 42, refs: "x" }])); expect(out).toEqual([ { type: "未分类", where: "", refs: [], suggestion: "" }, ]); }); it("returns [] for undefined item or missing conflicts", () => { expect(normalizeConflicts(undefined)).toEqual([]); }); }); describe("latestReview", () => { it("returns first item (history is newest-first)", () => { const a = item([]); const b = item([]); expect(latestReview([a, b])).toBe(a); expect(latestReview([])).toBeUndefined(); expect(latestReview(undefined)).toBeUndefined(); }); });