Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(syncservice): Apply Yjs steps in wrong order
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jul 11, 2023
commit 27f39948331df35dd28bc42c9a8e3aaabc040a7b
37 changes: 36 additions & 1 deletion cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { randUser } from '../../utils/index.js'
import { SyncService } from '../../../src/services/SyncService.js'
import createSyncServiceProvider from '../../../src/services/SyncServiceProvider.js'
import { Doc } from 'yjs'
import { Doc, applyUpdate, encodeStateAsUpdate, encodeStateVector } from 'yjs'

const user = randUser()

Expand Down Expand Up @@ -164,4 +164,39 @@ describe('Sync service provider', function() {
cy.get('@sync.all').its('length').should('be.lessThan', 60)
})

it.only('applies step in wrong order', function() {
const source = new Doc()
const target = new Doc()
const sourceMap = source.getMap()
const targetMap = target.getMap()

target.on('afterTransaction', (tr, doc) => {
// console.log('afterTransaction', tr)
})

// Add keyA to source and apply to target
sourceMap.set('keyA', 'valueA')
const update0A = encodeStateAsUpdate(source)
const sourceVectorA = encodeStateVector(source)
applyUpdate(target, update0A)
expect(targetMap.get('keyA')).to.be.eq('valueA')

// Add keyB to source, don't apply to target yet
sourceMap.set('keyB', 'valueB')
const updateAB = encodeStateAsUpdate(source, sourceVectorA)
const sourceVectorB = encodeStateVector(source)

// Add keyC to source, apply to target
sourceMap.set('keyC', 'valueC')
const updateBC = encodeStateAsUpdate(source, sourceVectorB)
applyUpdate(target, updateBC)
expect(targetMap.get('keyB')).to.be.eq(undefined)
expect(targetMap.get('keyC')).to.be.eq(undefined)

// Apply keyB to target
applyUpdate(target, updateAB)
expect(targetMap.get('keyB')).to.be.eq('valueB')
expect(targetMap.get('keyC')).to.be.eq('valueC')
})

})