muse-agent-example/web/tests/编辑/正文往返.test.ts
zizi ae02fd1732 前端:工作台页面、事件标签与旅程用例
- 上下文清单、任务列表与详情、恢复控制、运行观察、创作对话与消息流、正式变更决策面板、正文写作与候选审阅、资料研究等页面同步本轮后端能力。
- 事件标签表补齐后端事件类型;查询键与生成客户端随 HTTP 契约重新生成。
- 依赖调整后 lockfile 同步;交互用例与浏览器旅程 spec 一并更新。
- 证据:make 前端检查(lint + typecheck + Pi 工具桥 tsc)exit 0;make 前端测试 37 文件 / 120 用例通过。
2026-09-18 01:15:07 +08:00

57 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { afterEach, expect, it } from "vitest";
import { Editor } from "@tiptap/react";
import { 正文扩展 } from "../../src/界面/编辑器/正文编辑器";
import {
转为编辑文档,
转为正文,
正文文本,
} from "../../src/界面/编辑器/文档适配";
import { 解析纯文本 } from "../../src/界面/编辑器/粘贴处理";
import type { 正文草稿 } from "../../src/功能/正文写作/数据";
const editors: Editor[] = [];
afterEach(() => editors.splice(0).forEach((e) => e.destroy()));
// @muse-case {"case_id":"NC-editor-document-roundtrip","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"真实Tiptap与正文JSON","when":"打开后编辑文本","then":["段落身份、组合字符、空白和显式CRLF保留"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-editor-document-roundtrip:真实编辑器往返保留段落身份和原字符", () => {
const draft: 正文草稿 = {
format_version: 1,
paragraphs: [
{
paragraph_id: "p1",
content: [
{ type: "text", text: " “e\u0301🧑‍🏽” ", marks: ["strong"] },
{ type: "line_break", newline: "\r\n" },
{ type: "text", text: "第二行", marks: [] },
],
},
{ paragraph_id: "empty1", content: [] },
{ paragraph_id: "empty2", content: [] },
],
};
const e = new Editor({
extensions: 正文扩展(),
content: 转为编辑文档(draft),
});
editors.push(e);
expect(转为正文(e.getJSON())).toEqual(draft);
e.commands.setTextSelection(2);
e.commands.insertContent("甲");
expect(转为正文(e.getJSON()).paragraphs.map((p) => p.paragraph_id)).toEqual([
"p1",
"empty1",
"empty2",
]);
expect(正文文本(转为正文(e.getJSON()))).toContain("e\u0301");
});
// @muse-case {"case_id":"NC-editor-plaintext-paste","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"连续空行与混合换行","when":"经真实PM解析器粘贴","then":["不折叠空行,实际可见文本与输入相同"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-editor-plaintext-paste:纯文本粘贴连续空行不被默认解析器折叠", () => {
const e = new Editor({ extensions: 正文扩展() });
editors.push(e);
const text = " 首行\n\n\n末行 \r\n";
const slice = 解析纯文本(text, e.schema);
e.view.dispatch(e.state.tr.replaceSelection(slice));
expect(正文文本(转为正文(e.getJSON()))).toBe(text);
});