import "jest"; import { EditorState } from "prosemirror-state"; import { UxCommand } from "../../constants"; import { Command } from "../../types"; import { uxCommands } from "../../uxCommands"; import { buildEditorState } from "../../__specs__/buildEditorState"; import "../../__specs__/expect.toMapEditorState"; import * as commands from "../commands"; function runToggleSuite(command: Command) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("wraps when empty text selection in single paragraph", () => { test( buildEditorState(({ doc, p }) => doc(p("t{^}{$}ext"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("t{^}{$}ext")))) ); }); it("wraps when partial text selection in single paragraph", () => { test( buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("t{^}ex{$}t")))) ); }); it("wraps when total text selection in single paragraph", () => { test( buildEditorState(({ doc, p }) => doc(p("{^}text{$}"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("{^}text{$}")))) ); }); it("wraps when full text selection across multiple paragraphs", () => { test( buildEditorState(({ doc, p }) => doc(p("{^}hello"), p("world{$}"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("{^}hello"), p("world{$}")))) ); }); it("wraps when partial text selection across multiple paragraphs", () => { test( buildEditorState(({ doc, p }) => doc(p("hel{^}lo"), p("wor{$}ld"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("hel{^}lo"), p("wor{$}ld")))) ); }); // Unwrapping it("unwraps when empty text selection in single paragraph", () => { test( buildEditorState(({ doc, bq, p }) => doc(bq(p("t{^}{$}ext")))), buildEditorState(({ doc, p }) => doc(p("t{^}{$}ext"))) ); }); it("unwraps when partial text selection in single paragraph", () => { test( buildEditorState(({ doc, bq, p }) => doc(bq(p("t{^}ex{$}t")))), buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t"))) ); }); it("unwraps when total text selection in single paragraph", () => { test( buildEditorState(({ doc, bq, p }) => doc(bq(p("{^}text{$}")))), buildEditorState(({ doc, p }) => doc(p("{^}text{$}"))) ); }); it("unwraps when full text selection across multiple paragraphs", () => { test( buildEditorState(({ doc, bq, p }) => doc(bq(p("{^}hello"), p("world{$}")))), buildEditorState(({ doc, p }) => doc(p("{^}hello"), p("world{$}"))) ); }); it("unwraps when partial text selection across multiple paragraphs", () => { test( buildEditorState(({ doc, bq, p }) => doc(bq(p("hel{^}lo"), p("wor{$}ld")))), buildEditorState(({ doc, p }) => doc(p("hel{^}lo"), p("wor{$}ld"))) ); }); // Converting from headings it("converts when empty text selection in single h1", () => { test( buildEditorState(({ doc, h1 }) => doc(h1("t{^}{$}ext"))), buildEditorState(({ doc, bq, p }) => doc(bq(p("t{^}{$}ext")))) ); }); } describe(commands.toggle.name, () => { runToggleSuite(commands.toggle); describe("via ui", () => { runToggleSuite(uxCommands[UxCommand.ToggleBlockquote]); }); });