import "jest"; import { EditorState } from "prosemirror-state"; import { UxCommand } from "../constants"; import * as pCommands from "../pCommands"; import { Command } from "../types"; import { uxCommands } from "../uxCommands"; import { describeRootsFactory, EditorStateFactory, editorStateFactoryFactory } from "./buildEditorState"; import "./expect.toMapEditorState"; const describeRoots = describeRootsFactory([ ["doc", editorStateFactoryFactory(children => ({ doc }) => doc(children))], ["doc > ul > li", editorStateFactoryFactory(children => ({ doc, ul, li }) => doc(ul(li(children))))], ["doc > bq", editorStateFactoryFactory(children => ({ doc, bq }) => doc(bq(children)))] ]); function runHardBreakSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("start of paragraph", () => { test(build(({ p }) => p("{^}text")), build(({ p, br }) => p(br(), "{^}text"))); }); it("middle of paragraph", () => { test(build(({ p }) => p("te{^}xt")), build(({ p, br }) => p("te", br(), "{^}xt"))); }); it("end of paragraph", () => { test(build(({ p }) => p("text{^}")), build(({ p, br }) => p("text", br(), "{^}"))); }); } describeRoots(build => { describe(pCommands.hardBreak.name, () => { runHardBreakSuite(pCommands.hardBreak, build); describe("via ui", () => { runHardBreakSuite(uxCommands[UxCommand.EnterHard], build); }); }); });