Skip to content

Commit

Permalink
fix: show alert instead of trips if both exist (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
boringcactus authored Apr 11, 2024
1 parent 2b54ead commit 671b0a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ data class PatternsByHeadsign(
}

fun format(now: Instant): Format {
val alert = alertsHere?.firstOrNull()
if (alert != null) return Format.NoService(alert)
if (this.upcomingTrips == null) return Format.Loading
val tripsToShow =
upcomingTrips
Expand All @@ -138,12 +140,7 @@ data class PatternsByHeadsign(
(this.route.type.isSubway() && it.format is UpcomingTrip.Format.Schedule)
}
.take(2)
if (tripsToShow.isEmpty()) {
this.alertsHere?.firstOrNull()?.let {
return Format.NoService(it)
}
return Format.None
}
if (tripsToShow.isEmpty()) return Format.None
return Format.Some(tripsToShow)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ class PatternsByHeadsignTest {
)
}

@Test
fun `formats as alert with trip and alert`() {
val now = Clock.System.now()

val objects = ObjectCollectionBuilder()
val route = objects.route()

val trip = objects.trip()
val prediction =
objects.prediction {
this.trip = trip
departureTime = now + 1.minutes
}
val upcomingTrip = objects.upcomingTrip(prediction)

val alert = objects.alert {}

assertEquals(
PatternsByHeadsign.Format.NoService(alert),
PatternsByHeadsign(route, "", emptyList(), listOf(upcomingTrip), listOf(alert))
.format(now)
)
}

@Test
fun `formats as none with no trips and no alert`() {
val now = Clock.System.now()
Expand Down

0 comments on commit 671b0a8

Please sign in to comment.