Files
Alfred/tests/web/routes/projects.test.tsx
lanyuanxiaoyao b5301ec7d1 refactor: 前端 antd 组件使用最佳实践重构
- 修正 API 响应类型,增加 ProjectResponse 包装类型
- ConfigProvider 配置中文 locale (zhCN)
- 生产入口启用 ErrorBoundary,使用 Result 组件
- ReactQueryDevtools 仅开发环境渲染
- Sider 增加 collapsible 配置,使用 antd 默认折叠行为
- 项目页面拆分为 ProjectToolbar/ProjectTable/ProjectFormModal
- 搜索改用 Input.Search,表单增加 whitespace 校验
- 404/ErrorBoundary/Dashboard 使用 antd Result/Typography/Card/Descriptions
- 清理未使用的 ProtectedRoute 和冗余样式类
- styles.css 仅保留必要布局样式,无 antd 内部类覆盖
- 更新测试覆盖,避免依赖 antd 内部类名
- 更新 docs/development/frontend.md 开发规范
2026-05-28 16:09:01 +08:00

40 lines
1.2 KiB
TypeScript

import { fireEvent, screen, waitFor } from "@testing-library/react";
import { describe, expect, test } from "bun:test";
import { createElement } from "react";
import { ProjectsPage } from "../../../src/web/pages/projects";
import { renderWithProviders } from "../test-utils";
describe("ProjectsPage", () => {
test("渲染 Tab、搜索框、新建按钮和表格", async () => {
renderWithProviders(createElement(ProjectsPage));
expect(screen.getByText("进行中")).not.toBeNull();
expect(screen.getByText("已归档")).not.toBeNull();
expect(screen.getByText("新建项目")).not.toBeNull();
expect(screen.getByPlaceholderText("搜索项目名称或描述")).not.toBeNull();
await waitFor(
() => {
const body = document.body.textContent ?? "";
expect(body).toContain("项目名称");
},
{ timeout: 10000 },
);
});
test("新建按钮点击打开弹窗", async () => {
renderWithProviders(createElement(ProjectsPage));
const createBtn = screen.getByRole("button", { name: /新建项目/ });
fireEvent.click(createBtn);
await waitFor(
() => {
expect(document.body.querySelector(".ant-modal")).not.toBeNull();
},
{ timeout: 10000 },
);
});
});