feat: add ci and op convert insert test

This commit is contained in:
cudr
2019-10-22 00:05:46 +03:00
parent 65bb9b134d
commit cc071a2d35
10 changed files with 101 additions and 8 deletions

View File

@@ -0,0 +1,34 @@
import * as Automerge from 'automerge'
import { toSlateOp } from './index'
import { createDoc, cloneDoc, createParagraphJSON } from '../utils'
describe('convert operations to slatejs model', () => {
it('convert insert operations', () => {
const doc1 = createDoc()
const doc2 = cloneDoc(doc1)
const change = Automerge.change(doc1, 'change', (d: any) => {
d.document.nodes.push(createParagraphJSON('hello!'))
d.document.nodes[1].nodes[0].text = 'hello!'
})
const operations = Automerge.diff(doc2, change)
const slateOps = toSlateOp(operations, change)
const expectedOps = [
{
type: 'insert_node',
path: [1],
node: { object: 'block', type: 'paragraph', nodes: [] }
},
{
type: 'insert_node',
path: [1, 0],
node: { object: 'text', marks: [], text: 'hello!' }
}
]
expect(slateOps).toStrictEqual(expectedOps)
})
})

View File

@@ -20,6 +20,7 @@ const AnnotationSetOp = ({ key, value }: Automerge.Diff) => (map, doc) => {
/**
* Looks like set_annotation option is broken, temporary disabled
*/
// if (!doc.annotations[key]) {
op = {
type: 'add_annotation',