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

64 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

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 { describe, expect, it } from "vitest";
import { Schema } from "@tiptap/pm/model";
import { 捕获选区 } from "../../src/界面/编辑器/选区定位";
const schema = new Schema({
nodes: {
doc: { content: "paragraph+" },
paragraph: {
content: "inline*",
attrs: { paragraph_id: { default: null } },
},
text: { group: "inline" },
hardBreak: {
inline: true,
group: "inline",
attrs: { newline: { default: "\n" } },
},
},
marks: { emphasis: {} },
});
const p = (id: string, text: string) =>
schema.node("paragraph", { paragraph_id: id }, [schema.text(text)]);
describe("作者真实圈选", () => {
// @muse-case {"case_id":"NC-selection-location","environment":"离线浏览器组件","given":"真实ProseMirror文档位置","when":"捕获浏览器选择并转换码点","then":["NC-selection-location:重复原句按第二段定位"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-selection-location:重复原句按第二段定位", () => {
const doc = schema.node("doc", null, [
p("p1", "雨停了。"),
p("p2", "雨停了。"),
]);
expect(捕获选区(doc, 7, 11)).toEqual([
{ paragraph_id: "p2", start: 0, end: 4, original: "雨停了。" },
]);
});
// @muse-case {"case_id":"NC-selection-unicode","environment":"离线浏览器组件","given":"真实ProseMirror文档位置","when":"捕获浏览器选择并转换码点","then":["NC-selection-unicode:表情、组合字符和CRLF不使用UTF16假码点"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-selection-unicode:表情、组合字符和CRLF不使用UTF16假码点", () => {
const doc = schema.node("doc", null, [
schema.node("paragraph", { paragraph_id: "p" }, [
schema.text("🙂e\u0301"),
schema.node("hardBreak", { newline: "\r\n" }),
schema.text("雨停"),
]),
]);
expect(捕获选区(doc, 6, 8)).toEqual([
{ paragraph_id: "p", start: 5, end: 7, original: "雨停" },
]);
expect(() => 捕获选区(doc, 2, 3)).toThrow(/Unicode/);
});
// @muse-case {"case_id":"NC-selection-style","environment":"离线浏览器组件","given":"真实ProseMirror文档位置","when":"捕获浏览器选择并转换码点","then":["NC-selection-style:跨样式圈选拆成相邻明确选段"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-selection-style:跨样式圈选拆成相邻明确选段", () => {
const doc = schema.node("doc", null, [
schema.node("paragraph", { paragraph_id: "p" }, [
schema.text("雨停"),
schema.text("了。", [schema.mark("emphasis")]),
]),
]);
expect(捕获选区(doc, 1, 5)).toEqual([
{ paragraph_id: "p", start: 0, end: 2, original: "雨停" },
{ paragraph_id: "p", start: 2, end: 4, original: "了。" },
]);
expect(捕获选区(doc, 2, 2)).toEqual([]);
});
});