import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { getDashboardNavItems, getActiveNavItem } from "@/components/agnet/layout/dashboard-nav";

vi.mock("next/navigation", () => ({
  usePathname: () => "/farmers/dashboard/finance",
}));

describe("dashboard-nav", () => {
  it("returns five nav items with stable ids", () => {
    const items = getDashboardNavItems("en");
    expect(items).toHaveLength(5);
    expect(items.map((item) => item.id)).toEqual([
      "overview",
      "finance",
      "trade",
      "identity",
      "inputs",
    ]);
  });

  it("resolves active item from pathname", () => {
    const items = getDashboardNavItems("en");
    const active = getActiveNavItem("/farmers/dashboard/identity", items);
    expect(active.id).toBe("identity");
    expect(active.moduleTitle).toBe("AGNET Identity");
  });
});

describe("DashboardSidebar", () => {
  it("renders nav links with data-testid attributes", async () => {
    const { default: DashboardSidebar } = await import(
      "@/components/agnet/layout/DashboardSidebar"
    );
    const items = getDashboardNavItems("en");

    render(<DashboardSidebar items={items} />);

    expect(screen.getByTestId("dashboard-sidebar")).toBeInTheDocument();
    expect(screen.getByTestId("dashboard-nav-finance")).toBeInTheDocument();
    expect(screen.getByTestId("dashboard-nav-identity")).toHaveAttribute(
      "href",
      "/farmers/dashboard/identity",
    );
  });
});
