Skip to content

Commit

Permalink
filter to route in FilteredRouteView constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
boringcactus committed Apr 10, 2024
1 parent 9a431f7 commit 769914b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ struct StopDetailsFilteredRouteView: View {

let rows: [RowData]

init(patternsByStop: PatternsByStop, now: Instant, filter: Binding<StopDetailsFilter?>) {
init(departures: StopDetailsDepartures, now: Instant, filter filterBinding: Binding<StopDetailsFilter?>) {
_filter = filterBinding
let filter = filterBinding.wrappedValue
let patternsByStop = departures.routes.first(where: { $0.route.id == filter?.routeId })!
self.patternsByStop = patternsByStop
self.now = now
_filter = filter

let expectedDirection: Int32? = filter.wrappedValue?.directionId
let expectedDirection: Int32? = filter?.directionId
rows = patternsByStop.allUpcomingTrips().compactMap {
RowData(trip: $0, route: patternsByStop.route, expectedDirection: expectedDirection, now: now)
}
Expand Down
3 changes: 1 addition & 2 deletions iosApp/iosApp/Pages/StopDetails/StopDetailsRoutesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ struct StopDetailsRoutesView: View {

var body: some View {
if let filter {
let selectedData = departures.routes.first(where: { $0.route.id == filter.routeId })!
StopDetailsFilteredRouteView(patternsByStop: selectedData, now: now, filter: $filter)
StopDetailsFilteredRouteView(departures: departures, now: now, filter: $filter)
} else {
List(departures.routes, id: \.route.id) { patternsByStop in
StopDetailsRouteView(patternsByStop: patternsByStop, now: now, filter: $filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ViewInspector
import XCTest

final class StopDetailsFilteredRouteViewTests: XCTestCase {
private func testData() -> (patternsByStop: PatternsByStop, routeId: String, now: Instant) {
private func testData() -> (departures: StopDetailsDepartures, routeId: String, now: Instant) {
let objects = ObjectCollectionBuilder()
let route = objects.route()
let stop = objects.stop { _ in }
Expand Down Expand Up @@ -45,14 +45,16 @@ final class StopDetailsFilteredRouteViewTests: XCTestCase {
.init(route: route, headsign: "South", patterns: [patternSouth], upcomingTrips: [objects.upcomingTrip(prediction: predictionSouth)], alertsHere: nil),
])

return (patternsByStop: patternsByStop, routeId: route.id, now: now.toKotlinInstant())
let departures = StopDetailsDepartures(routes: [patternsByStop])

return (departures: departures, routeId: route.id, now: now.toKotlinInstant())
}

func testAppliesFilter() throws {
let (patternsByStop: patternsByStop, routeId: routeId, now: now) = testData()
let (departures: departures, routeId: routeId, now: now) = testData()

let sut = StopDetailsFilteredRouteView(
patternsByStop: patternsByStop,
departures: departures,
now: now,
filter: .constant(.init(routeId: routeId, directionId: 0))
)
Expand All @@ -62,11 +64,11 @@ final class StopDetailsFilteredRouteViewTests: XCTestCase {
}

func testClearsFilter() throws {
let (patternsByStop: patternsByStop, routeId: routeId, now: now) = testData()
let (departures: departures, routeId: routeId, now: now) = testData()

let filter = Binding<StopDetailsFilter?>(wrappedValue: .init(routeId: routeId, directionId: 1))

let sut = StopDetailsFilteredRouteView(patternsByStop: patternsByStop, now: now, filter: filter)
let sut = StopDetailsFilteredRouteView(departures: departures, now: now, filter: filter)

try sut.inspect().find(button: "Clear Filter").tap()

Expand Down

0 comments on commit 769914b

Please sign in to comment.