import { describe, expect, it } from "vitest";
import { primaryNav } from "./nav";
import { normalizeAppPath, pageHelpKeys, resolvePageHelpId } from "./pageHelp";

describe("pageHelp", () => {
  it("resolves longest prefix routes", () => {
    expect(resolvePageHelpId("/app/radar/watches")).toBe("radar_watches");
    expect(resolvePageHelpId("/app/radar/today")).toBe("radar_today");
    expect(resolvePageHelpId("/app/radar")).toBe("radar_today");
    expect(primaryNav.find((item) => item.key === "radar")?.path).toBe("/app/radar/watches");
    expect(resolvePageHelpId("/app/today")).toBe("today");
    expect(resolvePageHelpId("/app/radar/opportunities")).toBe("radar_today");
    expect(resolvePageHelpId("/app/crm/followups")).toBe("crm_followups");
    expect(resolvePageHelpId("/app/crm/stats")).toBe("crm_stats");
    expect(resolvePageHelpId("/app/crm?contact=x")).toBe("crm_board");
    expect(resolvePageHelpId("/app/policy")).toBe("policy");
    expect(resolvePageHelpId("/app/usage/plans")).toBe("usage_plans");
    expect(resolvePageHelpId("/app")).toBe("today");
  });

  it("falls back outside /app", () => {
    expect(resolvePageHelpId("/login")).toBe("generic");
    expect(normalizeAppPath("/app/scout/")).toBe("/app/scout");
  });

  it("builds i18n key namespace", () => {
    const k = pageHelpKeys("radar_today");
    expect(k.title).toBe("help.page.radar_today.title");
    expect(k.steps).toHaveLength(3);
  });
});
