Skip to content

Commit 2bb25a4

Browse files
committed
fix: test doesn't capture initial Idle state
1 parent 23c1234 commit 2bb25a4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

auth/src/test/java/com/firebase/ui/auth/compose/FirebaseAuthUIAuthStateTest.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,31 @@ class FirebaseAuthUIAuthStateTest {
287287
// Given initial idle state
288288
`when`(mockFirebaseAuth.currentUser).thenReturn(null)
289289

290-
// When updating auth state internally
291-
authUI.updateAuthState(AuthState.Loading("Signing in..."))
292-
293-
// Then the flow should reflect the updated state
290+
// Start collecting the flow to capture initial state
294291
val states = mutableListOf<AuthState>()
295292
val job = launch {
296-
authUI.authStateFlow().take(2).toList(states)
293+
authUI.authStateFlow().take(3).toList(states)
297294
}
298295

299-
// Update state again
296+
// Wait for initial state to be collected
300297
delay(100)
298+
299+
// When updating auth state internally
300+
authUI.updateAuthState(AuthState.Loading("Signing in..."))
301+
302+
// Wait for state update to propagate
303+
delay(100)
304+
305+
// Update state again
301306
authUI.updateAuthState(AuthState.Cancelled)
302307

303308
job.join()
304309

305-
// The first state should be Idle (initial), second should be Loading
306-
assertThat(states[0]).isEqualTo(AuthState.Idle)
307-
// Note: The internal state update may not be immediately visible in the flow
308-
// because the auth state listener overrides it
310+
// Verify the emitted states
311+
assertThat(states).hasSize(3)
312+
assertThat(states[0]).isEqualTo(AuthState.Idle) // Initial state
313+
assertThat(states[1]).isInstanceOf(AuthState.Loading::class.java) // After first update
314+
assertThat(states[2]).isEqualTo(AuthState.Cancelled) // After second update
309315
}
310316

311317
// =============================================================================================

0 commit comments

Comments
 (0)