From f94653424af1b542a0727cb9432fa2383878356f Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Wed, 14 Nov 2018 07:20:06 +0100 Subject: [PATCH] add prosemirror tests --- examples/indexeddb/index.html | 1 - test/index.js | 2 +- test/prosemirror.test.js | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/prosemirror.test.js diff --git a/examples/indexeddb/index.html b/examples/indexeddb/index.html index 9ab44a5e..8b3a4746 100644 --- a/examples/indexeddb/index.html +++ b/examples/indexeddb/index.html @@ -18,7 +18,6 @@ - diff --git a/test/index.js b/test/index.js index 869d5b34..8f30d9ae 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,4 @@ // TODO: include all tests - import './red-black-tree.js' import './y-array.tests.js' import './y-text.tests.js' @@ -7,3 +6,4 @@ import './y-map.tests.js' import './y-xml.tests.js' import './encode-decode.tests.js' import './diff.tests.js' +import './prosemirror.test.js' diff --git a/test/prosemirror.test.js b/test/prosemirror.test.js new file mode 100644 index 00000000..0eff2f03 --- /dev/null +++ b/test/prosemirror.test.js @@ -0,0 +1,38 @@ +import { test } from '../node_modules/cutest/cutest.mjs' +import * as random from '../lib/random/random.js' +import * as Y from '../src/index.js' + +import { prosemirrorPlugin, cursorPlugin } from '../bindings/ProsemirrorBinding/ProsemirrorBinding.js' +import {EditorState} from 'prosemirror-state' +import {EditorView} from 'prosemirror-view' +import {Schema, DOMParser, Mark, Fragment, Node, Slice} from 'prosemirror-model' +import {schema} from 'prosemirror-schema-basic' +import {exampleSetup} from 'prosemirror-example-setup' + +const createNewProsemirrorView = y => { + const view = new EditorView(document.createElement('div'), { + state: EditorState.create({ + schema, + plugins: exampleSetup({schema}).concat([prosemirrorPlugin(y.define('prosemirror', Y.XmlFragment))]) + }) + }) + return view +} + +test('random prosemirror insertions', async t => { + const gen = random.createPRNG(t.getSeed()) + const y = new Y.Y() + const p1 = createNewProsemirrorView(y) + const p2 = createNewProsemirrorView(y) + for (let i = 0; i < 10; i++) { + const p = random.oneOf(gen, [p1, p2]) + const insertPos = random.int32(gen, 0, p.state.doc.content.size) + const overwrite = random.int32(gen, 0, p.state.doc.content.size - insertPos) + p.dispatch(p.state.tr.insertText('' + i, insertPos, insertPos + overwrite)) + } + t.compare( + p1.state.doc.toJSON(), + p2.state.doc.toJSON(), + 'compare prosemirror models' + ) +})