11/// <reference types="@types/jest" />
22
3- import Daily , {
4- DailyCall ,
5- DailyEvent ,
6- DailyEventObjectActiveSpeakerChange ,
7- } from '@daily-co/daily-js' ;
3+ import Daily , { DailyCall } from '@daily-co/daily-js' ;
84import { act , renderHook , waitFor } from '@testing-library/react' ;
95import React from 'react' ;
106
@@ -13,6 +9,7 @@ import { useActiveSpeakerId } from '../../src/hooks/useActiveSpeakerId';
139import {
1410 emitActiveSpeakerChange ,
1511 emitJoinedMeeting ,
12+ emitLeftMeeting ,
1613} from '../.test-utils/event-emitter' ;
1714import { mockParticipant } from '../.test-utils/mocks' ;
1815
@@ -62,6 +59,34 @@ describe('useActiveSpeakerId', () => {
6259 expect ( result . current ) . toBeNull ( ) ;
6360 } ) ;
6461 } ) ;
62+ it ( 'reset to null when leaving meeting' , async ( ) => {
63+ const daily = Daily . createCallObject ( ) ;
64+ ( daily . participants as jest . Mock ) . mockImplementation ( ( ) => ( {
65+ local : {
66+ session_id : 'local' ,
67+ user_name : '' ,
68+ } ,
69+ a : {
70+ session_id : 'a' ,
71+ user_name : 'Alpha' ,
72+ } ,
73+ } ) ) ;
74+ const { result } = renderHook ( ( ) => useActiveSpeakerId ( ) , {
75+ wrapper : createWrapper ( daily ) ,
76+ } ) ;
77+ act ( ( ) => {
78+ emitActiveSpeakerChange ( daily , 'local' ) ;
79+ } ) ;
80+ await waitFor ( ( ) => {
81+ expect ( result . current ) . toEqual ( 'local' ) ;
82+ } ) ;
83+ act ( ( ) => {
84+ emitLeftMeeting ( daily ) ;
85+ } ) ;
86+ await waitFor ( ( ) => {
87+ expect ( result . current ) . toEqual ( null ) ;
88+ } ) ;
89+ } ) ;
6590 describe ( 'active-speaker-change event' , ( ) => {
6691 it ( 'changes returned participant session id (local)' , async ( ) => {
6792 const daily = Daily . createCallObject ( ) ;
@@ -78,16 +103,8 @@ describe('useActiveSpeakerId', () => {
78103 const { result } = renderHook ( ( ) => useActiveSpeakerId ( ) , {
79104 wrapper : createWrapper ( daily ) ,
80105 } ) ;
81- const event : DailyEvent = 'active-speaker-change' ;
82- const payload : DailyEventObjectActiveSpeakerChange = {
83- action : event ,
84- activeSpeaker : {
85- peerId : 'local' ,
86- } ,
87- } ;
88106 act ( ( ) => {
89- // @ts -ignore
90- daily . emit ( event , payload ) ;
107+ emitActiveSpeakerChange ( daily , 'local' ) ;
91108 } ) ;
92109 await waitFor ( ( ) => {
93110 expect ( result . current ) . toEqual ( 'local' ) ;
0 commit comments