diff --git a/androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteViewTest.kt b/androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteViewTest.kt index 4b5b42f06..26bc60420 100644 --- a/androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteViewTest.kt +++ b/androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteViewTest.kt @@ -2,13 +2,16 @@ package com.mbta.tid.mbta_app.android.stopDetails import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick import com.mbta.tid.mbta_app.model.LocationType import com.mbta.tid.mbta_app.model.NearbyStaticData import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder import com.mbta.tid.mbta_app.model.PatternsByStop import com.mbta.tid.mbta_app.model.RealtimePatterns import com.mbta.tid.mbta_app.model.RouteType +import com.mbta.tid.mbta_app.model.StopDetailsFilter import com.mbta.tid.mbta_app.model.UpcomingTrip +import kotlin.test.assertEquals import kotlin.time.Duration.Companion.minutes import kotlinx.datetime.Instant import org.junit.Rule @@ -119,7 +122,8 @@ class StopDetailsRouteViewTest { ), now = now, pinned = false, - onPin = {} + onPin = {}, + updateStopFilter = {} ) } @@ -127,4 +131,50 @@ class StopDetailsRouteViewTest { composeTestRule.onNodeWithText("Sample Headsign").assertExists() composeTestRule.onNodeWithText("1 min").assertExists() } + + @Test + fun testUpdatesStopFilter() { + var updatedStopFilter: StopDetailsFilter? = null + composeTestRule.setContent { + StopDetailsRouteView( + patternsByStop = + PatternsByStop( + route, + stop, + listOf( + RealtimePatterns.ByHeadsign( + staticData = + NearbyStaticData.StaticPatterns.ByHeadsign( + route, + trip.headsign, + line, + listOf(routePatternOne, routePatternTwo), + stopIds = setOf(stop.id), + ), + upcomingTripsMap = + mapOf( + RealtimePatterns.UpcomingTripKey.ByRoutePattern( + route.id, + trip.routePatternId, + stop.id, + ) to listOf(UpcomingTrip(trip, prediction)) + ), + parentStopId = stop.id, + alertsHere = emptyList(), + alertsDownstream = emptyList(), + hasSchedulesTodayByPattern = null, + allDataLoaded = false + ) + ) + ), + now = now, + pinned = false, + onPin = {}, + updateStopFilter = { updatedStopFilter = it } + ) + } + + composeTestRule.onNodeWithText("Sample Headsign").performClick() + assertEquals(StopDetailsFilter(route.id, trip.directionId), updatedStopFilter) + } } diff --git a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteView.kt b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteView.kt index d11bbbf75..224cd19d6 100644 --- a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteView.kt +++ b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRouteView.kt @@ -5,6 +5,8 @@ import com.mbta.tid.mbta_app.android.component.LineCard import com.mbta.tid.mbta_app.android.component.RouteCard import com.mbta.tid.mbta_app.android.component.StopDeparturesSummaryList import com.mbta.tid.mbta_app.model.PatternsByStop +import com.mbta.tid.mbta_app.model.RealtimePatterns +import com.mbta.tid.mbta_app.model.StopDetailsFilter import com.mbta.tid.mbta_app.model.TripInstantDisplay import kotlinx.datetime.Instant @@ -13,16 +15,21 @@ fun StopDetailsRouteView( patternsByStop: PatternsByStop, now: Instant, pinned: Boolean, - onPin: (String) -> Unit + onPin: (String) -> Unit, + updateStopFilter: (StopDetailsFilter?) -> Unit ) { + fun onTappedPatterns(patterns: RealtimePatterns) { + updateStopFilter(StopDetailsFilter(patternsByStop.routeIdentifier, patterns.directionId())) + } if (patternsByStop.line != null) { LineCard(patternsByStop.line!!, patternsByStop.routes, pinned, onPin) { StopDeparturesSummaryList( patternsByStop, condenseHeadsignPredictions = patternsByStop.routes.size > 1, now, - TripInstantDisplay.Context.StopDetailsUnfiltered - ) {} + TripInstantDisplay.Context.StopDetailsUnfiltered, + ::onTappedPatterns + ) } } else { val route = patternsByStop.routes.firstOrNull() ?: return @@ -31,8 +38,9 @@ fun StopDetailsRouteView( patternsByStop, false, now, - TripInstantDisplay.Context.StopDetailsUnfiltered - ) {} + TripInstantDisplay.Context.StopDetailsUnfiltered, + ::onTappedPatterns + ) } } } diff --git a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRoutesView.kt b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRoutesView.kt index 4e6d21ecd..b50697bb4 100644 --- a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRoutesView.kt +++ b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/stopDetails/StopDetailsRoutesView.kt @@ -49,7 +49,8 @@ fun StopDetailsRoutesView( patternsByStop, now, pinned = pinnedRoutes.contains(patternsByStop.routeIdentifier), - onPin = pinRoute + onPin = pinRoute, + updateStopFilter ) } }