-
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.
- Loading branch information
1 parent
e40b3b6
commit 66582bc
Showing
6 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
// | ||
// 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() -> (patternsByStop: PatternsByStop, 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), | ||
]) | ||
|
||
return (patternsByStop: patternsByStop, routeId: route.id, now: now.toKotlinInstant()) | ||
} | ||
|
||
func testAppliesFilter() throws { | ||
let (patternsByStop: patternsByStop, routeId: routeId, now: now) = testData() | ||
|
||
let sut = StopDetailsFilteredRouteView( | ||
patternsByStop: patternsByStop, | ||
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 (patternsByStop: patternsByStop, routeId: routeId, now: now) = testData() | ||
|
||
let filter = Binding<StopDetailsFilter?>(wrappedValue: .init(routeId: routeId, directionId: 1)) | ||
|
||
let sut = StopDetailsFilteredRouteView(patternsByStop: patternsByStop, 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)) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
iosApp/iosAppTests/Pages/StopDetails/StopDetailsRoutesViewTests.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,50 @@ | ||
// | ||
// StopDetailsRoutesViewTests.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 StopDetailsRoutesViewTests: XCTestCase { | ||
private func testData() -> (departures: StopDetailsDepartures, routeId: String) { | ||
let objects = ObjectCollectionBuilder() | ||
let route = objects.route() | ||
let stop = objects.stop { _ in } | ||
let wrongRoute = objects.route() | ||
|
||
let departures = StopDetailsDepartures(routes: [ | ||
PatternsByStop(route: route, stop: stop, patternsByHeadsign: []), | ||
PatternsByStop(route: wrongRoute, stop: stop, patternsByHeadsign: []), | ||
]) | ||
|
||
return (departures: departures, routeId: route.id) | ||
} | ||
|
||
func testShowsListWithoutFilter() throws { | ||
let (departures: departures, routeId: _) = testData() | ||
|
||
let sut = StopDetailsRoutesView(departures: departures, now: Date.now.toKotlinInstant(), filter: .constant(nil)) | ||
|
||
XCTAssertNotNil(try sut.inspect().list()) | ||
XCTAssertNil(try? sut.inspect().find(StopDetailsFilteredRouteView.self)) | ||
} | ||
|
||
func testShowsFilteredWithFilter() throws { | ||
let (departures: departures, routeId: routeId) = testData() | ||
|
||
let filter = StopDetailsFilter(routeId: routeId, directionId: 0) | ||
let sut = StopDetailsRoutesView(departures: departures, now: Date.now.toKotlinInstant(), filter: .constant(filter)) | ||
|
||
let actualView = try sut.inspect().find(StopDetailsFilteredRouteView.self).actualView() | ||
XCTAssertEqual(actualView.filter, filter) | ||
XCTAssertEqual(actualView.patternsByStop, departures.routes[0]) | ||
XCTAssertNil(try? sut.inspect().list()) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
iosApp/iosAppTests/Utils/SheetNavigationStackEntryTests.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,54 @@ | ||
// | ||
// SheetNavigationStackEntryTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Horn, Melody on 2024-04-09. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
@testable import iosApp | ||
import shared | ||
import XCTest | ||
|
||
final class SheetNavigationStackEntryTests: XCTestCase { | ||
func testLastFilterEmpty() throws { | ||
var stack: [SheetNavigationStackEntry] = [] | ||
|
||
XCTAssertNil(stack.lastStopDetailsFilter) | ||
|
||
stack.lastStopDetailsFilter = .init(routeId: "A", directionId: 1) | ||
|
||
XCTAssertEqual(stack, []) | ||
} | ||
|
||
func testLastFilterShallow() throws { | ||
let stop = ObjectCollectionBuilder.Single.shared.stop { _ in } | ||
var stack: [SheetNavigationStackEntry] = [.stopDetails(stop, nil)] | ||
|
||
XCTAssertNil(stack.lastStopDetailsFilter) | ||
|
||
stack.lastStopDetailsFilter = .init(routeId: "A", directionId: 1) | ||
|
||
XCTAssertEqual(stack, [.stopDetails(stop, .init(routeId: "A", directionId: 1))]) | ||
XCTAssertEqual(stack.lastStopDetailsFilter, .init(routeId: "A", directionId: 1)) | ||
|
||
stack.lastStopDetailsFilter = nil | ||
|
||
XCTAssertEqual(stack, [.stopDetails(stop, nil)]) | ||
XCTAssertEqual(stack.lastStopDetailsFilter, nil) | ||
} | ||
|
||
func testLastFilterDeep() throws { | ||
let stop = ObjectCollectionBuilder.Single.shared.stop { _ in } | ||
let otherStop = ObjectCollectionBuilder.Single.shared.stop { _ in } | ||
let previousEntry = SheetNavigationStackEntry.stopDetails(otherStop, .init(routeId: "A", directionId: 1)) | ||
var stack: [SheetNavigationStackEntry] = [previousEntry, .stopDetails(stop, .init(routeId: "B", directionId: 0))] | ||
|
||
XCTAssertEqual(stack.lastStopDetailsFilter, .init(routeId: "B", directionId: 0)) | ||
|
||
stack.lastStopDetailsFilter = nil | ||
|
||
XCTAssertEqual(stack, [previousEntry, .stopDetails(stop, nil)]) | ||
XCTAssertEqual(stack.lastStopDetailsFilter, nil) | ||
} | ||
} |
Oops, something went wrong.