import { screen } from "@testing-library/react";
import { describe, expect, test } from "bun:test";
import { createElement } from "react";

import { Sidebar } from "../../../../src/web/components/Sidebar";
import { ADMIN_MENU_ITEMS } from "../../../../src/web/consoles/admin/menu";
import { renderWithProviders } from "../../test-utils";

describe("Sidebar", () => {
  test("渲染 Admin 菜单项", () => {
    renderWithProviders(createElement(Sidebar, { menuItems: ADMIN_MENU_ITEMS }));

    expect(screen.getByText("总览")).not.toBeNull();
    expect(screen.getByText("项目管理")).not.toBeNull();
  });

  test("项目管理菜单项可导航到 /projects", () => {
    renderWithProviders(createElement(Sidebar, { menuItems: ADMIN_MENU_ITEMS }), {
      initialRoute: "/projects",
    });

    const activeItem = document.querySelector(".ant-menu-item-selected");
    expect(activeItem).not.toBeNull();
    expect(activeItem?.textContent).toContain("项目管理");
  });

  test("高亮当前路由对应的总览菜单项", () => {
    renderWithProviders(createElement(Sidebar, { menuItems: ADMIN_MENU_ITEMS }), {
      initialRoute: "/",
    });

    const activeItem = document.querySelector(".ant-menu-item-selected");
    expect(activeItem).not.toBeNull();
    expect(activeItem?.textContent).toContain("总览");
  });
});
