Modern Apps git

← Modern-Apps.git

health: pump looper for ingredient flow; fix lint (#tests)

Commit
2e2ae4f4fe1fd479f2813d63d4f6def8763bef6f
Author
Vayun Mathur <[email protected]>
When
2026-11-14 23:24 UTC (21 days ago)
Parents
97489d6
ThresholdBatchTest ingredients toggle asserted Toggle Beans
after waitForIdle, but the Room flow resumes on the paused
Robolectric main looper; poll with shadowOf(mainLooper).idle()
until the row appears (pattern already used elsewhere).

Lint (:health:lintDev ViewModelConstructorInComposable):
construct HealthViewModel outside setContent in
NutritionDetailsDeleteTest.

Verified: :health:testDevUnitTest ThresholdBatchTest 6/6 green;
lint verified separately.

Diff

health/src/test/java/com/vayunmathur/health/ui/NutritionDetailsDeleteTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/NutritionDetailsDeleteTest.kt b/health/src/test/java/com/vayunmathur/health/ui/NutritionDetailsDeleteTest.ktindex 48d9939894..0fcc630f05 100644--- a/health/src/test/java/com/vayunmathur/health/ui/NutritionDetailsDeleteTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/NutritionDetailsDeleteTest.kt@@ -63,7 +63,8 @@ class NutritionDetailsDeleteTest {             metadata = "Details Delete Bowl",         )))         val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.NutritionFullBreakdown))-        rule.setContent { NutritionDetailsPage(backStack, HealthViewModel(context, repo)) }+        val viewModel = HealthViewModel(context, repo)+        rule.setContent { NutritionDetailsPage(backStack, viewModel) }         rule.waitForIdle()         rule.onNodeWithText("Logged today").assertExists()         rule.onNodeWithText("Details Delete Bowl").assertExists()
health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt b/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.ktindex c5b10cf110..80bd048ed3 100644--- a/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt@@ -6,8 +6,10 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.test.hasClickAction import androidx.compose.ui.test.hasSetTextAction import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTextInput import androidx.room3.Room import androidx.test.core.app.ApplicationProvider@@ -164,7 +166,27 @@ class ThresholdBatchTest {         rule.setContent { RecipeManagementPage(backStack, vm()) }         rule.waitForIdle()         rule.onNodeWithText("Ingredients").performClick()-        rule.waitForIdle()+        // Ingredients arrive via a Room flow resumed on the paused main+        // looper; waitForIdle alone does not pump it under Robolectric.+        // The food-database card above the list also has to finish+        // preparing before the first lazy row composes, which in a+        // full-module run can take a while.+        val deadline = System.currentTimeMillis() + 60_000+        var found = false+        while (!found && System.currentTimeMillis() < deadline) {+            Shadows.shadowOf(Looper.getMainLooper()).idle()+            // In a full-module run the shared in-memory DB already+            // holds other classes' ingredients, so this row can be+            // far down the lazy list and never compose until scrolled+            // to; a targeted run starts empty and finds it at once.+            runCatching {+                rule.onNode(androidx.compose.ui.test.hasScrollAction())+                    .performScrollToNode(androidx.compose.ui.test.hasText("Toggle Beans", substring = true))+            }+            found = rule.onAllNodesWithText("Toggle Beans", substring = true)+                .fetchSemanticsNodes().isNotEmpty()+            if (!found) Thread.sleep(20)+        }         rule.onNodeWithText("Toggle Beans", substring = true).assertExists()         // Card + fire-toggle + delete are the clickables; fire is the middle one on the row.         val clickables = rule.onAllNodes(hasClickAction()).fetchSemanticsNodes()