// frontend/tests/Topbar.test.tsx
import { render, screen } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
import { Topbar } from "@/components/Topbar";
import { MAIN } from "@/lib/nav";

vi.mock("next/navigation", () => ({ usePathname: () => "/tasks" }));

describe("Topbar", () => {
  it("모든 메인 내비 항목(nav.ts MAIN)을 렌더한다", () => {
    render(<Topbar />);
    MAIN.forEach((m) => expect(screen.getByText(m.label)).toBeInTheDocument());
  });

  it("현재 경로(/tasks=작업)가 active 클래스 + aria-current=page", () => {
    render(<Topbar />);
    const active = screen.getByRole("link", { name: /작업/ });
    expect(active).toHaveClass("active");
    expect(active).toHaveAttribute("aria-current", "page");
  });

  it("결재함=3, 작업=4, 알림=6 배지가 표시된다", () => {
    render(<Topbar />);
    expect(screen.getByText("3")).toBeInTheDocument();
    expect(screen.getByText("4")).toBeInTheDocument();
    expect(screen.getByText("6")).toBeInTheDocument();
  });

  it("브랜드/아바타 텍스트와 우측 액션 aria-label", () => {
    render(<Topbar />);
    expect(screen.getByText("아리")).toBeInTheDocument();
    expect(screen.getByText("AI LIFE OS")).toBeInTheDocument();
    expect(screen.getByText("지")).toBeInTheDocument(); // user.initial
    expect(screen.getByLabelText("검색")).toBeInTheDocument();
    expect(screen.getByLabelText("알림")).toBeInTheDocument();
    expect(screen.getByLabelText("테마 전환")).toBeInTheDocument();
  });
});
