import { describe, expect, it } from "vitest";

import { buildAcceptPreview } from "./accept-preview";

describe("buildAcceptPreview", () => {
  it("always previews version promotion, digest, and overdue scan", () => {
    const items = buildAcceptPreview({
      conflictCount: 0,
      foreshadowSuggestions: 0,
    });
    const labels = items.map((it) => it.label);
    expect(labels).toContain("晋升章节版次");
    expect(labels).toContain("提炼章节摘要");
    expect(labels).toContain("扫描伏笔到期");
  });

  it("omits the decisions line when there are no conflicts", () => {
    const items = buildAcceptPreview({
      conflictCount: 0,
      foreshadowSuggestions: 0,
    });
    expect(items.some((it) => it.label === "写回冲突裁决")).toBe(false);
  });

  it("includes the decisions line with the conflict count", () => {
    const items = buildAcceptPreview({
      conflictCount: 3,
      foreshadowSuggestions: 0,
    });
    const decisions = items.find((it) => it.label === "写回冲突裁决");
    expect(decisions?.detail).toContain("3");
  });

  it("reminds about pending foreshadow suggestions only when present", () => {
    expect(
      buildAcceptPreview({
        conflictCount: 0,
        foreshadowSuggestions: 0,
      }).some((it) => it.label === "伏笔建议待登记"),
    ).toBe(false);
    const items = buildAcceptPreview({
      conflictCount: 0,
      foreshadowSuggestions: 2,
    });
    const foreshadow = items.find((it) => it.label === "伏笔建议待登记");
    expect(foreshadow?.detail).toContain("2");
  });
});
