taxi: keep tracking live when a cancel attempt fails
- Commit
7afa03c0d504bcc7c179a41f0232eb759532d95c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:42 UTC (28 days ago)
- Parents
05b6fca
RideTrackingScreen ended tracking unconditionally after every cancel\nattempt, including CancelResult.Failed and CancelResult.Unsupported.\nLyftRidesClient.cancelRide reports Failed for any non-2xx response\n(rate limits, transient 5xx, validation errors) and when no token is\ncached, so a failed cancel — which leaves the ride live on the server\n— stopped both poll loops, hid the Cancel button, and showed the\nended status header while the driver was still coming. The user had\nto leave and re-enter the screen to resume tracking, and could not\nretry the cancel from the stranded screen.\n\nOnly a confirmed CancelResult.Done now sets ended; a failed or\nunsupported cancel keeps the polls running and the Cancel button\noffered, so the user sees the failure message and can retry.\n\nAdds trackingScreenFailedCancelKeepsTracking, which fails a cancel\nwith HTTP 500 and asserts the failure message is shown while the\nCancel button stays on screen. Verified with\n:taxi:testDevUnitTest (TaxiPass3TrackingScreenTest: 6/6 pass).
Diff
taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.ktindex 2bc9e760c1..91ee2c11c8 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt@@ -184,14 +184,19 @@ fun RideTrackingScreen(rideId: String) { confirmingCancel = false cancelling = true scope.launch {- cancelMessage = when (val result = provider.cancelRide(rideId)) {+ val result = provider.cancelRide(rideId)+ cancelMessage = when (result) { is CancelResult.Done -> context.getString(R.string.ride_cancelled) is CancelResult.Failed -> context.getString(R.string.cancel_failed, result.message) CancelResult.Unsupported -> context.getString(R.string.cancel_failed, "unsupported") } cancelling = false- ended = true+ // A failed cancel leaves the ride live: only a confirmed+ // cancel ends tracking, so the user can retry after a+ // transient failure instead of being stranded on a+ // screen that claims the ride ended.+ if (result is CancelResult.Done) ended = true } }) { Text(stringResource(R.string.cancel_ride), color = MaterialTheme.colorScheme.error)
taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.ktindex 0e5d1a7360..6e220603cb 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt@@ -8,6 +8,7 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.test.core.app.ApplicationProvider import com.vayunmathur.taxi.R+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.taxi.data.lyft.LyftTokenStore import com.vayunmathur.taxi.network.TaxiPass3FakeHttp import com.vayunmathur.taxi.network.lyft.LyftToken@@ -100,6 +101,29 @@ class TaxiPass3TrackingScreenTest { assertTrue(http.callsTo("/cancel").isNotEmpty()) } + @Test+ fun trackingScreenFailedCancelKeepsTracking() {+ http.on("/v1/activeride") { http.raw(200, rideJson("approaching"), url = it.url) }+ http.on("/driver-location") {+ http.raw(200, """{"location":{"lat":37.71,"lng":-122.41}}""", url = it.url)+ }+ http.on("/cancel") { http.raw(500, "kaput", "text/plain", it.url) }+ rule.setContent { RideTrackingScreen(rideId = "r1") }+ waitForText(str(R.string.cancel_ride))+ rule.onNodeWithText(str(R.string.cancel_ride)).performClick()+ waitForText(str(R.string.cancel_ride_title))+ // Confirm (the dialog's Cancel ride action is the last one).+ val buttons = rule.onAllNodesWithText(str(R.string.cancel_ride)).fetchSemanticsNodes()+ assertTrue(buttons.size >= 2)+ rule.onAllNodesWithText(str(R.string.cancel_ride))[buttons.lastIndex].performClick()+ // The failure is reported, but the ride is still live: dismiss the+ // message and the Cancel button must still be offered for a retry.+ waitForText(str(R.string.cancel_failed, "Lyft returned HTTP 500: kaput"))+ rule.onNodeWithText(str(UiR.string.close)).performClick()+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.cancel_ride)).assertIsDisplayed()+ }+ @Test fun trackingScreenKeepRideDismissesDialog() { http.on("/v1/activeride") { http.raw(200, rideJson("accepted"), url = it.url) }