1 import type { InternalEventBusInterface } from '@proton/docs-shared'
2 import type { UserState } from '@lexical/yjs'
3 import { DocParticipantTracker, ParticipantTrackerEvent } from './DocParticipantTracker'
5 describe('DocParticipantTracker', () => {
6 let tracker: DocParticipantTracker
9 tracker = new DocParticipantTracker({
11 } as unknown as InternalEventBusInterface)
14 describe('updateParticipantsFromUserStates', () => {
15 it('should update the totalParticipants and publish an event if the limit is reached', () => {
16 const states = new Array(10).fill({}) as UserState[]
18 tracker.updateParticipantsFromUserStates(states)
20 expect(tracker.isParticipantLimitReached()).toBe(true)
21 expect(tracker.eventBus.publish).toHaveBeenCalledWith({
22 type: ParticipantTrackerEvent.DocumentLimitBreached,
27 it('should update the totalParticipants and publish an event if the limit is unbreached', () => {
28 tracker.updateParticipantsFromUserStates(new Array(10).fill({}) as UserState[])
30 tracker.eventBus.publish = jest.fn()
32 tracker.updateParticipantsFromUserStates(new Array(9).fill({}) as UserState[])
34 expect(tracker.isParticipantLimitReached()).toBe(false)
35 expect(tracker.eventBus.publish).toHaveBeenCalledWith({
36 type: ParticipantTrackerEvent.DocumentLimitUnbreached,