feat(inbox): 素材持久化 CRUD — 数据库表 + API + 前端接入
- 新增 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
This commit is contained in:
@@ -2,7 +2,7 @@ import { screen } from "@testing-library/react";
|
||||
import { describe, expect, test, vi } from "bun:test";
|
||||
import { createElement } from "react";
|
||||
|
||||
import type { Material } from "../../../../src/web/features/inbox/types";
|
||||
import type { Material } from "../../../../src/shared/api";
|
||||
|
||||
import { MaterialList } from "../../../../src/web/features/inbox/components/MaterialList";
|
||||
import { renderWithProviders } from "../../test-utils";
|
||||
@@ -10,15 +10,21 @@ import { renderWithProviders } from "../../test-utils";
|
||||
const MOCK_MATERIALS: Material[] = [
|
||||
{
|
||||
associatedDate: "2026-06-03",
|
||||
createdAt: new Date().toISOString(),
|
||||
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: new Date().toISOString(),
|
||||
createdAt: "2026-06-02T00:00:00.000Z",
|
||||
description: "素材二",
|
||||
id: "id-2",
|
||||
projectId: "project-1",
|
||||
status: "pending",
|
||||
updatedAt: "2026-06-02T00:00:00.000Z",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -26,6 +32,7 @@ describe("MaterialList", () => {
|
||||
test("列表为空时显示暂无素材", () => {
|
||||
renderWithProviders(
|
||||
createElement(MaterialList, {
|
||||
loading: false,
|
||||
materials: [],
|
||||
onAddClick: vi.fn(),
|
||||
onDelete: vi.fn(),
|
||||
@@ -39,6 +46,7 @@ describe("MaterialList", () => {
|
||||
test("渲染素材卡片列表", () => {
|
||||
renderWithProviders(
|
||||
createElement(MaterialList, {
|
||||
loading: false,
|
||||
materials: MOCK_MATERIALS,
|
||||
onAddClick: vi.fn(),
|
||||
onDelete: vi.fn(),
|
||||
@@ -54,6 +62,7 @@ describe("MaterialList", () => {
|
||||
const onAddClick = vi.fn();
|
||||
renderWithProviders(
|
||||
createElement(MaterialList, {
|
||||
loading: false,
|
||||
materials: [],
|
||||
onAddClick,
|
||||
onDelete: vi.fn(),
|
||||
@@ -64,4 +73,18 @@ describe("MaterialList", () => {
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user