44 */
55
66import * as Y from 'yjs'
7- import { getDocumentState , getUpdateMessage , applyUpdateMessage } from '../../../src/helpers/yjs.js'
7+ import { getDocumentState , documentStateToStep , applyStep } from '../../../src/helpers/yjs.js'
88
99describe ( 'Yjs base64 wrapped with our helpers' , function ( ) {
10- it ( 'applies step in wrong order ' , function ( ) {
10+ it ( 'applies step generated from document state ' , function ( ) {
1111 const source = new Y . Doc ( )
1212 const target = new Y . Doc ( )
1313 const sourceMap = source . getMap ( )
@@ -17,44 +17,26 @@ describe('Yjs base64 wrapped with our helpers', function() {
1717 // console.log('afterTransaction', tr)
1818 } )
1919
20- const state0 = getDocumentState ( source )
21-
2220 // Add keyA to source and apply to target
2321 sourceMap . set ( 'keyA' , 'valueA' )
2422
2523 const stateA = getDocumentState ( source )
26- const update0A = getUpdateMessage ( source , state0 )
27- applyUpdateMessage ( target , update0A )
24+ const step0A = documentStateToStep ( stateA )
25+ applyStep ( target , step0A )
2826 expect ( targetMap . get ( 'keyA' ) ) . to . be . eq ( 'valueA' )
2927
3028 // Add keyB to source, don't apply to target yet
3129 sourceMap . set ( 'keyB' , 'valueB' )
3230 const stateB = getDocumentState ( source )
33- const updateAB = getUpdateMessage ( source , stateA )
31+ const step0B = documentStateToStep ( stateB )
3432
3533 // Add keyC to source, apply to target
3634 sourceMap . set ( 'keyC' , 'valueC' )
37- const updateBC = getUpdateMessage ( source , stateB )
38- applyUpdateMessage ( target , updateBC )
39- expect ( targetMap . get ( 'keyB' ) ) . to . be . eq ( undefined )
40- expect ( targetMap . get ( 'keyC' ) ) . to . be . eq ( undefined )
4135
4236 // Apply keyB to target
43- applyUpdateMessage ( target , updateAB )
37+ applyStep ( target , step0B )
4438 expect ( targetMap . get ( 'keyB' ) ) . to . be . eq ( 'valueB' )
45- expect ( targetMap . get ( 'keyC' ) ) . to . be . eq ( 'valueC' )
46- } )
47-
48- it ( 'update message is empty if no additional state exists' , function ( ) {
49- const source = new Y . Doc ( )
50- const sourceMap = source . getMap ( )
51- const state0 = getDocumentState ( source )
52- sourceMap . set ( 'keyA' , 'valueA' )
53- const stateA = getDocumentState ( source )
54- const update0A = getUpdateMessage ( source , state0 )
55- const updateAA = getUpdateMessage ( source , stateA )
56- expect ( update0A . length ) . to . be . eq ( 29 )
57- expect ( updateAA ) . to . be . eq ( undefined )
39+ expect ( targetMap . get ( 'keyC' ) ) . to . be . eq ( undefined )
5840 } )
5941
6042} )
0 commit comments