|
@@ -4,6 +4,8 @@ import { EditorState } from "prosemirror-state"
|
|
|
import { EditorView } from "prosemirror-view"
|
|
import { EditorView } from "prosemirror-view"
|
|
|
import type { PatternOpenPayload } from "@/composables/usePatternPlugin"
|
|
import type { PatternOpenPayload } from "@/composables/usePatternPlugin"
|
|
|
import {
|
|
import {
|
|
|
|
|
+ buildMentionGroups,
|
|
|
|
|
+ buildSlashGroups,
|
|
|
useMentionGroups,
|
|
useMentionGroups,
|
|
|
useSlashGroups,
|
|
useSlashGroups,
|
|
|
} from "@/composables/useSuggestionGroups"
|
|
} from "@/composables/useSuggestionGroups"
|
|
@@ -387,3 +389,88 @@ function stableId(prefix: string): () => string {
|
|
|
let n = 0
|
|
let n = 0
|
|
|
return () => `${prefix}-${n++}`
|
|
return () => `${prefix}-${n++}`
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+describe("suggestion menu selection", () => {
|
|
|
|
|
+ it("slash command Heading 1 inserts # markdown syntax", () => {
|
|
|
|
|
+ const respond = vi.fn()
|
|
|
|
|
+ const closeSession = vi.fn()
|
|
|
|
|
+ const onClose = vi.fn()
|
|
|
|
|
+
|
|
|
|
|
+ const payload: PatternOpenPayload = {
|
|
|
|
|
+ kind: "command",
|
|
|
|
|
+ trigger: "/",
|
|
|
|
|
+ query: "/he",
|
|
|
|
|
+ position: { x: 0, y: 0 },
|
|
|
|
|
+ range: { from: 0, to: 3 },
|
|
|
|
|
+ respond,
|
|
|
|
|
+ close: closeSession,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const groups = buildSlashGroups(payload, null, onClose)
|
|
|
|
|
+ const heading1 = groups
|
|
|
|
|
+ .flatMap((g) => g.items ?? [])
|
|
|
|
|
+ .find((item) => item.label === "Heading 1")
|
|
|
|
|
+
|
|
|
|
|
+ expect(heading1).toBeDefined()
|
|
|
|
|
+ heading1!.onSelect()
|
|
|
|
|
+
|
|
|
|
|
+ expect(respond).toHaveBeenCalledWith({ text: "# ", mode: "replace" })
|
|
|
|
|
+ expect(closeSession).toHaveBeenCalledWith("completed")
|
|
|
|
|
+ expect(onClose).toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("[[ mention menu selects page and inserts [[Page Name]]", () => {
|
|
|
|
|
+ const respond = vi.fn()
|
|
|
|
|
+ const closeSession = vi.fn()
|
|
|
|
|
+ const onClose = vi.fn()
|
|
|
|
|
+
|
|
|
|
|
+ const payload: PatternOpenPayload = {
|
|
|
|
|
+ kind: "reference",
|
|
|
|
|
+ trigger: "[[",
|
|
|
|
|
+ query: "[[Page",
|
|
|
|
|
+ position: { x: 0, y: 0 },
|
|
|
|
|
+ range: { from: 0, to: 7 },
|
|
|
|
|
+ respond,
|
|
|
|
|
+ close: closeSession,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const groups = buildMentionGroups(payload, onClose)
|
|
|
|
|
+ const firstPage = groups
|
|
|
|
|
+ .flatMap((g) => g.items ?? [])
|
|
|
|
|
+ .find((item: any) => item.suffix === "Page")
|
|
|
|
|
+
|
|
|
|
|
+ expect(firstPage).toBeDefined()
|
|
|
|
|
+ expect(groups[0].id).toBe("pages")
|
|
|
|
|
+ firstPage!.onSelect()
|
|
|
|
|
+
|
|
|
|
|
+ expect(respond).toHaveBeenCalledWith({
|
|
|
|
|
+ text: "[[Getting Started]]",
|
|
|
|
|
+ mode: "replace",
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(closeSession).toHaveBeenCalledWith("completed")
|
|
|
|
|
+ expect(onClose).toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("drag block 1 to position 3 reorders correctly", () => {
|
|
|
|
|
+ const blocks = [
|
|
|
|
|
+ { id: "a", depth: 0, content: "first" },
|
|
|
|
|
+ { id: "b", depth: 1, content: "second" },
|
|
|
|
|
+ { id: "c", depth: 2, content: "third" },
|
|
|
|
|
+ { id: "d", depth: 0, content: "fourth" },
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ // Drag block at index 1 ("second") to index 3
|
|
|
|
|
+ const reordered = moveBlock(blocks, 1, 3)
|
|
|
|
|
+ expect(reordered[0].id).toBe("a")
|
|
|
|
|
+ expect(reordered[1].id).toBe("c")
|
|
|
|
|
+ expect(reordered[2].id).toBe("d")
|
|
|
|
|
+ expect(reordered[3].id).toBe("b")
|
|
|
|
|
+
|
|
|
|
|
+ // Undo — drag back from 3 to 1
|
|
|
|
|
+ const restored = moveBlock(reordered, 3, 1)
|
|
|
|
|
+ expect(restored[0].id).toBe("a")
|
|
|
|
|
+ expect(restored[1].id).toBe("b")
|
|
|
|
|
+ expect(restored[2].id).toBe("c")
|
|
|
|
|
+ expect(restored[3].id).toBe("d")
|
|
|
|
|
+ })
|
|
|
|
|
+})
|