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 runInsertHorizontalRuleSuite(command: Command) { function test(initial: EditorState, expected: EditorState) { expect(command).toMapEditorState(initial, expected); } it("cursor in empty p", () => { test(buildEditorState(({ doc, p }) => doc(p("{^}"))), buildEditorState(({ doc, hr }) => doc(hr()))); }); it("cursor in non-empty p splits content", () => { test( buildEditorState(({ doc, p }) => doc(p("hello{^}world"))), buildEditorState(({ doc, hr, p }) => doc(p("hello"), hr(), p("{^}world"))) ); }); it("in list item", () => { test( buildEditorState(({ doc, ul, li, p }) => doc(ul(li(p("hello{^}world"))))), buildEditorState(({ doc, ul, li, hr, p }) => doc(ul(li(p("hello"))), hr(), ul(li(p("{^}world"))))) ); }); it("with wedge selection start of document", () => { test( buildEditorState(({ doc, hr }) => doc("{wedge}", hr())), buildEditorState(({ doc, hr }) => doc(hr(), "{wedge}", hr())) ); }); it("with wedge selection end of document", () => { test( buildEditorState(({ doc, hr }) => doc(hr(), "{wedge}")), buildEditorState(({ doc, hr }) => doc(hr(), hr(), "{wedge}")) ); }); } describe(commands.insertHorizontalRule.name, () => { runInsertHorizontalRuleSuite(commands.insertHorizontalRule); describe("via ui", () => { runInsertHorizontalRuleSuite(uxCommands[UxCommand.InsertHorizontalRule]); }); });