Files
mnote/wolai-frontend/src/lib/documents/page-subtree-response.test.ts
T
lix-2026 e8ba12e461 收口 Rust Web 入口与 AI 写入链
- 将 3000 主入口继续收口到 mnote-web,补齐 /favicon.ico、/api/auth、session alias、AI run 等 Rust Web 路由边界。

- 更新登录页与 Convex Auth 代理,支持测试账号快速登录写入真实 Convex Auth cookie。

- 推进页面设置、Wolai 对齐、Phase 7 AI kernel/CLI-first 设计文档与相关 smoke 脚本。

- 更新 leptos-tiptap 生成资产、mnote-cli/bridge-runtime、前端依赖和 dev/prod 启动脚本。
2026-05-06 21:44:20 +08:00

108 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeDocumentContentResponse } from "@/lib/documents/page-subtree-response";
import type { PageSubtreeProjection } from "@/lib/documents/page-subtree";
describe("page subtree response helpers", () => {
it("保留服务端返回的 pageSubtree", () => {
const serverPageSubtree = {
projectionId: "server_projection",
projection: "page_tree",
rootNodeId: "doc_1",
rootNode: {
id: "doc_1",
parentNodeId: null,
nodeType: "page",
blockId: null,
anchorBlockId: null,
depth: 0,
metadata: {
title: "服务端标题",
textSnippet: null,
blockType: null,
headingLevel: null,
numbering: null,
childCount: 0,
order: 0,
path: ["doc_1"],
},
},
subtree: {
rootNodeId: "doc_1",
nodes: [],
},
outline: [],
evidence: [],
stats: {
blockCount: 0,
headingCount: 0,
evidenceCount: 0,
maxDepth: 0,
},
} satisfies PageSubtreeProjection;
const normalized = normalizeDocumentContentResponse({
documentId: "doc_1",
payload: {
content: null,
revision: 1,
conflictDetectionKey: "doc_1:1",
pageSubtree: serverPageSubtree,
},
});
expect(normalized.pageSubtree).toBe(serverPageSubtree);
});
it("在服务端缺失 pageSubtree 时保留空值", () => {
const normalized = normalizeDocumentContentResponse({
documentId: "doc_1",
title: "测试页面",
payload: {
content: [
{
id: "heading_1",
type: "heading",
props: { level: 1 },
content: [{ type: "text", text: "章节一" }],
},
],
revision: 3,
conflictDetectionKey: "doc_1:3",
},
});
expect(normalized.revision).toBe(3);
expect(normalized.conflictDetectionKey).toBe("doc_1:3");
expect(normalized.pageSubtree).toBeNull();
});
it("兼容 mnote-web transport 返回的 result 包装", () => {
const normalized = normalizeDocumentContentResponse({
documentId: "doc_1",
payload: {
result: {
content: [
{
id: "paragraph_1",
type: "paragraph",
content: [{ type: "text", text: "CLI 写入后应可编辑" }],
},
],
revision: 4,
conflictDetectionKey: "doc_1:4",
},
},
});
expect(normalized.content).toEqual([
{
id: "paragraph_1",
type: "paragraph",
content: [{ type: "text", text: "CLI 写入后应可编辑" }],
},
]);
expect(normalized.revision).toBe(4);
expect(normalized.conflictDetectionKey).toBe("doc_1:4");
});
});