0.6 rust重构01
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { DocumentRecord } from "@/lib/documents";
|
||||
import type { WorkspaceSummary } from "@/lib/workspaces";
|
||||
import type { SidebarInitialData } from "@/components/sidebar/types";
|
||||
import { buildSidebarInitialData, extractMindmapImageAssetIdsFromData } from "@/lib/sidebar-data";
|
||||
|
||||
describe("extractMindmapImageAssetIdsFromData", () => {
|
||||
it("提取导图节点里的 asset 图片引用并去重", () => {
|
||||
const ids = extractMindmapImageAssetIdsFromData({
|
||||
root: {
|
||||
data: { image: "asset:img_1" },
|
||||
children: [
|
||||
{ image: { url: "asset:img_2" } },
|
||||
{ data: { image: { url: "asset:img_1" } } },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(ids).toEqual(["img_1", "img_2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSidebarInitialData", () => {
|
||||
it("统一组装 mindmap/table/media 相关侧边栏数据", () => {
|
||||
const workspaces: WorkspaceSummary[] = [
|
||||
{
|
||||
id: "ws_1",
|
||||
name: "工作区",
|
||||
type: "personal",
|
||||
iconUrl: null,
|
||||
memberCount: 1,
|
||||
isDefault: true,
|
||||
},
|
||||
];
|
||||
|
||||
const documents: DocumentRecord[] = [
|
||||
{
|
||||
id: "doc_1",
|
||||
workspace_id: "ws_1",
|
||||
title: "页面 1",
|
||||
parent_id: null,
|
||||
sort_order: 1,
|
||||
is_starred: false,
|
||||
access_scope: "private",
|
||||
is_template: false,
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
|
||||
const trashedDocuments: SidebarInitialData["trashedDocuments"] = [];
|
||||
|
||||
const payload = buildSidebarInitialData({
|
||||
activeWorkspaceId: "ws_1",
|
||||
workspaces,
|
||||
documents,
|
||||
trashedDocuments,
|
||||
mediaAssets: [
|
||||
{
|
||||
id: "asset_file_1",
|
||||
workspace_id: "ws_1",
|
||||
document_id: "doc_1",
|
||||
asset_type: "file",
|
||||
file_url: "/file/1",
|
||||
thumbnail_url: null,
|
||||
bucket: null,
|
||||
storage_path: null,
|
||||
file_name: "a.txt",
|
||||
file_size: null,
|
||||
mime_type: "text/plain",
|
||||
ocr_payload: undefined,
|
||||
ocr_strategy: null,
|
||||
ocr_text: null,
|
||||
ocr_status: null,
|
||||
signed_url: null,
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: "2026-04-14T00:00:00Z",
|
||||
},
|
||||
],
|
||||
trashedMediaAssets: [],
|
||||
mindmaps: [
|
||||
{
|
||||
mindmap_id: "mind_1",
|
||||
workspace_id: "ws_1",
|
||||
document_id: "doc_1",
|
||||
data: {
|
||||
root: {
|
||||
data: { image: "asset:img_a" },
|
||||
children: [{ image: { url: "asset:img_b" } }],
|
||||
},
|
||||
},
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: "2026-04-14T00:00:00Z",
|
||||
deleted_at: null,
|
||||
},
|
||||
{
|
||||
mindmap_id: "mind_2",
|
||||
workspace_id: "ws_1",
|
||||
document_id: "doc_1",
|
||||
data: null,
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: "2026-04-14T00:00:00Z",
|
||||
deleted_at: "2026-04-14T01:00:00Z",
|
||||
deleted_by: "user_1",
|
||||
},
|
||||
],
|
||||
tables: [
|
||||
{
|
||||
id: "table_1",
|
||||
workspace_id: "ws_1",
|
||||
document_id: "doc_1",
|
||||
title: "预算",
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: "2026-04-14T00:00:00Z",
|
||||
is_archived: false,
|
||||
},
|
||||
{
|
||||
id: "table_2",
|
||||
workspace_id: "ws_1",
|
||||
document_id: "doc_1",
|
||||
title: "归档表格",
|
||||
created_at: "2026-04-14T00:00:00Z",
|
||||
updated_at: "2026-04-14T00:00:00Z",
|
||||
deleted_at: "2026-04-14T01:00:00Z",
|
||||
deleted_by: "user_1",
|
||||
purged_at: null,
|
||||
is_archived: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(payload.activeWorkspaceId).toBe("ws_1");
|
||||
expect(payload.mindmapDocs).toEqual(["doc_1"]);
|
||||
expect(payload.mindmapAssetChildren).toEqual({
|
||||
mind_1: ["img_a", "img_b"],
|
||||
});
|
||||
expect(payload.mindmapAssets?.map((item) => item.id)).toEqual(["mind_1"]);
|
||||
expect(payload.trashedMindmapAssets?.map((item) => item.id)).toEqual(["mind_2"]);
|
||||
expect(payload.tableAssets?.map((item) => item.file_name)).toEqual(["预算.luckysheet"]);
|
||||
expect(payload.trashedTableAssets?.map((item) => item.id)).toEqual(["table_2"]);
|
||||
expect(payload.mediaAssets?.map((item) => item.id)).toEqual(["asset_file_1"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user