Skip to content

Commit

Permalink
Fix RouteControllerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
kried committed Dec 19, 2023
1 parent 3190fb9 commit 0f2f737
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Tests/MapboxCoreNavigationTests/RouteControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class RouteControllerTests: TestCase {
private var routeResponse: RouteResponse!
private var singleRouteResponse: RouteResponse!
private var multilegRouteResponse: RouteResponse!

private var singleDecodedRoute: Route!
private var singleRouteInterface: RouteInterface!

private let rawLocation = CLLocation(latitude: 47.208674, longitude: 9.524650)
private var locationWithDate: CLLocation {
let coordinate = CLLocationCoordinate2D(latitude: 59.337928, longitude: 18.076841)
Expand Down Expand Up @@ -79,6 +81,8 @@ class RouteControllerTests: TestCase {
navigationSessionManagerSpy = NavigationSessionManagerSpy.shared

singleRouteResponse = makeSingleRouteResponse()
singleRouteInterface = TestRouteProvider.createRoute(routeResponse: singleRouteResponse)!
singleDecodedRoute = makeSingleDecodedRoute(with: singleRouteInterface)
multilegRouteResponse = makeMultilegRouteResponse()

routeController = makeRouteController()
Expand Down Expand Up @@ -1237,16 +1241,16 @@ class RouteControllerTests: TestCase {
}

func testSwitchToCoincideOnlineRouteIfNavNativeFailed() {
let route = TestRouteProvider.createRoute(routeResponse: singleRouteResponse)!
let route = singleRouteInterface!
let callbackExpectation = expectation(description: "Switch to coincident online route should be reported")
delegate.onDidSwitchToCoincideRoute = { actualRoute in
XCTAssertEqual(actualRoute, self.singleRouteResponse.routes?[0])
XCTAssertEqual(actualRoute, self.singleDecodedRoute)
callbackExpectation.fulfill()
}

expectation(forNotification: .routeControllerDidSwitchToCoincidentOnlineRoute, object: routeController) { (notification) -> Bool in
let actualRoute = notification.userInfo?[RouteController.NotificationUserInfoKey.coincidentRouteKey] as? Route
XCTAssertEqual(actualRoute, self.singleRouteResponse.routes?[0])
XCTAssertEqual(actualRoute, self.singleDecodedRoute)
return true
}
navigatorSpy.returnedSetRoutesResult = .failure(DirectionsError.unableToRoute)
Expand All @@ -1257,21 +1261,21 @@ class RouteControllerTests: TestCase {
XCTAssertEqual(routeController.indexedRouteResponse.routeIndex, 0)
XCTAssertEqual(routeController.indexedRouteResponse.responseOrigin, route.getRouterOrigin())
XCTAssertEqual(routeController.continuousAlternatives.count, 0)
XCTAssertEqual(routeController.indexedRouteResponse.currentRoute?.legs, singleRouteResponse.routes?[0].legs)
XCTAssertEqual(routeController.indexedRouteResponse.currentRoute?.legs, singleDecodedRoute.legs)
waitForExpectations(timeout: expectationsTimeout)
}

func testSwitchToCoincideOnlineRouteIfNavNativeSucceed() {
let route = TestRouteProvider.createRoute(routeResponse: singleRouteResponse)!
let route = singleRouteInterface!
let callbackExpectation = expectation(description: "Switch to coincident online route should be reported")
delegate.onDidSwitchToCoincideRoute = { actualRoute in
XCTAssertEqual(actualRoute, self.singleRouteResponse.routes?[0])
XCTAssertEqual(actualRoute, self.singleDecodedRoute)
callbackExpectation.fulfill()
}

expectation(forNotification: .routeControllerDidSwitchToCoincidentOnlineRoute, object: routeController) { (notification) -> Bool in
let actualRoute = notification.userInfo?[RouteController.NotificationUserInfoKey.coincidentRouteKey] as? Route
XCTAssertEqual(actualRoute, self.singleRouteResponse.routes?[0])
XCTAssertEqual(actualRoute, self.singleDecodedRoute)
return true
}

Expand All @@ -1280,7 +1284,7 @@ class RouteControllerTests: TestCase {

XCTAssertEqual(routeController.indexedRouteResponse.routeIndex, 0)
XCTAssertEqual(routeController.indexedRouteResponse.responseOrigin, route.getRouterOrigin())
XCTAssertEqual(routeController.indexedRouteResponse.currentRoute?.legs, singleRouteResponse.routes?[0].legs)
XCTAssertEqual(routeController.indexedRouteResponse.currentRoute?.legs, singleDecodedRoute.legs)
waitForExpectations(timeout: expectationsTimeout)
}

Expand Down Expand Up @@ -1715,6 +1719,12 @@ class RouteControllerTests: TestCase {
return Fixture.routeResponse(from: "route", options: routeOptions)
}

private func makeSingleDecodedRoute(with routeInterface: RouteInterface) -> Route {
let decoded = RerouteController.decode(routeRequest: routeInterface.getRequestUri(),
routeResponse: routeInterface.getResponseJsonRef())!
return decoded.routeResponse.routes![0]
}

private func makeMultilegRouteResponse() -> RouteResponse {
let routeOptions = NavigationRouteOptions(coordinates: [
CLLocationCoordinate2D(latitude: 9.519172, longitude: 47.210823),
Expand Down

0 comments on commit 0f2f737

Please sign in to comment.