Modern Apps git

← Modern-Apps.git

unblockjam: await focus and the move in the arrow-key test (#tests)

Commit
14e6df15df923a6489fae1231a09c780aaa477ec
Author
Vayun Mathur <[email protected]>
When
2026-11-16 18:25 UTC (19 days ago)
Parents
b3bad80
arrowKeysMoveTheFocusedBlock pressed the arrow key immediately
after requestFocus(); on a loaded box focus had not landed
yet, the move never happened, and the stray key/focus work
surfaced around the test as UncaughtExceptionsBeforeTest. It
now awaits the focused state (pumping Robolectric's paused
main looper) before pressing, and awaits the resulting board
change instead of asserting synchronously.

Reproduced under TZ=UTC with 4 workers in the combined module
run; verified green in three consecutive combined runs plus a
TZ=America/New_York spot check.

Diff

games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibilityTest.kt
diff --git a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibilityTest.kt b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibilityTest.ktindex 725271bd80..2a1ffb02b1 100644--- a/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibilityTest.kt+++ b/games/unblockjam/src/test/java/com/vayunmathur/games/unblockjam/ui/components/BlockAccessibilityTest.kt@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.ui.Modifier import androidx.compose.ui.input.key.Key import androidx.compose.ui.test.ExperimentalTestApi+import androidx.compose.ui.test.assertIsFocused import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.performCustomAccessibilityActionWithLabel@@ -78,7 +79,23 @@ class BlockAccessibilityTest {         setBoard({ changed = it })         val node = rule.onNodeWithContentDescription(describe(R.string.cd_block, level.blocks[1]))         node.requestFocus()+        // The key event only reaches the block once focus actually lands;+        // on a loaded box requestFocus is still in flight when the key is+        // pressed, the move never happens, and the stray key/focus work+        // surfaces as an uncaught exception around the test. Await the+        // focused state (pumping the paused main looper), then the move.+        rule.waitUntil(15_000) {+            org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()+            runCatching {+                node.assertIsFocused()+                true+            }.getOrDefault(false)+        }         node.performKeyInput { pressKey(Key.DirectionLeft) }+        rule.waitUntil(15_000) {+            org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()+            changed?.blocks?.get(1)?.position == Coord(2, 5)+        }         assertEquals(Coord(2, 5), assertNotNull(changed).blocks[1].position)     }