muse-agent-example/web/tests/编辑/正文往返.test.ts
zizi 98530437f2 W11 编辑器、动态表单与人审工作台:编辑器、动态表单与人审工作台(确认前正文不落正式库)。
按 R2 串行阶段整理提交;包内文件为该阶段交付(含后续小增量),状态以工作包清单为准。
2026-09-10 19:25:41 +08:00

55 lines
1.9 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()));
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");
});
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);
});