Skip to content

Commit

Permalink
Merge branch 'main' into es-combined-prediction-missing-vehicle
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaSimon authored Jan 2, 2025
2 parents 98182fa + ea5c43f commit c2074cb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,12 +122,59 @@ class StopDetailsRouteViewTest {
),
now = now,
pinned = false,
onPin = {}
onPin = {},
updateStopFilter = {}
)
}

composeTestRule.onNodeWithText("Sample Route").assertExists()
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -31,8 +38,9 @@ fun StopDetailsRouteView(
patternsByStop,
false,
now,
TripInstantDisplay.Context.StopDetailsUnfiltered
) {}
TripInstantDisplay.Context.StopDetailsUnfiltered,
::onTappedPatterns
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ fun StopDetailsRoutesView(
patternsByStop,
now,
pinned = pinnedRoutes.contains(patternsByStop.routeIdentifier),
onPin = pinRoute
onPin = pinRoute,
updateStopFilter
)
}
}
Expand Down

0 comments on commit c2074cb

Please sign in to comment.