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 48655e0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
15 changes: 13 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.0.6)
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
Expand All @@ -32,6 +37,8 @@ GEM
aws-sigv4 (1.5.2)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
bigdecimal (3.1.5)
claide (1.1.0)
cocoapods (1.12.1)
addressable (~> 2.8)
Expand Down Expand Up @@ -75,12 +82,15 @@ GEM
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
declarative (0.0.20)
digest-crc (0.6.4)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
drb (2.2.0)
ruby2_keywords
emoji_regex (3.2.3)
escape (0.0.4)
ethon (0.16.0)
Expand Down Expand Up @@ -220,11 +230,12 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_portile2 (2.8.1)
minitest (5.18.1)
minitest (5.20.0)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.0.0)
mustache (1.1.1)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
naturally (2.2.1)
Expand Down
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 48655e0

Please sign in to comment.