Files
Alfred/tests/web/components/Sidebar/index.test.tsx
lanyuanxiaoyao b1dec691e9 refactor(web): 前端目录重构 — consoles/pages → layouts/features + shared
- consoles/admin/ → layouts/admin-layout/
- consoles/workbench/ → layouts/workbench-layout/ + features/chat/
- pages/ → features/ (dashboard, models, projects, not-found)
- components/ → shared/components/
- hooks/ → shared/hooks/
- utils/ → shared/utils/
- 更新所有 import 路径 (src/web/ + tests/web/)
- 更新开发文档 (README.md, frontend.md, architecture.md)
2026-06-02 23:17:28 +08:00

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 { fireEvent, screen } from "@testing-library/react";
import { describe, expect, test } from "bun:test";
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();
});
});