import "jest"; import { EditorState } from "prosemirror-state"; import { schema } from "../../schema"; import { buildEditorState } from "../../__specs__/buildEditorState"; import { isHActive, isMarkActive } from "../isActive"; describe(isHActive.name, () => { function test(editorState: EditorState, level: number, expected: boolean): void { expect(isHActive(editorState, level)).toBe(expected); } describe("h1", () => { it("text selection of partial node", () => test(buildEditorState(({ doc, h1 }) => doc(h1("t{^}ex{$}t"))), 1, true)); }); }); describe(isMarkActive.name, () => { function test(editorState: EditorState, expected: boolean): void { expect(isMarkActive(editorState, schema.marks.b)).toBe(expected); } it("no mark in range", () => test(buildEditorState(({ doc, p }) => doc(p("t{^}ex{$}t"))), false)); it("mark over full range", () => test(buildEditorState(({ doc, p, b }) => doc(p("t{^}", b("ex"), "{$}t"))), true)); it("mark over partial range", () => test(buildEditorState(({ doc, p, b }) => doc(p("t{^}e", b("x"), "{$}t"))), true)); it("mark extends beyond full range", () => test(buildEditorState(({ doc, p, b }) => doc(p(b("t{^}ex{$}t")))), true)); it("unaffected by other mark", () => test(buildEditorState(({ doc, p, b, i }) => doc(p(b("t{^}", i("e"), "x{$}t")))), true)); it("uses matching stored mark for empty selection", () => test(buildEditorState(({ doc, p }) => doc(p("t{^}{$}text")), { storedMarks: ({ b }) => [b()] }), true)); it("ignores non-matching stored mark for empty selection", () => test(buildEditorState(({ doc, p }) => doc(p("t{^}{$}text")), { storedMarks: ({ i }) => [i()] }), false)); });