import { describe, it, expect } from "vitest";
import { NAV_ITEMS } from "./index";

/**
 * Nav gating contract (#299). Locks in the /review-spec CRITICAL caveat:
 * the `reports` nav item points to the FREE hub (/reports, not route-gated)
 * and must NEVER carry a `feature` — gating it would show a lock over a
 * fully functional free page.
 */
describe("NAV_ITEMS feature gating", () => {
  const byKey = Object.fromEntries(NAV_ITEMS.map((item) => [item.key, item]));

  it("gates budget, adjustments and balance with their matching feature key", () => {
    expect(byKey.budget.feature).toBe("budget");
    expect(byKey.adjustments.feature).toBe("adjustments");
    expect(byKey.balance.feature).toBe("balance");
  });

  it("never gates the reports hub nav item nor any Free module", () => {
    expect(byKey.reports.feature).toBeUndefined();
    expect(byKey.dashboard.feature).toBeUndefined();
    expect(byKey.import.feature).toBeUndefined();
    expect(byKey.transactions.feature).toBeUndefined();
    expect(byKey.categories.feature).toBeUndefined();
    expect(byKey.settings.feature).toBeUndefined();
  });

  it("gates exactly 3 of the 9 nav items", () => {
    const gated = NAV_ITEMS.filter((item) => item.feature !== undefined);
    expect(NAV_ITEMS).toHaveLength(9);
    expect(gated.map((item) => item.key).sort()).toEqual([
      "adjustments",
      "balance",
      "budget",
    ]);
  });
});
