- 新增 materials 表(id/projectId/description/associatedDate/status/createdAt/updatedAt) - 新增 4 个后端 API 路由(list/create/get/delete)+ 13 个测试 - 新增 use-materials hooks(TanStack Query) - 收集箱页面重构为三层架构(InboxPage + MaterialSidebar + MaterialDetailPanel) - MaterialCard: Popconfirm 删除确认 + 粗粒度时间格式 - MaterialContent: 展示状态标签 + createdAt - 更新开发文档 backend.md / frontend.md
91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
import { screen } from "@testing-library/react";
|
|
import { describe, expect, test, vi } from "bun:test";
|
|
import { createElement } from "react";
|
|
|
|
import type { Material } from "../../../../src/shared/api";
|
|
|
|
import { MaterialList } from "../../../../src/web/features/inbox/components/MaterialList";
|
|
import { renderWithProviders } from "../../test-utils";
|
|
|
|
const MOCK_MATERIALS: Material[] = [
|
|
{
|
|
associatedDate: "2026-06-03",
|
|
createdAt: "2026-06-03T00:00:00.000Z",
|
|
description: "素材一",
|
|
id: "id-1",
|
|
projectId: "project-1",
|
|
status: "pending",
|
|
updatedAt: "2026-06-03T00:00:00.000Z",
|
|
},
|
|
{
|
|
associatedDate: "2026-06-02",
|
|
createdAt: "2026-06-02T00:00:00.000Z",
|
|
description: "素材二",
|
|
id: "id-2",
|
|
projectId: "project-1",
|
|
status: "pending",
|
|
updatedAt: "2026-06-02T00:00:00.000Z",
|
|
},
|
|
];
|
|
|
|
describe("MaterialList", () => {
|
|
test("列表为空时显示暂无素材", () => {
|
|
renderWithProviders(
|
|
createElement(MaterialList, {
|
|
loading: false,
|
|
materials: [],
|
|
onAddClick: vi.fn(),
|
|
onDelete: vi.fn(),
|
|
onSelect: vi.fn(),
|
|
selectedId: null,
|
|
}),
|
|
);
|
|
expect(screen.getByText("暂无素材")).not.toBeNull();
|
|
});
|
|
|
|
test("渲染素材卡片列表", () => {
|
|
renderWithProviders(
|
|
createElement(MaterialList, {
|
|
loading: false,
|
|
materials: MOCK_MATERIALS,
|
|
onAddClick: vi.fn(),
|
|
onDelete: vi.fn(),
|
|
onSelect: vi.fn(),
|
|
selectedId: null,
|
|
}),
|
|
);
|
|
expect(screen.getByText("素材一")).not.toBeNull();
|
|
expect(screen.getByText("素材二")).not.toBeNull();
|
|
});
|
|
|
|
test("点击新增素材按钮触发 onAddClick", () => {
|
|
const onAddClick = vi.fn();
|
|
renderWithProviders(
|
|
createElement(MaterialList, {
|
|
loading: false,
|
|
materials: [],
|
|
onAddClick,
|
|
onDelete: vi.fn(),
|
|
onSelect: vi.fn(),
|
|
selectedId: null,
|
|
}),
|
|
);
|
|
screen.getByText("新增素材").click();
|
|
expect(onAddClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test("加载中显示 Spin", () => {
|
|
renderWithProviders(
|
|
createElement(MaterialList, {
|
|
loading: true,
|
|
materials: [],
|
|
onAddClick: vi.fn(),
|
|
onDelete: vi.fn(),
|
|
onSelect: vi.fn(),
|
|
selectedId: null,
|
|
}),
|
|
);
|
|
expect(document.querySelector(".ant-spin")).not.toBeNull();
|
|
});
|
|
});
|