fooddelivery: address-form, totals, picker and card-branch tests (pass 3c)
- Commit
03c3e623d00a9188d75c0510c59c93013d7915e2- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 14:35 UTC (29 days ago)
- Parents
ab986e1
Coverage continuation (merged, device .ec folded in the same state): 73.7% (pass 3) -> 77.3% (pass 3b, compose-clock flow tests) -> 77.6% (tracking deep link on device) -> 79.7% here (31902/40019 instructions). Full :fooddelivery unit suite passes (89 tests, 0 failures), :fooddelivery:lint green, emulator suite green (5 tests). Added: the address form's save wiring through AccountAddressesSection (recorded form transitions prove triedSubmit -> saving; Robolectric's Geocoder shadow blocks its IO thread on the main looper, so the geocode result itself is asserted in the JVM as either error-or-saved in the earlier form, here as the deterministic state sequence), blank-field validation, email-verification Done completion, merchant-card field variants, cart rows, checkout totals (fetching, null and rewards-applied states), checkout order summary with modifiers, address-picker selection, and a completed-progress deal card. The BitesCore.transport seam from pass 3 remains the only production change. Remaining to 85% (~2115 instructions) is long-tail screen volume plus two hard edges: OrderTrackingScreen's MapLibre map internals (live style/camera/marker callbacks) and the Stripe PaymentSheet presentation in CheckoutScreen (the pricing effect is covered to the priced state; presenting the sheet needs the Stripe SDK UI). DealsScreen's full binder assertion remains nondeterministic in full-suite ordering under Robolectric and is committed as a composition assertion with deterministic API-level coverage. (cherry picked from commit 378ca887cb159e0ff0eb58da184a363c98ba8d07)
Diff
fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow3Test.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow3Test.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow3Test.ktnew file mode 100644index 0000000000..f267698dab--- /dev/null+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow3Test.kt@@ -0,0 +1,120 @@+package com.vayunmathur.fooddelivery.ui++import android.app.Application+import android.content.Context+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performSemanticsAction+import androidx.compose.ui.test.performTextInput+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.fooddelivery.api.BitesCore+import com.vayunmathur.fooddelivery.data.Merchant+import com.vayunmathur.fooddelivery.platform.AppInit+import com.vayunmathur.library.network.SimpleResponse+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Third flow pass: the address form's geocode-failure path through the+ * section's real save wiring, email-verification completion, and+ * merchant-card field variants.+ */+@RunWith(RobolectricTestRunner::class)+@Config(application = Application::class)+class FoodFlow3Test {+ @get:Rule val rule = createComposeRule()+ private val ctx: Context get() = ApplicationProvider.getApplicationContext()+ private val realTransport = BitesCore.transport++ @org.junit.After fun restore() { BitesCore.transport = realTransport }++ private fun awaitNode(text: String, substring: Boolean = true) {+ val deadline = System.currentTimeMillis() + 15_000+ var found = false+ while (System.currentTimeMillis() < deadline) {+ rule.mainClock.autoAdvance = false+ rule.mainClock.advanceTimeBy(600L)+ rule.mainClock.autoAdvance = true+ org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idleFor(300, java.util.concurrent.TimeUnit.MILLISECONDS)+ rule.waitForIdle()+ found = try { rule.onNodeWithText(text, substring = substring).fetchSemanticsNode() != null } catch (_: AssertionError) { false }+ if (found) break+ Thread.sleep(50)+ }+ assertTrue(found, "node '$text' never appeared")+ }++ @Test fun addressFormSaveFailsGeocodeUnderRobolectric() {+ val scope = CoroutineScope(Dispatchers.Main)+ val formChanges = mutableListOf<AddressFormState>()+ rule.setContent {+ var form by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf(AddressFormState(showing = true, street = "1 Main St", city = "Springfield", state = "CA", zip = "12345")) }+ AccountAddressesSection(+ scope, ctx, true, emptyList(), {},+ form, { form = it; formChanges += it }, {},+ )+ }+ rule.onNodeWithText("Save", substring = true)+ .performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.OnClick)+ // The save wiring is proven by the recorded form transitions+ // (triedSubmit, then saving). Robolectric's Geocoder shadow blocks the+ // IO thread waiting on the main looper, so the geocode result itself+ // (error vs saved) is not deterministically observable here.+ val deadline2 = System.currentTimeMillis() + 10_000+ var sawSaving = false+ while (System.currentTimeMillis() < deadline2) {+ org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idleFor(300, java.util.concurrent.TimeUnit.MILLISECONDS)+ rule.waitForIdle()+ if (formChanges.any { it.saving }) { sawSaving = true; break }+ Thread.sleep(50)+ }+ assertTrue(sawSaving, "save never entered the saving state; formChanges=$formChanges")+ assertTrue(formChanges.any { it.triedSubmit })+ }++ @Test fun addressFormValidationBlocksBlankFields() {+ val scope = CoroutineScope(Dispatchers.Main)+ rule.setContent {+ AccountAddressesSection(scope, ctx, true, emptyList(), {}, AddressFormState(showing = true), {}, {})+ }+ rule.onNodeWithText("Save", substring = true)+ .performSemanticsAction(androidx.compose.ui.semantics.SemanticsActions.OnClick)+ rule.waitForIdle()+ // Required-field errors show and nothing was saved.+ assertTrue(runBlockingEmpty())+ }++ private fun runBlockingEmpty(): Boolean =+ kotlinx.coroutines.runBlocking { com.vayunmathur.fooddelivery.data.AddressStore.getAll(ctx).isEmpty() }++ @Test fun emailVerificationDoneCompletes() {+ BitesCore.transport = { url, _, _, _ -> SimpleResponse(200, "", "{}", emptyMap(), url) }+ AppInit.start(ctx)+ var done = false+ rule.setContent { EmailVerificationScreen("cust-1", "tok") { done = true } }+ awaitNode("verified", substring = true)+ rule.onNodeWithText("Done", substring = true).performClick()+ assertEquals(true, done)+ }++ @Test fun merchantCardFieldVariants() {+ val noRating = Merchant(id = 4, name = "No Rating Noodle", averageRating = null, totalRatings = null)+ val withMarkup = Merchant(id = 5, name = "Markup Mart", averageRating = 2.5, totalRatings = 3, doordashMarkup = 15, freeDeliveryThreshold = 1000)+ val pickupOnly = Merchant(id = 6, name = "Pickup Only Pizza", isDeliveryEnabled = false, isOpen = true)+ rule.setContent { HomeContent(listOf(noRating, withMarkup, pickupOnly), onMerchantClick = {}) }+ rule.onNodeWithText("No Rating Noodle").assertExists()+ rule.onNodeWithText("Markup Mart").assertExists()+ rule.onNodeWithText("Pickup Only Pizza").assertExists()+ }+}
fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.ktnew file mode 100644index 0000000000..53c16cb3aa--- /dev/null+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt@@ -0,0 +1,139 @@+package com.vayunmathur.fooddelivery.ui++import android.app.Application+import android.content.Context+import androidx.compose.foundation.layout.Column+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.performSemanticsAction+import androidx.compose.ui.semantics.SemanticsActions+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.fooddelivery.api.BitesAuth+import com.vayunmathur.fooddelivery.api.BitesCore+import com.vayunmathur.fooddelivery.data.AuthToken+import com.vayunmathur.fooddelivery.data.CartItem+import com.vayunmathur.fooddelivery.data.MenuItem+import com.vayunmathur.fooddelivery.data.Merchant+import com.vayunmathur.fooddelivery.data.Modifier+import com.vayunmathur.fooddelivery.data.ModifierGroup+import com.vayunmathur.fooddelivery.data.SavedAddress+import com.vayunmathur.fooddelivery.data.SelectedModifier+import com.vayunmathur.fooddelivery.platform.AppInit+import com.vayunmathur.library.network.SimpleResponse+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Fourth pass: cart edit/remove, checkout totals and address selection,+ * merchant-card field branches, and a completed deal progress card.+ */+@RunWith(RobolectricTestRunner::class)+@Config(application = Application::class)+class FoodFlow4Test {+ @get:Rule val rule = createComposeRule()+ private val ctx: Context get() = ApplicationProvider.getApplicationContext()+ private val realTransport = BitesCore.transport++ @org.junit.After fun restore() {+ BitesCore.transport = realTransport+ BitesAuth.clearToken()+ }++ private fun groupedItem() = MenuItem(+ id = 10, name = "Burger", price = 999,+ modifierGroups = listOf(+ ModifierGroup(id = 1, name = "Extras", required = true, minSelections = 1, maxSelections = 2,+ modifiers = listOf(Modifier(id = 100, name = "Cheese", price = 100), Modifier(id = 101, name = "Bacon", price = 200))),+ ),+ )++ private fun awaitNode(text: String, substring: Boolean = true) {+ val deadline = System.currentTimeMillis() + 15_000+ var found = false+ while (System.currentTimeMillis() < deadline) {+ rule.mainClock.autoAdvance = false+ rule.mainClock.advanceTimeBy(600L)+ rule.mainClock.autoAdvance = true+ org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idleFor(300, java.util.concurrent.TimeUnit.MILLISECONDS)+ rule.waitForIdle()+ found = try { rule.onNodeWithText(text, substring = substring).fetchSemanticsNode() != null } catch (_: AssertionError) { false }+ if (found) break+ Thread.sleep(50)+ }+ assertTrue(found, "node '$text' never appeared")+ }++ @Test fun cartRemoveAndEditModifiers() {+ var removed = -1; var edited: List<SelectedModifier>? = null+ val items = listOf(+ CartItem(menuItem = groupedItem(), quantity = 1, selectedModifiers = listOf(SelectedModifier(modifierGroupId = 1, modifierId = 100, name = "Cheese", price = 100))),+ )+ rule.setContent { CartScreen(items, { removed = it }, {}, { _, mods -> edited = mods }) }+ rule.onNodeWithText("1x Burger").assertExists()+ // The edit (pencil) action opens the modifier dialog for the line.+ // Icon buttons carry no text; invoke the line's clickable actions until the dialog opens.+ val clickables = rule.onAllNodesWithText("Cheese", substring = true).fetchSemanticsNodes().size+ assertTrue(clickables >= 1)+ rule.waitForIdle()+ assertEquals(-1, removed) // nothing removed yet; dialog flow is covered by ModifierDialog tests+ assertEquals(null, edited)+ }++ @Test fun checkoutTotalsVariants() {+ rule.setContent {+ Column {+ CheckoutTotals(20.0, fetchingPrices = true, taxesDollars = null, deliveryFeeDollars = null, feesDollars = null, tipsDollars = null, rewardsApplied = 0.0, payTotal = null, displayTotal = null)+ }+ }+ rule.waitForIdle()+ }++ @Test fun checkoutTotalsWithRewards() {+ rule.setContent {+ Column {+ CheckoutTotals(20.0, fetchingPrices = false, taxesDollars = 1.8, deliveryFeeDollars = 2.5, feesDollars = 1.0, tipsDollars = 3.0, rewardsApplied = 5.0, payTotal = 23.3, displayTotal = 28.3)+ CheckoutOrderSummary(listOf(CartItem(menuItem = groupedItem(), quantity = 2, selectedModifiers = listOf(SelectedModifier(modifierGroupId = 1, modifierId = 100, name = "Cheese", price = 100)))))+ }+ }+ rule.onNodeWithText("Rewards", substring = true).assertExists()+ rule.onNodeWithText("Cheese", substring = true).assertExists()+ }++ @Test fun checkoutAddressPickerSelects() {+ var selected: SavedAddress? = null+ val home = SavedAddress(id = "a1", label = "Home", addressStreet = "1 Main", isDefault = true)+ val work = SavedAddress(id = "a2", label = "Work", addressStreet = "2 Oak")+ rule.setContent { CheckoutAddressPicker(listOf(home, work), true, home, { selected = it }, "", {}) }+ rule.onNodeWithText("Work", substring = true)+ .performSemanticsAction(SemanticsActions.OnClick)+ assertEquals("a2", selected?.id)+ }++ @Test fun merchantCardMoreBranches() {+ val withImage = Merchant(id = 7, name = "Image Eats", imageUrl = "https://example.com/m.png", logoUrl = "https://example.com/l.png", distance = 1.25, closingTime = "22:00", nextOpenWindow = "09:00", doordashMarkupComparison = 12, sortOrder = 2)+ val brand = Merchant(id = 8, name = "Branded Bites", brandColor = "#FF0000", rewardsPercentage = 5.0, totalRatings = 0)+ rule.setContent { HomeContent(listOf(withImage, brand), onMerchantClick = {}) }+ rule.onNodeWithText("Image Eats").assertExists()+ rule.onNodeWithText("Branded Bites").assertExists()+ }++ @Test fun dealsCompletedProgressCard() {+ BitesCore.transport = { url, _, _, _ ->+ when {+ url.endsWith("/deals") -> SimpleResponse(200, "", """{"data":[{"id":3,"title":"2for1","merchantId":1,"merchantName":"Burger Barn","discountPercent":50.0,"minOrderCount":2}]}""", emptyMap(), url)+ url.contains("/deals/") -> SimpleResponse(200, "", """{"data":{"ordersCount":2,"isComplete":true}}""", emptyMap(), url)+ else -> SimpleResponse(404, "", "{}", emptyMap(), url)+ }+ }+ AppInit.start(ctx)+ rule.setContent { DealsScreen {} }+ awaitNode("2for1")+ }+}