import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, test, vi } from "vitest";
import { EXTERNAL_CAPABILITIES } from "../config/capabilities.js";
import OverviewPage from "./OverviewPage.jsx";

const authState = vi.hoisted(() => ({
  session: {
    account: "fami-operator",
    appCode: "fami",
    appName: "Fami",
    capabilities: ["user:list"]
  }
}));

vi.mock("../auth/ExternalAuthProvider.jsx", () => ({
  useExternalAuth: () => authState
}));

describe("OverviewPage", () => {
  test("renders all 20 market capability entries and only links enabled entries", () => {
    render(<MemoryRouter><OverviewPage /></MemoryRouter>);

    expect(EXTERNAL_CAPABILITIES).toHaveLength(20);
    expect(screen.getAllByText("Enabled")).toHaveLength(1);
    expect(screen.getAllByText("Not enabled")).toHaveLength(19);
    expect(screen.getByText("User list").closest("a")).toHaveAttribute("href", "/users");
    expect(screen.getByText("Edit user information").closest("a")).toBeNull();
    expect(screen.getByText("My team")).toBeInTheDocument();
  });
});
