ai-chatbot/tests/routes/flow-board-search.test.ts
134 79253245f3 fix(flow-board): align Xmind editor UI and restore marquee feedback
Add native-style menus, search and presentation controls, typography resources, and Xmind import/export styling support.

Bundle canvas styles for preview and production, show marquee borders and selection fills, and align editor density with the project UI. Include interaction regression coverage and client comparison notes.
2026-10-04 13:32:54 +08:00

38 lines
1.9 KiB
TypeScript

import { expect, test } from "@playwright/test";
import type { PlaitElement } from "@plait/core";
import { replaceTopicText, searchTopics } from "@/lib/flow-board/topic-search";
const topic = (id: string, leaves: Record<string, unknown>[], children: PlaitElement[] = []): PlaitElement => ({
id, type: "mind_child", data: { topic: { children: leaves } }, children,
});
test("search includes folded descendants and counts literal matches across sheets", () => {
const child = topic("c", [{ text: "C++ C++" }]);
const parent = { ...topic("p", [{ text: "折叠分支" }], [child]), isCollapsed: true };
const sheets = [
{ id: "a", title: "当前", children: [parent] },
{ id: "b", title: "归档", children: [topic("b", [{ text: "c++" }])] },
];
expect(searchTopics(sheets, "C++").map(item => [item.sheetId, item.id, item.occurrences])).toEqual([["a", "c", 2], ["b", "b", 1]]);
expect(searchTopics(sheets, "C++", true)).toHaveLength(1);
expect(searchTopics(sheets, "")).toEqual([]);
});
test("replacement crosses styled leaves while preserving marks and literal replacement text", () => {
const original = topic("a", [{ text: "start de", bold: true }, { text: "sign end", color: "#ff0000" }]);
const before = JSON.stringify(original);
expect(replaceTopicText(original, "design", "$& 新设计")).toEqual({ children: [
{ text: "start $& 新设计", bold: true },
{ text: " end", color: "#ff0000" },
] });
expect(JSON.stringify(original)).toBe(before);
});
test("adjacent matches replace once each, including matches spanning three leaves", () => {
const original = topic("a", [{ text: "a" }, { text: "ba", italic: true }, { text: "bab" }]);
const output = replaceTopicText(original, "ab", "X");
expect(output.children.map((leaf: {text: string}) => leaf.text).join("")).toBe("XXX");
expect(output.children[1].italic).toBe(true);
expect(replaceTopicText(original, "", "X")).toEqual(original.data.topic);
});