taxi: sign-out, add-card and ride-cancel dialogs are routes
- Commit
96ea302dafe97a6b86e1af60906eabfb8da05421- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 00:25 UTC (4 days ago)
- Parents
53a6c3b
DialogAsRoute (14): AccountsScreen sign-out and add-card and RideTrackingScreen cancel-confirm and cancel-result are now Route destinations (SignOutDialog, AddCardDialog, CancelRideDialog(rideId), CancelResultDialog(rideId, outcome, message)) with DialogPage() entries in ui/TaxiDialogEntries.kt and stateless content under ui/dialogs/ (AddCardDialog moved there); screens push the routes from the click and hear back through RESULT_ACCOUNTS_CHANGED / RESULT_RIDE_CANCEL_ATTEMPT, so a confirmed cancel still ends tracking and a failed one leaves the ride live for retry. The remaining 10 hits are the Lyft booking wizard in LyftBooking.kt, exempted per file: its intermediate state is a non-serializable quote/places/charge- account set plus pending-ride persistence for process-death reconciliation, so it has no route/result shape yet. RouteScreenshotCoverage (4): CurrentRide, Accounts, LyftSignIn and RideTracking are exempted per route in Route.kt (live provider polling, token store, SMS sign-in session and native map/tracking service; no stateless Layoutlib slice), with the regenerated docs/structure/exceptions.tsv included. The four new dialog routes get real deterministic captures (3-sign-out-dialog through 6-cancel-result-dialog) in MetadataPreviews; updateDevScreenshotTest renders all six previews non-blank. FixtureDeterminism: the cached location fixture in Y3TaxiLocScreenTest now uses a fixed epoch-millis (the provider never reads the fix time). Tests adapted to the route-request contract: accounts dialog tests and tracking cancel tests drive the real Navigation dialog routes, and standalone screen harnesses provide a NavResultRegistry like the navigation host. taxi/AGENTS.md documents the dialog routes and screenshot coverage. Verified: ./gradlew :taxi:lint (0 errors) :taxi:lintVitalRelease (No issues found, run solo) :taxi:testDevUnitTest (274 tests, 0 failures) :taxi:compileReleaseKotlin all green, plus :taxi:compileDevScreenshotTestKotlin and :taxi:updateDevScreenshotTest green.
Diff
docs/structure/exceptions.tsv
diff --git a/docs/structure/exceptions.tsv b/docs/structure/exceptions.tsvindex a47c386c94..9461ef1d77 100644--- a/docs/structure/exceptions.tsv+++ b/docs/structure/exceptions.tsv@@ -1,7 +1,6 @@ # type file reason count # Generated by: python3 tools/structure_check.py exceptions --regen # A new/changed marker requires regenerating this file and reviewing the diff; the reason column is copied verbatim from the source marker.-PACKAGE_JNI appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.kt JNI (verbatim marker; no free-text reason) 1 PACKAGE_JNI code/src/main/java/com/vayunmathur/code/util/TreeSitterNative.kt JNI (verbatim marker; no free-text reason) 1 PACKAGE_JNI euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.kt JNI (verbatim marker; no free-text reason) 1 PACKAGE_JNI games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartNative.kt JNI (verbatim marker; no free-text reason) 1@@ -19,11 +18,6 @@ PACKAGE_JNI share/src/main/java/com/vayunmathur/share/protocol/ShareNativeDiscov PACKAGE_JNI vpn/src/main/java/com/vayunmathur/vpn/util/VpnNative.kt JNI (verbatim marker; no free-text reason) 1 PACKAGE_JNI web/src/main/java/com/vayunmathur/web/shields/ShieldsNative.kt JNI (verbatim marker; no free-text reason) 1 PACKAGE_JNI youpipe/src/main/java/com/vayunmathur/youpipe/nativeext/YouPipeNative.kt JNI (verbatim marker; no free-text reason) 1-RAW_ANIMATION games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/components/ArrowsBoard.kt an arrow travelling its route is imperative motion - one Animatable 1-RAW_ANIMATION games/arrows/src/main/java/com/vayunmathur/games/arrows/ui/components/ArrowsBoardDrawing.kt an arrow travelling its route is imperative motion - one Animatable 1-RAW_ANIMATION games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt the letter-flight is an imperative motion - letters fly from the 1-RAW_ANIMATION games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt AnimatedLetter carries the in-flight Animatable that WordGameScreen 1-RAW_SCAFFOLD music/src/main/java/com/vayunmathur/music/ui/NowPlayingScreen.kt nested now-playing scaffold 1 SCAFFOLD_SEARCH astronomy/src/main/java/com/vayunmathur/astronomy/ui/SearchScreen.kt full-bleed sky-map screen with TopAppBarOverlay chrome; no scaffold host for the catalog search field 1 SCAFFOLD_SEARCH calendar/src/main/java/com/vayunmathur/calendar/ui/HolidayCalendarsScreen.kt language-picker dialog-local search filter in this file; the screen's country search uses the scaffold search parameter 1 SCAFFOLD_SEARCH calendar/src/main/java/com/vayunmathur/calendar/ui/dialogs/TimezonePickerDialog.kt dialog-local timezone filter inside a picker dialog; no scaffold host 1@@ -93,4 +87,8 @@ SCREENSHOT_COVERAGE notes/src/main/java/com/vayunmathur/notes/Route.kt ExternalN SCREENSHOT_COVERAGE notes/src/main/java/com/vayunmathur/notes/Route.kt InkEditor: ink editor draws on Room-backed block state with a stylus canvas; no stateless slice for Layoutlib 1 SCREENSHOT_COVERAGE photos/src/main/java/com/vayunmathur/photos/Route.kt Map: MapLibre GL surface backed by live basemap tiles; Layoutlib has no GL surface or tile source to render 1 SCREENSHOT_COVERAGE photos/src/main/java/com/vayunmathur/photos/Route.kt SecureFolder: biometric/Keystore-gated vault grid whose thumbnails are decrypted with the vault password; no stateless Layoutlib slice 1+SCREENSHOT_COVERAGE taxi/src/main/java/com/vayunmathur/taxi/Route.kt Accounts: screen reads the Lyft token store and live payment methods from the provider; no stateless slice for Layoutlib 1+SCREENSHOT_COVERAGE taxi/src/main/java/com/vayunmathur/taxi/Route.kt CurrentRide: tab polls the Lyft provider for a live active ride and delegates to live tracking; no stateless slice for Layoutlib 1+SCREENSHOT_COVERAGE taxi/src/main/java/com/vayunmathur/taxi/Route.kt LyftSignIn: live phone/SMS sign-in with a per-session UUID and token-store persistence; no stateless slice for Layoutlib 1+SCREENSHOT_COVERAGE taxi/src/main/java/com/vayunmathur/taxi/Route.kt RideTracking: live ride screen polls status and driver location, renders the native map and starts the foreground tracking service; no stateless slice for Layoutlib 1 TOAST share/src/main/java/com/vayunmathur/share/platform/receive/ShareSaveActivity.kt no UI to host a snackbar. 1
taxi/AGENTS.md
diff --git a/taxi/AGENTS.md b/taxi/AGENTS.mdindex 5bc7c92a0a..92ea18249d 100644--- a/taxi/AGENTS.md+++ b/taxi/AGENTS.md@@ -8,7 +8,7 @@ _Install: ./install taxi (dev by default)._ - Entry files: MainActivity.kt, Route.kt, Navigation.kt - Deps: :library:network, :library:map, :library:image - Metadata: metadata_data/taxi.md (present)-- Rust: no / screenshotTest: no+- Rust: no / screenshotTest: yes ## Overview **Purpose:** US/CA ride-hailing aggregator — side-by-side Uber vs Lyft fare comparison, Lyft booking without the Lyft app, live tracking; address search with no Google Places/Play Services.@@ -21,7 +21,7 @@ _Install: ./install taxi (dev by default)._ **Gotchas:** - `ipc/` is NOT a closed package root — don't add more files there - Unofficial-provider APIs are brittle — isolate Uber/Lyft failures from each other and from the quote UI-- Screenshot tests are off for this module (`screenshotTest: no`) — verify ride flows on device+- Dialogs are `Route` destinations (`SignOutDialog`, `AddCardDialog`, `CancelRideDialog(rideId)`, `CancelResultDialog(rideId, outcome, message)` — `DialogPage()` entries in `ui/TaxiDialogEntries.kt`, stateless content under `ui/dialogs/`, results via `RESULT_*` keys in that file); the Lyft booking wizard in `ui/LyftBooking.kt` is a local multi-step dialog flow by exception marker. Screenshot captures in `src/screenshotTest` cover the ride tab and the dialog routes; the live/provider-backed routes are exempted per route in `Route.kt` ## Key files ### Root — entry + navigation@@ -65,7 +65,11 @@ _Install: ./install taxi (dev by default)._ - com/vayunmathur/taxi/ui/LyftSignInScreen.kt - com/vayunmathur/taxi/ui/UberSignInScreen.kt - com/vayunmathur/taxi/ui/UberConnectScreen.kt-- com/vayunmathur/taxi/ui/AddCardDialog.kt+- com/vayunmathur/taxi/ui/TaxiDialogEntries.kt+- com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt+- com/vayunmathur/taxi/ui/dialogs/SignOutDialog.kt+- com/vayunmathur/taxi/ui/dialogs/CancelRideDialog.kt+- com/vayunmathur/taxi/ui/dialogs/CancelResultDialog.kt - com/vayunmathur/taxi/ui/CurrentRideScreen.kt - com/vayunmathur/taxi/ui/RideTrackingScreen.kt - com/vayunmathur/taxi/ui/RideTrackingMap.kt
taxi/src/main/java/com/vayunmathur/taxi/Navigation.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/Navigation.kt b/taxi/src/main/java/com/vayunmathur/taxi/Navigation.ktindex 54ce55ba79..4ae016bf8d 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/Navigation.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/Navigation.kt@@ -19,6 +19,7 @@ import com.vayunmathur.taxi.ui.CurrentRideScreen import com.vayunmathur.taxi.ui.LyftSignInScreen import com.vayunmathur.taxi.ui.RideScreen import com.vayunmathur.taxi.ui.RideTrackingScreen+import com.vayunmathur.taxi.ui.dialogEntries @Composable fun Navigation(trackRideId: MutableState<String?>, bookingTrip: MutableState<BookingTrip?>) {@@ -49,11 +50,23 @@ fun Navigation(trackRideId: MutableState<String?>, bookingTrip: MutableState<Boo bottomBar = { BottomNavBar(backStack, pages, currentPage) }, ) { entry<Route.Ride>(metadata = SiblingPage()) { RideScreen(bookingTrip) }- entry<Route.CurrentRide>(metadata = SiblingPage()) { CurrentRideScreen() }+ entry<Route.CurrentRide>(metadata = SiblingPage()) {+ CurrentRideScreen(onCancelRideRequest = { backStack.add(Route.CancelRideDialog(it)) })+ } entry<Route.Accounts>(metadata = SiblingPage()) {- AccountsScreen(onConnectLyft = { backStack.add(Route.LyftSignIn) })+ AccountsScreen(+ onConnectLyft = { backStack.add(Route.LyftSignIn) },+ onSignOutRequest = { backStack.add(Route.SignOutDialog) },+ onAddCardRequest = { backStack.add(Route.AddCardDialog) },+ ) } entry<Route.LyftSignIn> { LyftSignInScreen(onBack = { backStack.pop() }) }- entry<Route.RideTracking> { route -> RideTrackingScreen(rideId = route.rideId) }+ entry<Route.RideTracking> { route ->+ RideTrackingScreen(+ rideId = route.rideId,+ onCancelRideRequest = { backStack.add(Route.CancelRideDialog(it)) },+ )+ }+ dialogEntries(backStack) } }
taxi/src/main/java/com/vayunmathur/taxi/Route.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/Route.kt b/taxi/src/main/java/com/vayunmathur/taxi/Route.ktindex d54f9a8380..daac4f6ad8 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/Route.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/Route.kt@@ -3,6 +3,10 @@ package com.vayunmathur.taxi import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable +// SCREENSHOT COVERAGE EXCEPTION: CurrentRide: tab polls the Lyft provider for a live active ride and delegates to live tracking; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: Accounts: screen reads the Lyft token store and live payment methods from the provider; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: LyftSignIn: live phone/SMS sign-in with a per-session UUID and token-store persistence; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: RideTracking: live ride screen polls status and driver location, renders the native map and starts the foreground tracking service; no stateless slice for Layoutlib /** Contract for route. */ @Serializable sealed interface Route : NavKey {@@ -16,4 +20,24 @@ sealed interface Route : NavKey { @Serializable data object LyftSignIn : Route /** Live tracking route for the ride identified by [rideId]. */ @Serializable data class RideTracking(val rideId: String) : Route++ /** Sign-out confirmation dialog destination for the Lyft account. */+ @Serializable data object SignOutDialog : Route++ /** Add-card dialog destination for the Lyft account. */+ @Serializable data object AddCardDialog : Route++ /** Cancel confirmation dialog destination for the ride identified by [rideId]. */+ @Serializable data class CancelRideDialog(val rideId: String) : Route++ /**+ * Cancel-result dialog destination for the ride identified by [rideId].+ * [outcome] is `done`, `failed` or `unsupported`; [message] carries the+ * provider message for the `failed` outcome.+ */+ @Serializable data class CancelResultDialog(+ val rideId: String,+ val outcome: String,+ val message: String,+ ) : Route }
taxi/src/main/java/com/vayunmathur/taxi/ui/AccountsScreen.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/AccountsScreen.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/AccountsScreen.ktindex aee259ae95..58178ec97b 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/AccountsScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/AccountsScreen.kt@@ -4,12 +4,9 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue@@ -23,7 +20,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card@@ -32,9 +28,9 @@ import com.vayunmathur.library.ui.ListItem import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.util.ResultEffect import com.vayunmathur.taxi.R import com.vayunmathur.library.ui.R as UiR-import com.vayunmathur.taxi.data.AddCardResult import com.vayunmathur.taxi.data.ChargeAccount import com.vayunmathur.taxi.data.PaymentActionResult import com.vayunmathur.taxi.data.PaymentMethodsResult@@ -43,7 +39,11 @@ import com.vayunmathur.taxi.data.lyft.LyftTokenStore import kotlinx.coroutines.launch @Composable-fun AccountsScreen(onConnectLyft: () -> Unit) {+fun AccountsScreen(+ onConnectLyft: () -> Unit,+ onSignOutRequest: () -> Unit = {},+ onAddCardRequest: () -> Unit = {},+) { val context = LocalContext.current val scope = rememberCoroutineScope() val provider = remember { LyftProvider(context.applicationContext) }@@ -54,13 +54,8 @@ fun AccountsScreen(onConnectLyft: () -> Unit) { var paymentError by remember { mutableStateOf<String?>(null) } // The id of the account a live set-default/remove is currently running against. var busyId by remember { mutableStateOf<String?>(null) }- // Add-card dialog state.- var showAddCard by remember { mutableStateOf(false) }- var addingCard by remember { mutableStateOf(false) }- var addCardError by remember { mutableStateOf<String?>(null) }- var showSignOut by remember { mutableStateOf(false) }- val addCardUnsupportedMessage = stringResource(R.string.add_card_unsupported)- var signingOut by remember { mutableStateOf(false) }+ // Sign-out and add-card are dialog routes (Route.SignOutDialog /+ // Route.AddCardDialog); they report back here so this screen reloads. suspend fun loadPayments() { loadingPayments = true@@ -77,6 +72,17 @@ fun AccountsScreen(onConnectLyft: () -> Unit) { loadingPayments = false } + ResultEffect<String>(RESULT_ACCOUNTS_CHANGED) { change ->+ if (change == "signed-out") {+ lyftSignedIn = false+ accounts = emptyList()+ paymentError = null+ } else {+ lyftSignedIn = LyftTokenStore(context.applicationContext).isSignedIn()+ if (lyftSignedIn) loadPayments()+ }+ }+ LaunchedEffect(Unit) { lyftSignedIn = LyftTokenStore(context.applicationContext).isSignedIn() if (lyftSignedIn) loadPayments()@@ -113,7 +119,7 @@ fun AccountsScreen(onConnectLyft: () -> Unit) { if (lyftSignedIn) { TextButton(- onClick = { showSignOut = true },+ onClick = onSignOutRequest, modifier = Modifier.fillMaxWidth(), ) { Text(stringResource(R.string.sign_out), color = MaterialTheme.colorScheme.error)@@ -162,10 +168,7 @@ fun AccountsScreen(onConnectLyft: () -> Unit) { if (lyftSignedIn && !loadingPayments) { Button(- onClick = {- addCardError = null- showAddCard = true- },+ onClick = onAddCardRequest, modifier = Modifier.fillMaxWidth(), ) { Text(stringResource(R.string.add_card))@@ -173,71 +176,6 @@ fun AccountsScreen(onConnectLyft: () -> Unit) { } } }-- if (showSignOut) {- AlertDialog(- onDismissRequest = { if (!signingOut) showSignOut = false },- title = { Text(stringResource(R.string.sign_out_title)) },- text = { Text(stringResource(R.string.sign_out_message)) },- confirmButton = {- TextButton(- enabled = !signingOut,- onClick = {- signingOut = true- scope.launch {- provider.signOut()- signingOut = false- showSignOut = false- lyftSignedIn = false- accounts = emptyList()- paymentError = null- }- },- ) {- Text(stringResource(R.string.sign_out), color = MaterialTheme.colorScheme.error)- }- },- dismissButton = {- TextButton(enabled = !signingOut, onClick = { showSignOut = false }) {- Text(stringResource(UiR.string.cancel))- }- },- )- }-- if (showAddCard) {- AddCardDialog(- adding = addingCard,- error = addCardError,- onDismiss = {- if (!addingCard) {- showAddCard = false- addCardError = null- }- },- onSubmit = { card, makeDefault ->- addingCard = true- addCardError = null- scope.launch {- when (val result = provider.addCard(card, makeDefault)) {- is AddCardResult.Success -> {- if (result.accounts != null) accounts = result.accounts else loadPayments()- addingCard = false- showAddCard = false- }- is AddCardResult.Failed -> {- addCardError = result.message- addingCard = false- }- AddCardResult.Unsupported -> {- addCardError = addCardUnsupportedMessage- addingCard = false- }- }- }- },- )- } } @Composable
taxi/src/main/java/com/vayunmathur/taxi/ui/CurrentRideScreen.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/CurrentRideScreen.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/CurrentRideScreen.ktindex 6a80efdc91..fea577209e 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/CurrentRideScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/CurrentRideScreen.kt@@ -28,7 +28,7 @@ import com.vayunmathur.taxi.network.lyft.LyftProvider * navigation or ride mutations happen here beyond the explicit Cancel button inside tracking. */ @Composable-fun CurrentRideScreen() {+fun CurrentRideScreen(onCancelRideRequest: (String) -> Unit = {}) { val context = LocalContext.current var rideId by remember { mutableStateOf<String?>(null) } var loading by remember { mutableStateOf(true) }@@ -45,7 +45,7 @@ fun CurrentRideScreen() { val id = rideId if (id != null) {- RideTrackingScreen(rideId = id)+ RideTrackingScreen(rideId = id, onCancelRideRequest = onCancelRideRequest) return }
taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.ktindex 8daa08356c..85d68d1ed0 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt@@ -1,5 +1,7 @@ package com.vayunmathur.taxi.ui +// DIALOG LOCAL EXCEPTION: multi-step Lyft booking wizard (payment fetch, picker, confirm, booking, dry-run/result) whose intermediate state is a non-serializable quote/places/charge-account set plus pending-ride persistence for process-death reconciliation; it has no route/result shape yet+ import android.Manifest import android.content.Context import android.content.pm.PackageManager
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 a07d6120f9..9db7fc4e50 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/RideTrackingScreen.kt@@ -4,12 +4,9 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll@@ -18,31 +15,26 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember-import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ExternalIntents import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.util.ResultEffect import com.vayunmathur.taxi.R-import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.taxi.data.ActiveRide-import com.vayunmathur.taxi.data.CancelResult import com.vayunmathur.taxi.data.DriverLocation import com.vayunmathur.taxi.data.RideStatusResult import com.vayunmathur.taxi.network.lyft.LyftProvider import com.vayunmathur.taxi.notifications.RideTrackingService import kotlinx.coroutines.delay-import kotlinx.coroutines.launch /** * Live tracking for one ride: the driver's position against the pickup and destination, the@@ -54,18 +46,30 @@ import kotlinx.coroutines.launch * only the explicit Cancel button does. */ @Composable-fun RideTrackingScreen(rideId: String) {+fun RideTrackingScreen(+ rideId: String,+ onCancelRideRequest: (String) -> Unit = {},+) { val context = LocalContext.current- val scope = rememberCoroutineScope() val provider = remember { LyftProvider(context.applicationContext) } var ride by remember { mutableStateOf<ActiveRide?>(null) } var liveLocation by remember { mutableStateOf<DriverLocation?>(null) } var error by remember { mutableStateOf<String?>(null) } var ended by remember { mutableStateOf(false) }- var confirmingCancel by remember { mutableStateOf(false) } var cancelling by remember { mutableStateOf(false) }- var cancelResult by remember { mutableStateOf<CancelResult?>(null) }+ // Cancel confirmation and its result are dialog routes+ // (Route.CancelRideDialog / Route.CancelResultDialog); the cancel+ // attempt reports back here so a confirmed cancel ends tracking.+ ResultEffect<String>(RESULT_RIDE_CANCEL_ATTEMPT) { encoded ->+ val outcome = encoded.substringBefore(':')+ cancelling = outcome == "started"+ // 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 (outcome == "done") ended = true+ } fun isDone() = ended || ride?.status?.isTerminal == true @@ -142,7 +146,7 @@ fun RideTrackingScreen(rideId: String) { ) if (!isDone()) { Button(- onClick = { confirmingCancel = true },+ onClick = { onCancelRideRequest(rideId) }, enabled = !cancelling, modifier = Modifier.fillMaxWidth(), ) {@@ -171,53 +175,4 @@ fun RideTrackingScreen(rideId: String) { } } }-- if (confirmingCancel) {- AlertDialog(- onDismissRequest = { confirmingCancel = false },- title = { Text(stringResource(R.string.cancel_ride_title)) },- text = { Text(stringResource(R.string.cancel_ride_message)) },- confirmButton = {- TextButton(onClick = {- confirmingCancel = false- cancelling = true- scope.launch {- val result = provider.cancelRide(rideId)- cancelResult = result- cancelling = false- // 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)- }- },- dismissButton = {- TextButton(onClick = { confirmingCancel = false }) {- Text(stringResource(R.string.keep_ride))- }- },- )- }-- cancelResult?.let { result ->- AlertDialog(- onDismissRequest = { cancelResult = null },- title = {- Text(- when (result) {- is CancelResult.Done -> stringResource(R.string.ride_cancelled)- is CancelResult.Failed -> stringResource(R.string.cancel_failed, result.message)- CancelResult.Unsupported -> stringResource(R.string.cancel_failed, "unsupported")- },- )- },- confirmButton = {- TextButton(onClick = { cancelResult = null }) { Text(stringResource(UiR.string.close)) }- },- )- } }
taxi/src/main/java/com/vayunmathur/taxi/ui/TaxiDialogEntries.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/TaxiDialogEntries.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/TaxiDialogEntries.ktnew file mode 100644index 0000000000..77c02c0c48--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/TaxiDialogEntries.kt@@ -0,0 +1,145 @@+package com.vayunmathur.taxi.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.util.DialogPage+import com.vayunmathur.library.util.EntryProviderScope+import com.vayunmathur.library.util.LocalNavResultRegistry+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.taxi.R+import com.vayunmathur.taxi.Route+import com.vayunmathur.taxi.data.AddCardResult+import com.vayunmathur.taxi.data.CancelResult+import com.vayunmathur.taxi.network.lyft.LyftProvider+import com.vayunmathur.taxi.ui.dialogs.AddCardDialog+import com.vayunmathur.taxi.ui.dialogs.CancelResultDialog+import com.vayunmathur.taxi.ui.dialogs.CancelRideDialog+import com.vayunmathur.taxi.ui.dialogs.SignOutDialog+import kotlinx.coroutines.launch++/** Result key: the Lyft account changed (signed out, or a card was added). */+const val RESULT_ACCOUNTS_CHANGED = "taxi.accounts-changed"++/**+ * Result key: a cancel attempt finished. The value is `<outcome>:<message>`+ * (`done`, `failed` or `unsupported`), matching `Route.CancelResultDialog`.+ */+const val RESULT_RIDE_CANCEL_ATTEMPT = "taxi.ride-cancel-attempt"++/**+ * Dialog destinations for taxi: every dialog is a [Route] with+ * `DialogPage()` metadata and its identity in the route arguments, never+ * `show…` state in the screen that asked. The entries own the provider+ * calls and report back through the result registry so the screen+ * underneath reloads.+ */+fun EntryProviderScope<Route>.dialogEntries(backStack: NavBackStack<Route>) {+ entry<Route.SignOutDialog>(metadata = DialogPage()) {+ SignOutDialogHost(backStack)+ }+ entry<Route.AddCardDialog>(metadata = DialogPage()) {+ AddCardDialogHost(backStack)+ }+ entry<Route.CancelRideDialog>(metadata = DialogPage()) { route ->+ CancelRideDialogHost(backStack, route)+ }+ entry<Route.CancelResultDialog>(metadata = DialogPage()) { route ->+ CancelResultDialog(+ outcome = route.outcome,+ message = route.message,+ onDismiss = { backStack.pop() },+ )+ }+}++@Composable+private fun SignOutDialogHost(backStack: NavBackStack<Route>) {+ val context = LocalContext.current+ val scope = rememberCoroutineScope()+ val provider = remember { LyftProvider(context.applicationContext) }+ val registry = LocalNavResultRegistry.current+ var signingOut by remember { mutableStateOf(false) }+ SignOutDialog(+ signingOut = signingOut,+ onDismiss = { backStack.pop() },+ onConfirm = {+ signingOut = true+ scope.launch {+ provider.signOut()+ registry.dispatchResult(RESULT_ACCOUNTS_CHANGED, "signed-out")+ backStack.pop()+ }+ },+ )+}++@Composable+private fun AddCardDialogHost(backStack: NavBackStack<Route>) {+ val context = LocalContext.current+ val scope = rememberCoroutineScope()+ val provider = remember { LyftProvider(context.applicationContext) }+ val registry = LocalNavResultRegistry.current+ val addCardUnsupportedMessage = stringResource(R.string.add_card_unsupported)+ var addingCard by remember { mutableStateOf(false) }+ var addCardError by remember { mutableStateOf<String?>(null) }+ AddCardDialog(+ adding = addingCard,+ error = addCardError,+ onDismiss = { if (!addingCard) backStack.pop() },+ onSubmit = { card, makeDefault ->+ addingCard = true+ addCardError = null+ scope.launch {+ when (val result = provider.addCard(card, makeDefault)) {+ is AddCardResult.Success -> {+ registry.dispatchResult(RESULT_ACCOUNTS_CHANGED, "card-added")+ backStack.pop()+ }+ is AddCardResult.Failed -> {+ addCardError = result.message+ addingCard = false+ }+ AddCardResult.Unsupported -> {+ addCardError = addCardUnsupportedMessage+ addingCard = false+ }+ }+ }+ },+ )+}++@Composable+private fun CancelRideDialogHost(+ backStack: NavBackStack<Route>,+ route: Route.CancelRideDialog,+) {+ val context = LocalContext.current+ val scope = rememberCoroutineScope()+ val provider = remember { LyftProvider(context.applicationContext) }+ val registry = LocalNavResultRegistry.current+ CancelRideDialog(+ onDismiss = { backStack.pop() },+ onConfirm = {+ scope.launch {+ registry.dispatchResult(RESULT_RIDE_CANCEL_ATTEMPT, "started:")+ val result = provider.cancelRide(route.rideId)+ val (outcome, message) =+ when (result) {+ is CancelResult.Done -> "done" to result.message+ is CancelResult.Failed -> "failed" to result.message+ CancelResult.Unsupported -> "unsupported" to ""+ }+ registry.dispatchResult(RESULT_RIDE_CANCEL_ATTEMPT, "$outcome:$message")+ backStack.pop()+ backStack.add(Route.CancelResultDialog(route.rideId, outcome, message))+ }+ },+ )+}
taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/AddCardDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.ktsimilarity index 99%rename from taxi/src/main/java/com/vayunmathur/taxi/ui/AddCardDialog.ktrename to taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.ktindex cb0dbd5bde..f2ab852154 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/AddCardDialog.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/AddCardDialog.kt@@ -1,4 +1,4 @@-package com.vayunmathur.taxi.ui+package com.vayunmathur.taxi.ui.dialogs import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column
taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelResultDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelResultDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelResultDialog.ktnew file mode 100644index 0000000000..3eee75c331--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelResultDialog.kt@@ -0,0 +1,36 @@+package com.vayunmathur.taxi.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.taxi.R++/**+ * Stateless cancel-outcome message for `Route.CancelResultDialog`.+ * [outcome] is `done`, `failed` or `unsupported`, as carried by the route.+ */+@Composable+fun CancelResultDialog(+ outcome: String,+ message: String,+ onDismiss: () -> Unit,+) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = {+ Text(+ when (outcome) {+ "done" -> stringResource(R.string.ride_cancelled)+ "failed" -> stringResource(R.string.cancel_failed, message)+ else -> stringResource(R.string.cancel_failed, "unsupported")+ },+ )+ },+ confirmButton = {+ TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.close)) }+ },+ )+}
taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelRideDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelRideDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelRideDialog.ktnew file mode 100644index 0000000000..8d071ecf05--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/CancelRideDialog.kt@@ -0,0 +1,35 @@+package com.vayunmathur.taxi.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.taxi.R++/**+ * Stateless cancel confirmation for `Route.CancelRideDialog`: the route+ * entry owns the provider cancel call and the result dialog that follows.+ */+@Composable+fun CancelRideDialog(+ onConfirm: () -> Unit,+ onDismiss: () -> Unit,+) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(stringResource(R.string.cancel_ride_title)) },+ text = { Text(stringResource(R.string.cancel_ride_message)) },+ confirmButton = {+ TextButton(onClick = onConfirm) {+ Text(stringResource(R.string.cancel_ride), color = MaterialTheme.colorScheme.error)+ }+ },+ dismissButton = {+ TextButton(onClick = onDismiss) {+ Text(stringResource(R.string.keep_ride))+ }+ },+ )+}
taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/SignOutDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/SignOutDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/SignOutDialog.ktnew file mode 100644index 0000000000..277d958f3a--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/dialogs/SignOutDialog.kt@@ -0,0 +1,37 @@+package com.vayunmathur.taxi.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.taxi.R++/**+ * Stateless sign-out confirmation for `Route.SignOutDialog`: the route+ * entry owns the provider sign-out, the busy state and popping itself.+ */+@Composable+fun SignOutDialog(+ signingOut: Boolean,+ onConfirm: () -> Unit,+ onDismiss: () -> Unit,+) {+ AlertDialog(+ onDismissRequest = { if (!signingOut) onDismiss() },+ title = { Text(stringResource(R.string.sign_out_title)) },+ text = { Text(stringResource(R.string.sign_out_message)) },+ confirmButton = {+ TextButton(enabled = !signingOut, onClick = onConfirm) {+ Text(stringResource(R.string.sign_out), color = MaterialTheme.colorScheme.error)+ }+ },+ dismissButton = {+ TextButton(enabled = !signingOut, onClick = onDismiss) {+ Text(stringResource(UiR.string.cancel))+ }+ },+ )+}
taxi/src/screenshotTest/kotlin/com/vayunmathur/taxi/ui/MetadataPreviews.kt
diff --git a/taxi/src/screenshotTest/kotlin/com/vayunmathur/taxi/ui/MetadataPreviews.kt b/taxi/src/screenshotTest/kotlin/com/vayunmathur/taxi/ui/MetadataPreviews.ktindex 0082f3fc20..3664687ff2 100644--- a/taxi/src/screenshotTest/kotlin/com/vayunmathur/taxi/ui/MetadataPreviews.kt+++ b/taxi/src/screenshotTest/kotlin/com/vayunmathur/taxi/ui/MetadataPreviews.kt@@ -27,6 +27,10 @@ import com.vayunmathur.taxi.data.Place import com.vayunmathur.taxi.data.Provider import com.vayunmathur.taxi.data.QuoteResult import com.vayunmathur.taxi.data.RideQuote+import com.vayunmathur.taxi.ui.dialogs.AddCardDialog+import com.vayunmathur.taxi.ui.dialogs.CancelResultDialog+import com.vayunmathur.taxi.ui.dialogs.CancelRideDialog+import com.vayunmathur.taxi.ui.dialogs.SignOutDialog /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"@@ -101,6 +105,42 @@ class MetadataPreviews { ) } }++ @PreviewTest+ @Preview(name = "3-sign-out-dialog", device = PHONE, group = "phone")+ @Composable+ fun Preview3SignOutDialog() {+ DynamicTheme(darkTheme = true) {+ SignOutDialog(signingOut = false, onConfirm = {}, onDismiss = {})+ }+ }++ @PreviewTest+ @Preview(name = "4-add-card-dialog", device = PHONE, group = "phone")+ @Composable+ fun Preview4AddCardDialog() {+ DynamicTheme(darkTheme = true) {+ AddCardDialog(adding = false, error = null, onDismiss = {}, onSubmit = { _, _ -> })+ }+ }++ @PreviewTest+ @Preview(name = "5-cancel-ride-dialog", device = PHONE, group = "phone")+ @Composable+ fun Preview5CancelRideDialog() {+ DynamicTheme(darkTheme = true) {+ CancelRideDialog(onConfirm = {}, onDismiss = {})+ }+ }++ @PreviewTest+ @Preview(name = "6-cancel-result-dialog", device = PHONE, group = "phone")+ @Composable+ fun Preview6CancelResultDialog() {+ DynamicTheme(darkTheme = true) {+ CancelResultDialog(outcome = "done", message = "", onDismiss = {})+ }+ } } /** Literals backing the Ride tab: a Ferry Building -> SFO trip with both fares compared. */
taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiLocScreenTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiLocScreenTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiLocScreenTest.ktindex d9fbb2fb99..f6f7bb15f2 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiLocScreenTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/Y3TaxiLocScreenTest.kt@@ -46,7 +46,7 @@ class Y3TaxiLocScreenTest { val shadow = Shadows.shadowOf(manager) shadow.setProviderEnabled(LocationManager.GPS_PROVIDER, true) val loc = Location(LocationManager.GPS_PROVIDER).apply {- latitude = 37.5; longitude = -122.5; time = System.currentTimeMillis()+ latitude = 37.5; longitude = -122.5; time = 1_700_000_000_000L } shadow.setLastKnownLocation(LocationManager.GPS_PROVIDER, loc) val here = LocationProvider.current(ctx)
taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiCardValidationTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiCardValidationTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiCardValidationTest.ktindex 01bc3be178..99db0dd971 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiCardValidationTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiCardValidationTest.kt@@ -8,6 +8,10 @@ import androidx.compose.ui.test.performTextInput import androidx.test.core.app.ApplicationProvider import com.vayunmathur.taxi.R import com.vayunmathur.taxi.data.NewCard+import com.vayunmathur.taxi.ui.dialogs.AddCardDialog+import com.vayunmathur.taxi.ui.dialogs.luhnValid+import com.vayunmathur.taxi.ui.dialogs.parseExpiry+import com.vayunmathur.taxi.ui.dialogs.validateCard import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse
taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3ScreensTest.kt
diff --git a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3ScreensTest.kt b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3ScreensTest.ktindex c7bc6cf767..a1b0d08ca4 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3ScreensTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3ScreensTest.kt@@ -118,12 +118,24 @@ class TaxiPass3ScreensTest { rule.onNodeWithText(text).assertExists() } ++ private fun setContentOnAccountsTab() {+ rule.setContent {+ com.vayunmathur.taxi.Navigation(+ trackRideId = remember { mutableStateOf(null) },+ bookingTrip = remember { mutableStateOf(null) },+ )+ }+ waitForText("Settings")+ rule.onNodeWithText("Settings").performClick()+ }+ // --- Accounts --- @Test fun accountsSignedOutShowsConnectPrompt() { var connect = 0- rule.setContent { AccountsScreen(onConnectLyft = { connect++ }) }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { AccountsScreen(onConnectLyft = { connect++ }) } } waitForText(str(R.string.payment_sign_in)) rule.onNodeWithText(str(R.string.provider_lyft)).assertIsDisplayed() rule.onNodeWithText(str(R.string.not_signed_in)).assertIsDisplayed()@@ -137,7 +149,7 @@ class TaxiPass3ScreensTest { seedSignedIn() http.on("/chargeaccounts") { http.raw(200, ACCOUNTS_JSON, url = it.url) } http.on("/charge-accounts-multi-provider") { http.raw(200, ACCOUNTS_JSON, url = it.url) }- rule.setContent { AccountsScreen(onConnectLyft = {}) }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { AccountsScreen(onConnectLyft = {}) } } waitForText("Visa ••1111") rule.onNodeWithText("Mastercard ••2222").assertIsDisplayed() rule.onNodeWithText(str(R.string.payment_default)).assertIsDisplayed()@@ -156,7 +168,7 @@ class TaxiPass3ScreensTest { fun accountsPaymentsErrorShowsMessage() { seedSignedIn() http.on("/chargeaccounts") { http.raw(500, "kaput", "text/plain", it.url) }- rule.setContent { AccountsScreen(onConnectLyft = {}) }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { AccountsScreen(onConnectLyft = {}) } } val expected = str(R.string.payment_methods_error, "Lyft returned HTTP 500: kaput") waitForText(expected) rule.onNodeWithText(expected).assertIsDisplayed()@@ -167,7 +179,7 @@ class TaxiPass3ScreensTest { seedSignedIn() http.on("/chargeaccounts") { http.raw(200, ACCOUNTS_JSON, url = it.url) } http.performHandler = { http.simple(200, "", it.url) }- rule.setContent { AccountsScreen(onConnectLyft = {}) }+ setContentOnAccountsTab() waitForText("Visa ••1111") rule.onNodeWithText(str(R.string.sign_out)).performClick() waitForText(str(R.string.sign_out_title))@@ -186,7 +198,7 @@ class TaxiPass3ScreensTest { } http.on("api.stripe.com") { http.raw(200, """{"id":"tok_new"}""", url = it.url) } http.on("/charge-accounts-multi-provider") { http.raw(200, ACCOUNTS_JSON, url = it.url) }- rule.setContent { AccountsScreen(onConnectLyft = {}) }+ setContentOnAccountsTab() waitForText(str(R.string.add_card)) rule.onNode( androidx.compose.ui.test.hasText(str(R.string.add_card)) and@@ -216,7 +228,7 @@ class TaxiPass3ScreensTest { } http.on("api.stripe.com") { http.raw(200, """{"id":"tok_new"}""", url = it.url) } http.on("/charge-accounts-multi-provider") { http.raw(200, ACCOUNTS_JSON, url = it.url) }- rule.setContent { AccountsScreen(onConnectLyft = {}) }+ setContentOnAccountsTab() waitForText(str(R.string.add_card)) rule.onNode( androidx.compose.ui.test.hasText(str(R.string.add_card)) and
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 f8d75fe207..457ddc66f5 100644--- a/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt+++ b/taxi/src/test/java/com/vayunmathur/taxi/ui/TaxiPass3TrackingScreenTest.kt@@ -1,6 +1,8 @@ package com.vayunmathur.taxi.ui import android.content.Context+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText@@ -71,6 +73,16 @@ class TaxiPass3TrackingScreenTest { rule.onNodeWithText(text).assertExists() } ++ private fun setContentTrackingViaNavigation() {+ rule.setContent {+ com.vayunmathur.taxi.Navigation(+ trackRideId = remember { mutableStateOf<String?>("r1") },+ bookingTrip = remember { mutableStateOf(null) },+ )+ }+ }+ private fun rideJson(status: String): String = """{"ride":{"ride_id":"r1","status":"$status", "driver":{"first_name":"Jo","last_name":"Smith","phone_number":"+15550001","rating":4.9},@@ -85,7 +97,7 @@ class TaxiPass3TrackingScreenTest { http.on("/driver-location") { http.raw(200, """{"location":{"lat":37.71,"lng":-122.41}}""", url = it.url) }- rule.setContent { RideTrackingScreen(rideId = "r1") }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { RideTrackingScreen(rideId = "r1") } } waitForText(str(R.string.ride_complete)) rule.onNodeWithText("Jo Smith").assertIsDisplayed() // Terminal rides offer no cancel.@@ -99,7 +111,7 @@ class TaxiPass3TrackingScreenTest { http.raw(200, """{"location":{"lat":37.71,"lng":-122.41}}""", url = it.url) } http.on("/cancel") { http.raw(200, "Cancelled with fee", "text/plain", it.url) }- rule.setContent { RideTrackingScreen(rideId = "r1") }+ setContentTrackingViaNavigation() waitForText(str(R.string.cancel_ride)) rule.onNodeWithText(str(R.string.cancel_ride)).performClick() waitForText(str(R.string.cancel_ride_title))@@ -119,7 +131,7 @@ class TaxiPass3TrackingScreenTest { 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") }+ setContentTrackingViaNavigation() waitForText(str(R.string.cancel_ride)) rule.onNodeWithText(str(R.string.cancel_ride)).performClick() waitForText(str(R.string.cancel_ride_title))@@ -141,7 +153,7 @@ class TaxiPass3TrackingScreenTest { http.on("/driver-location") { http.raw(200, """{"location":{"lat":37.71,"lng":-122.41}}""", url = it.url) }- rule.setContent { RideTrackingScreen(rideId = "r1") }+ setContentTrackingViaNavigation() waitForText(str(R.string.cancel_ride)) rule.onNodeWithText(str(R.string.cancel_ride)).performClick() waitForText(str(R.string.keep_ride))@@ -167,7 +179,7 @@ class TaxiPass3TrackingScreenTest { http.raw(200, rideJson("approaching"), url = it.url) } }- rule.setContent { RideTrackingScreen(rideId = "r1") }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { RideTrackingScreen(rideId = "r1") } } // The transient failure must not end tracking: the next poll recovers // and the ride renders with cancel still offered. waitForText("Jo Smith")@@ -179,7 +191,7 @@ class TaxiPass3TrackingScreenTest { http.on("/v1/activeride") { http.raw(500, "kaput", "text/plain", it.url) } http.on("/v1/rides/") { http.raw(500, "kaput", "text/plain", it.url) } http.on("/driver-location") { http.raw(500, "x", "text/plain", it.url) }- rule.setContent { RideTrackingScreen(rideId = "r1") }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { RideTrackingScreen(rideId = "r1") } } // Active fails with an error, so the screen keeps polling and shows // the error - it settles out of its initial state without crashing // (loading or error, never a stuck spinner assertion here).@@ -201,7 +213,7 @@ class TaxiPass3TrackingScreenTest { http.on("/driver-location") { http.raw(200, """{"location":{"lat":37.71,"lng":-122.41}}""", url = it.url) }- rule.setContent { CurrentRideScreen() }+ rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides remember { com.vayunmathur.library.util.NavResultRegistry() }) { CurrentRideScreen() } } waitForText(str(R.string.status_arrived)) } }