import "jest"; import { EditorState } from "prosemirror-state"; import { UxCommand } from "../../constants"; import * as commands from "../commands"; import { Command } from "../../types"; import { uxCommands } from "../../uxCommands"; import { buildEditorState } from "../../__specs__/buildEditorState"; import "../../__specs__/expect.toMapEditorState"; function runEscapeFromStartSuite(command: Command) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("h1 start of line", () => { test(buildEditorState(({ doc, h1 }) => doc(h1("{^}text"))), buildEditorState(({ doc, p }) => doc(p("{^}text")))); }); it("h2 start of line", () => { test(buildEditorState(({ doc, h2 }) => doc(h2("{^}text"))), buildEditorState(({ doc, p }) => doc(p("{^}text")))); }); } function runToggleHeading1Suite(command: Command) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("partial selection in p", () => { test(buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t"))), buildEditorState(({ doc, h1 }) => doc(h1("t{^}ex{$}t")))); }); it("full selection in p", () => { test(buildEditorState(({ doc, p }) => doc(p("{^}text{$}"))), buildEditorState(({ doc, h1 }) => doc(h1("{^}text{$}")))); }); it("partial selection in h1", () => { test(buildEditorState(({ doc, h1 }) => doc(h1("t{^}ex{$}t"))), buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t")))); }); it("full selection in h1", () => { test(buildEditorState(({ doc, h1 }) => doc(h1("{^}text{$}"))), buildEditorState(({ doc, p }) => doc(p("{^}text{$}")))); }); it("partial selection in h2", () => { test(buildEditorState(({ doc, h2 }) => doc(h2("t{^}ex{$}t"))), buildEditorState(({ doc, h1 }) => doc(h1("t{^}ex{$}t")))); }); it("full selection in h2", () => { test(buildEditorState(({ doc, h2 }) => doc(h2("{^}text{$}"))), buildEditorState(({ doc, h1 }) => doc(h1("{^}text{$}")))); }); } function runToggleHeading2Suite(command: Command) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("partial selection in p", () => { test(buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t"))), buildEditorState(({ doc, h2 }) => doc(h2("t{^}ex{$}t")))); }); it("full selection in p", () => { test(buildEditorState(({ doc, p }) => doc(p("{^}text{$}"))), buildEditorState(({ doc, h2 }) => doc(h2("{^}text{$}")))); }); it("partial selection in h2", () => { test(buildEditorState(({ doc, h2 }) => doc(h2("t{^}ex{$}t"))), buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t")))); }); it("full selection in h2", () => { test(buildEditorState(({ doc, h2 }) => doc(h2("{^}text{$}"))), buildEditorState(({ doc, p }) => doc(p("{^}text{$}")))); }); it("partial selection in h1", () => { test(buildEditorState(({ doc, h1 }) => doc(h1("t{^}ex{$}t"))), buildEditorState(({ doc, h2 }) => doc(h2("t{^}ex{$}t")))); }); it("full selection in h1", () => { test(buildEditorState(({ doc, h1 }) => doc(h1("{^}text{$}"))), buildEditorState(({ doc, h2 }) => doc(h2("{^}text{$}")))); }); } describe(commands.escapeFromStart.name, () => { runEscapeFromStartSuite(commands.escapeFromStart); describe("via ui", () => { runEscapeFromStartSuite(uxCommands[UxCommand.DeleteBackward]); }); }); describe(commands.toggleHeading1.name, () => { runToggleHeading1Suite(commands.toggleHeading1); describe("via ui", () => { runToggleHeading1Suite(uxCommands[UxCommand.ToggleHeading1]); }); }); describe(commands.toggleHeading2.name, () => { runToggleHeading2Suite(commands.toggleHeading2); describe("via ui", () => { runToggleHeading2Suite(uxCommands[UxCommand.ToggleHeading2]); }); });