import { describe, expect, it } from "vitest" import { astToTiptap, tiptapToAst } from "../src/editor/adapter" import type { BlockNode } from "../src/core/types" describe("BlockFlow TipTap adapter", () => { it("round-trips paragraphs, text, and variables", () => { const blocks: BlockNode[] = [ { id: "p1", type: "paragraph", inlines: [ { type: "text", content: "你好," }, { type: "variable", path: "user.name", required: true } ] } ] expect(tiptapToAst(astToTiptap(blocks))).toEqual(blocks) }) it("round-trips structured blocks and atom blocks", () => { const blocks: BlockNode[] = [ { id: "container1", type: "container", name: "用户通知", children: [ { id: "if1", type: "condition", expression: "user.isVip", children: [ { id: "loop1", type: "loop", source: "items", itemName: "item", indexName: "index", children: [ { id: "p1", type: "paragraph", inlines: [{ type: "variable", path: "item.title" }] } ] } ] }, { id: "frag1", type: "fragmentRef", fragmentId: "fragment_common_footer" }, { id: "comment1", type: "comment", content: "备注" } ] } ] expect(tiptapToAst(astToTiptap(blocks))).toEqual(blocks) }) it("does not leak TipTap document wrapper into BlockFlow AST", () => { const ast = tiptapToAst({ type: "doc", content: [ { type: "paragraph", attrs: { id: "p1" }, content: [{ type: "text", text: "plain" }] } ] }) expect(ast).toEqual([ { id: "p1", type: "paragraph", inlines: [{ type: "text", content: "plain" }] } ]) expect(JSON.stringify(ast)).not.toContain("\"doc\"") }) })