@@ -95,9 +95,9 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
9595// Reset the store to initial state
9696useLiveKitCallStore . setState ( {
9797availableRooms :[
98- { id :'emergency-channel ' , name :'Emergency Channel ' } ,
99- { id :'tactical-1 ' , name :'Tactical 1 ' } ,
100- { id :'dispatch ' , name :'Dispatch ' } ,
98+ { id :'general-chat ' , name :'General Chat ' } ,
99+ { id :'dev-team-sync ' , name :'Dev Team Sync ' } ,
100+ { id :'product-updates ' , name :'Product Updates ' } ,
101101] ,
102102selectedRoomForJoining :null ,
103103currentRoomId :null ,
@@ -155,11 +155,11 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
155155
156156describe ( 'Room Connection with CallKeep' , ( ) => {
157157beforeEach ( ( ) => {
158- // Mock successful connection flow
158+ // Mock successful connection flow with proper async handling
159159mockRoom . on . mockImplementation ( ( event :any , callback :any ) => {
160160if ( event === 'connectionStateChanged' ) {
161- //Simulate connected state
162- setTimeout ( ( ) => callback ( 'connected' ) , 0 ) ;
161+ //Store the callback for manual triggering
162+ ( mockRoom as any ) . _connectionStateCallback = callback ;
163163}
164164return mockRoom ;
165165} ) ;
@@ -169,20 +169,28 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
169169const { result} = renderHook ( ( ) => useLiveKitCallStore ( ) ) ;
170170
171171await act ( async ( ) => {
172- await result . current . actions . connectToRoom ( 'emergency-channel' , 'test-participant' ) ;
173- // Wait for the connection state change event to fire
174- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
172+ await result . current . actions . connectToRoom ( 'general-chat' , 'test-participant' ) ;
173+
174+ // Manually trigger the connection state change
175+ if ( ( mockRoom as any ) . _connectionStateCallback ) {
176+ ( mockRoom as any ) . _connectionStateCallback ( 'connected' ) ;
177+ }
175178} ) ;
176179
177- expect ( mockCallKeepService . startCall ) . toHaveBeenCalledWith ( 'emergency-channel ' ) ;
180+ expect ( mockCallKeepService . startCall ) . toHaveBeenCalledWith ( 'general-chat ' ) ;
178181} ) ;
179182
180183it ( 'should not start CallKeep call on Android' , async ( ) => {
181184mockPlatform . OS = 'android' ;
182185const { result} = renderHook ( ( ) => useLiveKitCallStore ( ) ) ;
183186
184187await act ( async ( ) => {
185- await result . current . actions . connectToRoom ( 'emergency-channel' , 'test-participant' ) ;
188+ await result . current . actions . connectToRoom ( 'dev-team-sync' , 'test-participant' ) ;
189+
190+ // Manually trigger the connection state change
191+ if ( ( mockRoom as any ) . _connectionStateCallback ) {
192+ ( mockRoom as any ) . _connectionStateCallback ( 'connected' ) ;
193+ }
186194} ) ;
187195
188196expect ( mockCallKeepService . startCall ) . not . toHaveBeenCalled ( ) ;
@@ -195,14 +203,17 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
195203const { result} = renderHook ( ( ) => useLiveKitCallStore ( ) ) ;
196204
197205await act ( async ( ) => {
198- await result . current . actions . connectToRoom ( 'emergency-channel' , 'test-participant' ) ;
199- // Wait for the connection state change event to fire
200- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
206+ await result . current . actions . connectToRoom ( 'general-chat' , 'test-participant' ) ;
207+
208+ // Manually trigger the connection state change
209+ if ( ( mockRoom as any ) . _connectionStateCallback ) {
210+ ( mockRoom as any ) . _connectionStateCallback ( 'connected' ) ;
211+ }
201212} ) ;
202213
203214expect ( mockLogger . warn ) . toHaveBeenCalledWith ( {
204215message :'Failed to start CallKeep call (background audio may not work)' ,
205- context :{ error, roomId :'emergency-channel ' } ,
216+ context :{ error, roomId :'general-chat ' } ,
206217} ) ;
207218} ) ;
208219} ) ;
@@ -345,6 +356,7 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
345356const { result} = renderHook ( ( ) => useLiveKitCallStore ( ) ) ;
346357
347358expect ( result . current . availableRooms ) . toHaveLength ( 3 ) ;
359+ expect ( result . current . availableRooms [ 0 ] ) . toEqual ( { id :'general-chat' , name :'General Chat' } ) ;
348360expect ( result . current . selectedRoomForJoining ) . toBeNull ( ) ;
349361expect ( result . current . currentRoomId ) . toBeNull ( ) ;
350362expect ( result . current . isConnecting ) . toBe ( false ) ;
@@ -430,6 +442,8 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
430442message :'Error setting microphone state' ,
431443context :{ error, enabled :true } ,
432444} ) ;
445+
446+ // Check that error state was set after the await completes
433447expect ( result . current . error ) . toBe ( 'Could not change microphone state.' ) ;
434448} ) ;
435449
@@ -500,7 +514,6 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
500514} ) ;
501515
502516describe ( 'Error Handling' , ( ) => {
503- describe ( 'Error Handling' , ( ) => {
504517it ( 'should handle room initialization errors' , async ( ) => {
505518// Make the Room constructor throw an error
506519MockedRoom . mockImplementationOnce ( ( ) => {
@@ -534,17 +547,4 @@ describe('useLiveKitCallStore with CallKeep Integration', () => {
534547expect ( result . current . error ) . toBeNull ( ) ;
535548} ) ;
536549} ) ;
537-
538- it ( 'should handle basic error state management' , async ( ) => {
539- const { result} = renderHook ( ( ) => useLiveKitCallStore ( ) ) ;
540-
541- // Test basic error clearing functionality since token fetching isn't implemented
542- act ( ( ) => {
543- // Set an error state and then clear it
544- result . current . actions . _clearError ( ) ;
545- } ) ;
546-
547- expect ( result . current . error ) . toBeNull ( ) ;
548- } ) ;
549- } ) ;
550550} ) ;