commit
8c80a52068
@ -0,0 +1,17 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- '12'
|
||||
|
||||
env:
|
||||
- workerCount=3 timeout=600000
|
||||
|
||||
script:
|
||||
- npm run test
|
||||
|
||||
install:
|
||||
- npm run bootstrap
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
@ -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)
|
||||
})
|
||||
})
|
@ -0,0 +1,24 @@
|
||||
import * as Automerge from 'automerge'
|
||||
import { ValueJSON, TextJSON, NodeJSON } from 'slate'
|
||||
|
||||
export const createTextJSON = (text: string = ''): TextJSON => ({
|
||||
object: 'text',
|
||||
marks: [],
|
||||
text
|
||||
})
|
||||
|
||||
export const createParagraphJSON = (text: string = ''): NodeJSON => ({
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [createTextJSON(text)]
|
||||
})
|
||||
|
||||
export const createValueJSON = (): ValueJSON => ({
|
||||
document: {
|
||||
nodes: [createParagraphJSON()]
|
||||
}
|
||||
})
|
||||
|
||||
export const createDoc = () => Automerge.from(createValueJSON())
|
||||
|
||||
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
|
Loading…
Reference in new issue