library: let toast test state writes land before the clock moves (#ux-audit)
- Commit
ed10892d1fb7518b919ee5c73297be04f3af5ea7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 03:47 UTC (23 days ago)
- Parents
2e1f2a4
Follow-up to the toast commits (dab36a184, 6bf275308). Two of the new AchievementNotificationTest cases failed in the toolchain run - "a tap on the card dismisses it early" and "the toast keeps clear of the status bar inset" - for a test-harness reason, not a product one: with mainClock.autoAdvance = false, a state write made outside composition (the click handler's hide(), or the test assigning new insets) is only applied to the composition when the global snapshot is flushed, which waitForIdle() does and advanceTimeBy() does not. The tests advanced the clock first, so the exit animation / relayout never ran in the window they measured. Fix: call rule.waitForIdle() right after the click / the inset change and before advancing the clock. Test-only; no production change. Verification: :library:ui:testDebugUnitTest (AchievementNotificationTest).
Diff
library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.ktindex 38e2f4c0a6..f26dbeecdb 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt@@ -70,6 +70,8 @@ class AchievementNotificationTest { fun `a tap on the card dismisses it early`() { setToastOverScreen() rule.onNodeWithText("First win").performClick()+ // Let the click's state write reach the composition before the clock moves on.+ rule.waitForIdle() rule.mainClock.advanceTimeBy(1_000) rule.waitForIdle() assertEquals(1, dismissed)@@ -121,7 +123,9 @@ class AchievementNotificationTest { val flush = rule.onNodeWithText("First win").getUnclippedBoundsInRoot().top insets = WindowInsets(top = 40.dp)+ rule.waitForIdle() rule.mainClock.advanceTimeBy(100)+ rule.waitForIdle() val inset = rule.onNodeWithText("First win").getUnclippedBoundsInRoot().top assertEquals(40f, (inset - flush).value, 0.5f, "the whole card moves down by the inset") }