Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Android): filter stop details on headsign tap #613

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading