import "jest"; import { EditorState } from "prosemirror-state"; import { UxCommand } from "../constants"; import * as genericCommands from "../genericCommands"; 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))]]); function runDeleteBackwardSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("middle selection of paragraph", () => { test(build(({ p }) => p("t{^}ex{$}t")), build(({ p }) => p("t{^}t"))); }); } function runDeleteForwardSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("middle selection of paragraph", () => { test(build(({ p }) => p("t{^}ex{$}t")), build(({ p }) => p("t{^}t"))); }); } function runEnterSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("middle selection of paragraph", () => { test(build(({ p }) => p("te{^}xt")), build(({ p }) => [p("te"), p("{^}xt")])); }); for (const type of ["ul", "ol"]) { it(`lifts an empty ${type}(1/1)`, () => { test( build(({ ul, ol, li, p }) => { const list = type === "ul" ? ul : ol; return list(li(p("{^}"))); }), build(({ p }) => p("{^}")) ); }); } } function runSelectAllSuite(command: Command, build: EditorStateFactory) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("middle selection of paragraph", () => { test(build(({ p }) => p("t{^}ex{$}t")), build(({ p }) => p("text"), { selection: ({ all }) => all() })); }); } describe(genericCommands.deleteBackward.name, () => { describeRoots(editorStateFactory => { runDeleteBackwardSuite(genericCommands.deleteBackward, editorStateFactory); describe("via ui", () => { runDeleteBackwardSuite(uxCommands[UxCommand.DeleteBackward], editorStateFactory); }); }); }); describe(genericCommands.deleteForward.name, () => { describeRoots(editorStateFactory => { runDeleteForwardSuite(genericCommands.deleteForward, editorStateFactory); describe("via ui", () => { runDeleteForwardSuite(uxCommands[UxCommand.DeleteForward], editorStateFactory); }); }); }); describe(genericCommands.enter.name, () => { describeRoots(editorStateFactory => { runEnterSuite(genericCommands.enter, editorStateFactory); describe("via ui", () => { runEnterSuite(uxCommands[UxCommand.Enter], editorStateFactory); }); }); }); describe(genericCommands.selectAll.name, () => { describeRoots(editorStateFactory => { runSelectAllSuite(genericCommands.selectAll, editorStateFactory); describe("via ui", () => { runSelectAllSuite(uxCommands[UxCommand.SelectAll], editorStateFactory); }); }); });