- 抽取 ConsoleShell 共享外壳(Layout/Header/Sider/主题切换/侧边栏折叠) - Sidebar 纯化为接受 menuItems prop 的展示组件 - Admin 管理台:/ 总览 + /projects 项目管理 - Workbench 工作台:/workbench/:projectId 项目作用域 - WorkbenchProjectGate 入口守卫(loading/error/archived/不存在拦截) - ProjectContext 提供当前项目上下文 - 项目管理表格 active 行增加'进入工作台'按钮 - 项目名称 trim 后最多 10 字符(前后端一致) - Workbench 总览页展示项目 Descriptions - Header 区分:管理台显示副标题,工作台显示项目名 + 返回管理台按钮 - 28/28 前端测试通过 - 文档更新:frontend.md ConsoleShell 规范、usage.md 双入口说明
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { screen } from "@testing-library/react";
|
|
import { describe, expect, test } from "bun:test";
|
|
import { createElement } from "react";
|
|
|
|
import { APP } from "../../src/shared/app";
|
|
import { App } from "../../src/web/app";
|
|
import { renderWithProviders } from "./test-utils";
|
|
|
|
describe("App", () => {
|
|
test("渲染 Layout 骨架和品牌名", () => {
|
|
window.fetch = (() => {
|
|
return new Response(
|
|
JSON.stringify({ ok: true, service: "test-app", timestamp: new Date().toISOString(), version: "0.1.0" }),
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
status: 200,
|
|
},
|
|
);
|
|
}) as unknown as typeof fetch;
|
|
|
|
renderWithProviders(createElement(App));
|
|
|
|
expect(screen.getByText(APP.title)).not.toBeNull();
|
|
expect(screen.getByText("系统")).not.toBeNull();
|
|
expect(screen.getByText("明亮")).not.toBeNull();
|
|
expect(screen.getByText("黑暗")).not.toBeNull();
|
|
});
|
|
|
|
test("渲染 Admin 侧边栏菜单项", () => {
|
|
window.fetch = (() => {
|
|
return new Response(
|
|
JSON.stringify({ ok: true, service: "test-app", timestamp: new Date().toISOString(), version: "0.1.0" }),
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
status: 200,
|
|
},
|
|
);
|
|
}) as unknown as typeof fetch;
|
|
|
|
renderWithProviders(createElement(App));
|
|
|
|
expect(screen.getAllByText("总览").length).toBeGreaterThan(0);
|
|
expect(screen.getAllByText("项目管理").length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("Sider 渲染侧边栏菜单", () => {
|
|
window.fetch = (() => {
|
|
return new Response(
|
|
JSON.stringify({ ok: true, service: "test-app", timestamp: new Date().toISOString(), version: "0.1.0" }),
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
status: 200,
|
|
},
|
|
);
|
|
}) as unknown as typeof fetch;
|
|
|
|
renderWithProviders(createElement(App));
|
|
|
|
const sider = document.querySelector(".ant-layout-sider");
|
|
expect(sider).not.toBeNull();
|
|
const menu = document.querySelector(".ant-menu");
|
|
expect(menu).not.toBeNull();
|
|
});
|
|
|
|
test("Admin header 显示管理台标题", () => {
|
|
window.fetch = (() => {
|
|
return new Response(
|
|
JSON.stringify({ ok: true, service: "test-app", timestamp: new Date().toISOString(), version: "0.1.0" }),
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
status: 200,
|
|
},
|
|
);
|
|
}) as unknown as typeof fetch;
|
|
|
|
renderWithProviders(createElement(App));
|
|
|
|
expect(screen.getByText("管理台")).not.toBeNull();
|
|
});
|
|
});
|