1 import { DocsAwareness } from './DocsAwareness'
2 import * as Y from 'yjs'
4 describe('DocsAwareness', () => {
5 let awareness: DocsAwareness
8 awareness = new DocsAwareness(new Y.Doc())
15 describe('removeDuplicateClients', () => {
16 it('should delete the client with the older lastUpdated value', () => {
17 const newStates = new Map()
19 newStates.set(1, { name: 'user1', awarenessData: {} })
20 awareness.meta.set(1, { lastUpdated: 1, clock: 0 })
22 newStates.set(2, { name: 'user2', awarenessData: {} })
23 awareness.meta.set(2, { lastUpdated: 2, clock: 0 })
25 newStates.set(3, { name: 'user1', awarenessData: {} })
26 awareness.meta.set(3, { lastUpdated: 3, clock: 0 })
28 awareness.states = newStates
30 expect(awareness.getStates().size).toBe(3)
32 awareness.removeDuplicateClients()
34 expect(awareness.getStates().size).toBe(2)
35 expect(awareness.getStates().get(1)).toBeUndefined()