Files
Alfred/tests/web/components/Sidebar/index.test.tsx

41 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import { fireEvent, screen } from "@testing-library/react";
import { createElement } from "react";
import { useLocation } from "react-router";
import { ADMIN_MENU_ITEMS } from "../../../../src/web/layouts/admin-layout/menu";
import { Sidebar } from "../../../../src/web/shared/components/Sidebar";
import { renderWithProviders } from "../../test-utils";
function LocationProbe() {
const location = useLocation();
return <span>{location.pathname}</span>;
}
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("div", null, createElement(Sidebar, { menuItems: ADMIN_MENU_ITEMS }), createElement(LocationProbe)),
);
fireEvent.click(screen.getByText("项目管理"));
expect(screen.getByText("当前路径:/projects")).not.toBeNull();
});
test("当前路由仍展示对应菜单项", () => {
renderWithProviders(createElement(Sidebar, { menuItems: ADMIN_MENU_ITEMS }), {
initialRoute: "/",
});
expect(screen.getByText("总览")).not.toBeNull();
});
});