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 { renderWithProviders } from "../../test-utils";

describe("Sidebar", () => {
  test("渲染菜单项", () => {
    renderWithProviders(createElement(Sidebar));

    expect(screen.getByText("仪表盘")).not.toBeNull();
    expect(screen.getByText("项目管理")).not.toBeNull();
  });

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

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

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

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