/**
 * Tests for `confidenceBandHalfWidth` — issue #1926 (qualitative confidence band).
 *
 * The §22 forecast payload carries NO numeric quantiles (p25/p75) — only a
 * per-horizon qualitative confidence level. ui-conventions forbids showing a
 * prediction without an interval, so ForecastChart draws a band whose width is
 * derived from the confidence level: LOWER confidence → WIDER band. This pins
 * both the ordering (low > medium > high) and that the half-width stays within
 * the deficit axis span so a low-confidence band can still be clamped to [−1, 1].
 */
import { describe, expect, it } from "vitest";

import {
  CONFIDENCE_BAND_HALFWIDTH,
  confidenceBandHalfWidth,
} from "../forecast-helpers";

describe("confidenceBandHalfWidth — #1926 qualitative band width", () => {
  it("returns the mapped half-width per level", () => {
    expect(confidenceBandHalfWidth("high")).toBe(
      CONFIDENCE_BAND_HALFWIDTH.high,
    );
    expect(confidenceBandHalfWidth("medium")).toBe(
      CONFIDENCE_BAND_HALFWIDTH.medium,
    );
    expect(confidenceBandHalfWidth("low")).toBe(CONFIDENCE_BAND_HALFWIDTH.low);
  });

  it("lower confidence → wider band (low > medium > high)", () => {
    expect(confidenceBandHalfWidth("low")).toBeGreaterThan(
      confidenceBandHalfWidth("medium"),
    );
    expect(confidenceBandHalfWidth("medium")).toBeGreaterThan(
      confidenceBandHalfWidth("high"),
    );
  });

  it("every half-width is positive and fits within the deficit span (< 1)", () => {
    for (const level of ["high", "medium", "low"] as const) {
      const half = confidenceBandHalfWidth(level);
      expect(half).toBeGreaterThan(0);
      expect(half).toBeLessThan(1);
    }
  });
});
