/**
 * Tests for `stripSectionRefs` — issue #1963 (report microcopy).
 *
 * The §13 score `reason` strings carry internal section refs («§10.4», «§9.6»)
 * that read as jargon to a CFO. The 6.5 transparency block keeps the human text
 * inline and moves the refs into a tooltip-only «детали» string. This helper does
 * the split: clean prose out, refs collected, no orphan punctuation left behind.
 */
import { describe, expect, it } from "vitest";

import { stripSectionRefs } from "../forecast-helpers";

describe("stripSectionRefs — #1963", () => {
  it("removes a trailing parenthetical section ref", () => {
    const { clean, refs } = stripSectionRefs(
      "Коммерческий сигнал §10.4 недоступен (нет данных по нежилому).",
    );
    expect(clean).toBe("Коммерческий сигнал недоступен (нет данных по нежилому).");
    expect(refs).toBe("§10.4");
  });

  it("collects multiple refs and cleans orphan empty parens", () => {
    const { clean, refs } = stripSectionRefs(
      "Прокси платежа ~124 тыс.₽/мес (субсид. ставка, §7.9 — доступность относительная).",
    );
    expect(refs).toBe("§7.9");
    expect(clean).not.toContain("§");
    // No double spaces or dangling «(,» left over.
    expect(clean).not.toMatch(/\s{2,}/);
    expect(clean).not.toContain("( ");
  });

  it("returns null refs when there are none and leaves text intact", () => {
    const reason = "Темп поглощения ~511 ед./мес по локации.";
    const { clean, refs } = stripSectionRefs(reason);
    expect(refs).toBeNull();
    expect(clean).toBe(reason);
  });

  it("handles a bare § ref with no surrounding parens", () => {
    const { clean, refs } = stripSectionRefs("Чувствительность не определена §9.6.");
    expect(refs).toBe("§9.6");
    expect(clean).toBe("Чувствительность не определена.");
  });
});
