-
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.
test: Add test for stop page changing
- Loading branch information
Showing
7 changed files
with
134 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// InspectionEmissary.swift | ||
// iosAppTests | ||
// | ||
// This is used with ViewInspector as recommended in their docs. | ||
// See https://github.com/nalexn/ViewInspector/blob/0.9.11/guide.md#approach-2 | ||
// | ||
// Created by Simon, Emma on 4/10/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import iosApp | ||
import ViewInspector | ||
|
||
extension Inspection: InspectionEmissary {} |
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,43 @@ | ||
// | ||
// HomeMapViewTest.swift | ||
// iosAppTests | ||
// | ||
// Created by Simon, Emma on 4/10/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
@testable import iosApp | ||
import shared | ||
import SwiftPhoenixClient | ||
import SwiftUI | ||
import ViewInspector | ||
import XCTest | ||
@_spi(Experimental) import MapboxMaps | ||
|
||
final class HomeMapViewTest: XCTestCase { | ||
override func setUp() { | ||
executionTimeAllowance = 60 | ||
} | ||
|
||
func testAppears() throws { | ||
let viewportProvider: ViewportProvider = .init(viewport: .followPuck(zoom: 1)) | ||
let navStack: Binding<[SheetNavigationStackEntry]> = .init(wrappedValue: []) | ||
let sheetHeight: Binding<CGFloat> = .constant(100) | ||
|
||
var sut = HomeMapView( | ||
alertsFetcher: .init(socket: MockSocket()), | ||
globalFetcher: .init(backend: IdleBackend()), | ||
nearbyFetcher: .init(backend: IdleBackend()), | ||
railRouteShapeFetcher: .init(backend: IdleBackend()), | ||
viewportProvider: ViewportProvider(), | ||
navigationStack: navStack, | ||
sheetHeight: sheetHeight | ||
) | ||
|
||
let exp = sut.inspection.inspect { view in | ||
XCTAssertNotNil(view) | ||
} | ||
ViewHosting.host(view: sut) | ||
wait(for: [exp], timeout: 2) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
iosApp/iosAppTests/Pages/StopDetails/StopDetailsPageTests.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,47 @@ | ||
// | ||
// StopDetailsPageTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Simon, Emma on 4/5/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
@testable import iosApp | ||
import shared | ||
import SwiftPhoenixClient | ||
import SwiftUI | ||
import ViewInspector | ||
import XCTest | ||
@_spi(Experimental) import MapboxMaps | ||
|
||
final class StopDetailsPageTests: XCTestCase { | ||
override func setUp() { | ||
executionTimeAllowance = 60 | ||
} | ||
|
||
func testStopChange() throws { | ||
let objects = ObjectCollectionBuilder() | ||
let route = objects.route() | ||
let stop = objects.stop { _ in } | ||
let nextStop = objects.stop { $0.id = "next" } | ||
let routePattern = objects.routePattern(route: route) { _ in } | ||
|
||
let viewportProvider: ViewportProvider = .init(viewport: .followPuck(zoom: 1)) | ||
|
||
var sut = StopDetailsPage( | ||
backend: IdleBackend(), | ||
socket: MockSocket(), | ||
globalFetcher: .init(backend: IdleBackend()), | ||
viewportProvider: viewportProvider, | ||
stop: stop, filter: .init(routeId: route.id, directionId: routePattern.directionId) | ||
) | ||
|
||
let exp = sut.inspection.inspect { _ in | ||
XCTAssertEqual(viewportProvider.viewport.camera?.center, stop.coordinate) | ||
sut.stop = nextStop | ||
XCTAssertEqual(viewportProvider.viewport.camera?.center, nextStop.coordinate) | ||
} | ||
ViewHosting.host(view: sut) | ||
wait(for: [exp], timeout: 2) | ||
} | ||
} |
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