1 import type { UserState } from '@lexical/yjs'
2 import { DocParticipantTracker } from './DocParticipantTracker'
3 import type { DocumentState } from '../State/DocumentState'
5 describe('DocParticipantTracker', () => {
6 let tracker: DocParticipantTracker
7 let mockSharedState: jest.Mocked<DocumentState>
11 getProperty: jest.fn(),
12 setProperty: jest.fn(),
13 } as unknown as jest.Mocked<DocumentState>
15 tracker = new DocParticipantTracker(mockSharedState)
18 describe('updateParticipantsFromUserStates', () => {
19 it('should update shared state if the limit is reached', () => {
20 mockSharedState.getProperty.mockReturnValue(false)
21 const states = new Array(10).fill({}) as UserState[]
23 tracker.updateParticipantsFromUserStates(states)
25 expect(mockSharedState.setProperty).toHaveBeenCalledWith('realtimeIsParticipantLimitReached', true)
28 it('should update shared state if the limit is unbreached', () => {
29 mockSharedState.getProperty.mockReturnValue(true)
30 const states = new Array(9).fill({}) as UserState[]
32 tracker.updateParticipantsFromUserStates(states)
34 expect(mockSharedState.setProperty).toHaveBeenCalledWith('realtimeIsParticipantLimitReached', false)
37 it('should not update shared state if the limit status has not changed', () => {
38 mockSharedState.getProperty.mockReturnValue(true)
39 const states = new Array(10).fill({}) as UserState[]
41 tracker.updateParticipantsFromUserStates(states)
43 expect(mockSharedState.setProperty).not.toHaveBeenCalled()