import { EditorState } from "prosemirror-state"; import { describeRootsFactory, EditorStateFactory, editorStateFactoryFactory } from "../../__specs__/buildEditorState"; import "../../__specs__/expect.toMapEditorState"; import { UxCommand } from "../../constants"; import { Command } from "../../types"; import { uxCommands } from "../../uxCommands"; import { ux as wedgeUx } from "../commands"; function runTryWedgeUpSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("backwards between table and start from start of cell", () => test( build(({ table, tr, td, p }) => table(tr(td(p("{^}"))))), build(({ table, tr, td, p }) => table("{tableStart}", tr(td(p()))), { selection: ({ wedge, refs }) => wedge(refs.get("tableStart")! - 1) }) )); it("backwards between table and start from middle of cell", () => test( build(({ table, tr, td, p }) => table(tr(td(p("wo{^}rd"))))), build(({ table, tr, td, p }) => table("{tableStart}", tr(td(p("word")))), { selection: ({ wedge, refs }) => wedge(refs.get("tableStart")! - 1) }) )); } function runTryWedgeDownSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("forwards between table and end", () => test( build(({ table, tr, td, p }) => table(tr(td(p("{^}"))))), build(({ table, tr, td, p }) => table(tr(td(p())), "{tableEnd}"), { selection: ({ wedge, refs }) => wedge(refs.get("tableEnd")! + 1) }) )); it("forwards between attachment and end", () => test( build(({ at, table, tr, td }) => table(tr(td("{node}", at({ id: "0000" }))))), build(({ at, table, tr, td }) => table(tr(td(at({ id: "0000" }), "{cellEnd}"))), { selection: ({ wedge, refs }) => wedge(refs.get("cellEnd")!) }) )); it("forwards between attachment and end (with following p)", () => test( build(({ at, table, tr, td, p }) => [table(tr(td("{node}", at({ id: "0000" })))), p()]), build(({ at, table, tr, td, p }) => [table(tr(td(at({ id: "0000" }), "{cellEnd}"))), p()], { selection: ({ wedge, refs }) => wedge(refs.get("cellEnd")!) }) )); } function runTryWedgeRightSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("forwards between table and end", () => test( build(({ table, tr, td, p }) => table(tr(td(p("{^}"))))), build(({ table, tr, td, p }) => table(tr(td(p())), "{tableEnd}"), { selection: ({ wedge, refs }) => wedge(refs.get("tableEnd")! + 1) }) )); } function runTryWedgeLeftSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("backwards between table and start from start of cell", () => test( build(({ table, tr, td, p }) => table(tr(td(p("{^}"))))), build(({ table, tr, td, p }) => table("{tableStart}", tr(td(p()))), { selection: ({ wedge, refs }) => wedge(refs.get("tableStart")! - 1) }) )); it("backwards between table and start, when in the midde of text in a cell, without a view", () => test( build(({ table, tr, td, p }) => table(tr(td(p("wo{^}rd"))))), build(({ table, tr, td, p }) => table("{tableStart}", tr(td(p("word")))), { selection: ({ wedge, refs }) => wedge(refs.get("tableStart")! - 1) }) )); } const describeRoots = describeRootsFactory([["doc", editorStateFactoryFactory(child => ({ doc }) => doc(child))]]); describe("tryWedgeUp", () => { describeRoots(editorStateFactory => { runTryWedgeUpSuite(wedgeUx[UxCommand.ArrowUp], editorStateFactory); describe("via ui", () => { runTryWedgeUpSuite(uxCommands[UxCommand.ArrowUp], editorStateFactory); }); }); }); describe("tryWedgeDown", () => { describeRoots(editorStateFactory => { runTryWedgeDownSuite(wedgeUx[UxCommand.ArrowDown], editorStateFactory); describe("via ui", () => { runTryWedgeDownSuite(uxCommands[UxCommand.ArrowDown], editorStateFactory); }); }); }); describe("tryWedgeRight", () => { describeRoots(editorStateFactory => { runTryWedgeRightSuite(wedgeUx[UxCommand.ArrowRight], editorStateFactory); describe("via ui", () => { runTryWedgeRightSuite(uxCommands[UxCommand.ArrowRight], editorStateFactory); }); }); }); describe("tryWedgeLeft", () => { describeRoots(editorStateFactory => { runTryWedgeLeftSuite(wedgeUx[UxCommand.ArrowLeft], editorStateFactory); describe("via ui", () => { runTryWedgeLeftSuite(uxCommands[UxCommand.ArrowLeft], editorStateFactory); }); }); });