-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into es-map-stop-tap
- Loading branch information
Showing
18 changed files
with
484 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
iosApp/iosApp/Pages/StopDetails/StopDetailsFilteredRouteView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// StopDetailsFilteredRouteView.swift | ||
// iosApp | ||
// | ||
// Created by Horn, Melody on 2024-04-05. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import shared | ||
import SwiftUI | ||
|
||
struct StopDetailsFilteredRouteView: View { | ||
let patternsByStop: PatternsByStop | ||
let now: Instant | ||
@Binding var filter: StopDetailsFilter? | ||
|
||
struct RowData { | ||
let tripId: String | ||
let headsign: String | ||
let formatted: PatternsByHeadsign.Format | ||
|
||
init?(trip: UpcomingTrip, route: Route, expectedDirection: Int32?, now: Instant) { | ||
if trip.trip.directionId != expectedDirection { | ||
return nil | ||
} | ||
|
||
tripId = trip.trip.id | ||
headsign = trip.trip.headsign | ||
formatted = PatternsByHeadsign( | ||
route: route, headsign: headsign, patterns: [], upcomingTrips: [trip], alertsHere: nil | ||
).format(now: now) | ||
|
||
if !(formatted is PatternsByHeadsign.FormatSome) { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
let rows: [RowData] | ||
|
||
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 | ||
|
||
let expectedDirection: Int32? = filter?.directionId | ||
rows = patternsByStop.allUpcomingTrips().compactMap { | ||
RowData(trip: $0, route: patternsByStop.route, expectedDirection: expectedDirection, now: now) | ||
} | ||
} | ||
|
||
var body: some View { | ||
Button(action: { filter = nil }, label: { Text("Clear Filter") }) | ||
List { | ||
RoutePillSection(route: patternsByStop.route) { | ||
ForEach(rows, id: \.tripId) { row in | ||
HeadsignRowView(headsign: row.headsign, predictions: row.formatted) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
iosApp/iosAppTests/Pages/StopDetails/StopDetailsFilteredRouteViewTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// StopDetailsFilteredRouteViewTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Horn, Melody on 2024-04-09. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
@testable import iosApp | ||
import shared | ||
import SwiftUI | ||
import ViewInspector | ||
import XCTest | ||
|
||
final class StopDetailsFilteredRouteViewTests: XCTestCase { | ||
private func testData() -> (departures: StopDetailsDepartures, routeId: String, now: Instant) { | ||
let objects = ObjectCollectionBuilder() | ||
let route = objects.route() | ||
let stop = objects.stop { _ in } | ||
|
||
let patternNorth = objects.routePattern(route: route) { pattern in | ||
pattern.directionId = 0 | ||
pattern.representativeTrip { $0.headsign = "North" } | ||
} | ||
let patternSouth = objects.routePattern(route: route) { pattern in | ||
pattern.directionId = 1 | ||
pattern.representativeTrip { $0.headsign = "South" } | ||
} | ||
|
||
let now = Date.now | ||
|
||
let tripNorth = objects.trip(routePattern: patternNorth) | ||
let predictionNorth = objects.prediction { | ||
$0.trip = tripNorth | ||
$0.departureTime = now.toKotlinInstant() | ||
} | ||
let tripSouth = objects.trip(routePattern: patternSouth) | ||
let predictionSouth = objects.prediction { | ||
$0.trip = tripSouth | ||
$0.departureTime = now.toKotlinInstant() | ||
} | ||
|
||
let patternsByStop = PatternsByStop(route: route, stop: stop, patternsByHeadsign: [ | ||
.init(route: route, headsign: "North", patterns: [patternNorth], upcomingTrips: [objects.upcomingTrip(prediction: predictionNorth)], alertsHere: nil), | ||
.init(route: route, headsign: "South", patterns: [patternSouth], upcomingTrips: [objects.upcomingTrip(prediction: predictionSouth)], alertsHere: nil), | ||
]) | ||
|
||
let departures = StopDetailsDepartures(routes: [patternsByStop]) | ||
|
||
return (departures: departures, routeId: route.id, now: now.toKotlinInstant()) | ||
} | ||
|
||
func testAppliesFilter() throws { | ||
let (departures: departures, routeId: routeId, now: now) = testData() | ||
|
||
let sut = StopDetailsFilteredRouteView( | ||
departures: departures, | ||
now: now, | ||
filter: .constant(.init(routeId: routeId, directionId: 0)) | ||
) | ||
|
||
XCTAssertNotNil(try sut.inspect().find(text: "North")) | ||
XCTAssertNil(try? sut.inspect().find(text: "South")) | ||
} | ||
|
||
func testClearsFilter() throws { | ||
let (departures: departures, routeId: routeId, now: now) = testData() | ||
|
||
let filter = Binding<StopDetailsFilter?>(wrappedValue: .init(routeId: routeId, directionId: 1)) | ||
|
||
let sut = StopDetailsFilteredRouteView(departures: departures, now: now, filter: filter) | ||
|
||
try sut.inspect().find(button: "Clear Filter").tap() | ||
|
||
XCTAssertNil(filter.wrappedValue) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
iosApp/iosAppTests/Pages/StopDetails/StopDetailsRouteViewTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// StopDetailsRouteViewTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Horn, Melody on 2024-04-09. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
@testable import iosApp | ||
import shared | ||
import SwiftUI | ||
import ViewInspector | ||
import XCTest | ||
|
||
final class StopDetailsRouteViewTests: XCTestCase { | ||
func testSetFilter() throws { | ||
let objects = ObjectCollectionBuilder() | ||
let route = objects.route() | ||
let stop = objects.stop { _ in } | ||
|
||
let now = Date.now.toKotlinInstant() | ||
|
||
let filter = Binding<StopDetailsFilter?>(wrappedValue: nil) | ||
|
||
let northPattern = objects.routePattern(route: route) { $0.directionId = 0 } | ||
let southPattern = objects.routePattern(route: route) { $0.directionId = 1 } | ||
let patternsByHeadsignNorth = PatternsByHeadsign(route: route, headsign: "North", patterns: [northPattern], upcomingTrips: nil, alertsHere: nil) | ||
let patternsByHeadsignSouth = PatternsByHeadsign(route: route, headsign: "South", patterns: [southPattern], upcomingTrips: nil, alertsHere: nil) | ||
let patternsByStop = PatternsByStop(route: route, stop: stop, patternsByHeadsign: [patternsByHeadsignNorth, patternsByHeadsignSouth]) | ||
let sut = StopDetailsRouteView(patternsByStop: patternsByStop, now: now, filter: filter) | ||
|
||
XCTAssertNil(filter.wrappedValue) | ||
try sut.inspect().find(button: "North").tap() | ||
XCTAssertEqual(filter.wrappedValue, .init(routeId: route.id, directionId: 0)) | ||
try sut.inspect().find(button: "South").tap() | ||
XCTAssertEqual(filter.wrappedValue, .init(routeId: route.id, directionId: 1)) | ||
} | ||
} |
Oops, something went wrong.