How to use prosemirror-test-builder - 10 common examples

To help you get started, we’ve selected a few prosemirror-test-builder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
let tr = new Transform(ms.node("doc", null, [ms.node("paragraph", null, [ms.text("a")])]))
      tr.replace(3, 3, ms.node("doc", null, [
        ms.node("paragraph", null, [ms.text("b")], [ms.mark("em")])
      ]).slice(1, 3))
      ist(tr.doc.childCount, 2)
      ist(tr.doc.lastChild.marks.length, 1)
    })

    // A schema that enforces a heading and a body at the top level
    let hbSchema = new Schema({
      nodes: schema.spec.nodes.append({
        doc: Object.assign({}, schema.spec.nodes.get("doc"), {content: "heading body"}),
        body: {content: "block+"}
      })
    })
    let hb = builders(hbSchema, {
      p: {nodeType: "paragraph"},
      b: {nodeType: "body"},
      h: {nodeType: "heading", level: 1},
    })

    it("can unwrap a paragraph when replacing into a strict schema", () => {
      let tr = new Transform(hb.doc(hb.h("Head"), hb.b(hb.p("Content"))))
      tr.replace(0, tr.doc.content.size, tr.doc.slice(7, 16))
      ist(tr.doc, hb.doc(hb.h("Content"), hb.b(hb.p())), eq)
    })

    it("can unwrap a body after a placed node", () => {
      let tr = new Transform(hb.doc(hb.h("Head"), hb.b(hb.p("Content"))))
      tr.replace(7, 7, tr.doc.slice(0, tr.doc.content.size))
      ist(tr.doc, hb.doc(hb.h("Head"), hb.b(hb.h("Head"), hb.p("Content"), hb.p("Content"))), eq)
    })
github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
tr.replace(2, 7, tr.doc.slice(2, 7))
      ist(tr.doc, tr.before, eq)
    })

    it("preserves marks on open slice block nodes", () => {
      let tr = new Transform(ms.node("doc", null, [ms.node("paragraph", null, [ms.text("a")])]))
      tr.replace(3, 3, ms.node("doc", null, [
        ms.node("paragraph", null, [ms.text("b")], [ms.mark("em")])
      ]).slice(1, 3))
      ist(tr.doc.childCount, 2)
      ist(tr.doc.lastChild.marks.length, 1)
    })

    // A schema that enforces a heading and a body at the top level
    let hbSchema = new Schema({
      nodes: schema.spec.nodes.append({
        doc: Object.assign({}, schema.spec.nodes.get("doc"), {content: "heading body"}),
        body: {content: "block+"}
      })
    })
    let hb = builders(hbSchema, {
      p: {nodeType: "paragraph"},
      b: {nodeType: "body"},
      h: {nodeType: "heading", level: 1},
    })

    it("can unwrap a paragraph when replacing into a strict schema", () => {
      let tr = new Transform(hb.doc(hb.h("Head"), hb.b(hb.p("Content"))))
      tr.replace(0, tr.doc.content.size, tr.doc.slice(7, 16))
      ist(tr.doc, hb.doc(hb.h("Content"), hb.b(hb.p())), eq)
    })
github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
doc(ul(li(p("ABCD")), li(p("EFGH")))).slice(5, 13, true),
            doc(ul(li(p("abCD")), li(p("EFgh"))))))

    it("will auto-close a list item when it fits in a list", () =>
       repl(doc(ul(li(p("foo")), "<a>", li(p("bar")))),
            ul(li(p("a</a><a>bc")), li(p("de<b>f"))),
            doc(ul(li(p("foo")), li(p("bc")), li(p("de")), li(p("bar"))))))

    it("finds the proper openEnd value when unwrapping a deep slice", () =&gt;
       repl(doc("</b></a><b><a>", p(), "<b>"),
            doc(blockquote(blockquote(blockquote(p("hi"))))).slice(3, 6, true),
            doc(p("hi"))))

    // A schema that allows marks on top-level block nodes
    let ms = new Schema({
      nodes: schema.spec.nodes.update("doc", Object.assign({}, schema.spec.nodes.get("doc"), {marks: "_"})),
      marks: schema.spec.marks
    })

    it("preserves marks on block nodes", () =&gt; {
      let tr = new Transform(ms.node("doc", null, [
        ms.node("paragraph", null, [ms.text("hey")], [ms.mark("em")]),
        ms.node("paragraph", null, [ms.text("ok")], [ms.mark("strong")])
      ]))
      tr.replace(2, 7, tr.doc.slice(2, 7))
      ist(tr.doc, tr.before, eq)
    })

    it("preserves marks on open slice block nodes", () =&gt; {
      let tr = new Transform(ms.node("doc", null, [ms.node("paragraph", null, [ms.text("a")])]))
      tr.replace(3, 3, ms.node("doc", null, [
        ms.node("paragraph", null, [ms.text("b")], [ms.mark("em")])</b></a></b>
github ProseMirror / prosemirror-transform / test / test-structure.js View on Github external
const {canSplit, liftTarget, findWrapping, Transform} = require("..")
const {eq, schema: baseSchema} = require("prosemirror-test-builder")
const ist = require("ist")

const schema = new Schema({
  nodes: {
    doc: {content: "head? block* sect* closing?"},
    para: {content: "text*", group: "block"},
    head: {content: "text*", marks: ""},
    figure: {content: "caption figureimage", group: "block"},
    quote: {content: "block+", group: "block"},
    figureimage: {},
    caption: {content: "text*", marks: ""},
    sect: {content: "head block* sect*"},
    closing: {content: "text*"},
    text: baseSchema.spec.nodes.get("text"),

    fixed: {content: "head para closing", group: "block"}
  },
  marks: {
    em: {}
  }
})

function n(name, ...content) { return schema.nodes[name].create(null, content) }
function t(str, em) { return schema.text(str, em ? [schema.mark("em")] : null) }

const doc = n("doc", // 0
              n("head", t("Head")), // 6
              n("para", t("Intro")), // 13
              n("sect", // 14
                n("head", t("Section head")), // 28
github ProseMirror / prosemirror-model / test / test-slice.js View on Github external
it("preserves styles started after cut", () =&gt;
       t(doc(p("a ", em("sentence"), " wi<a>th ", em("text"), " in it")),
         doc(p("th ", em("text"), " in it")), 1, 0))
</a>
github ProseMirror / prosemirror-view / test / test-draw-decoration.js View on Github external
it("draws multiple widgets", () => {
    let view = tempEditor({doc: doc(p("foobar")),
                           plugins: [decoPlugin(["1-widget", "4-widget", "7-widget"])]})
    let found = view.dom.querySelectorAll("button")
    ist(found.length, 3)
    ist(found[0].nextSibling.textContent, "foo")
    ist(found[1].nextSibling.textContent, "bar")
    ist(found[2].previousSibling.textContent, "bar")
  })
github ProseMirror / prosemirror-view / test / test-selection.js View on Github external
it("can go back and forth between screen coords and document positions", () => {
    let view = tempEditor({doc: doc(p("one"), blockquote(p("two"), p("three")))})
    ;[1, 2, 4, 7, 14, 15].forEach(pos => {
      let coords = view.coordsAtPos(pos)
      let found = view.posAtCoords({top: coords.top + 1, left: coords.left}).pos
      ist(found, pos)
    })
  })
github ProseMirror / prosemirror-commands / test / test-commands.js View on Github external
it("deletes a leaf node after the current block", () =&gt;
     apply(doc(p("foo<a>"), hr, p("bar")), joinForward, doc(p("foo"), p("bar"))))
</a>
github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
it("can change a wrapped block", () =&gt;
       type(doc(blockquote(p("one<a>"), p("two<b>"))),
            doc(blockquote(h1("one</b></a><b><a>"), h1("two<b>"))),
            "heading", {level: 1}))
</b></a></b>
github ProseMirror / prosemirror-commands / test / test-commands.js View on Github external
it("moves a block into an adjacent wrapper", () =&gt;
     apply(doc(blockquote(p("hi")), p("<a>there")), joinBackward,
           doc(blockquote(p("hi"), p("there")))))
</a>