Skip to content

Commit 7002062

Browse files
authored
Fix MapboxCoreNavigationTests failures with reset of navigator before location update each time (#2918)
* Fix MapboxCoreNavigationTests failures with reset of navigator before location update each time * clean code
1 parent 444eeb6 commit 7002062

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

MapboxNavigation.xcodeproj/xcshareddata/xcschemes/MapboxCoreNavigation.xcscheme

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
<Test
6464
Identifier = "MapboxNavigationTests/testLowAlert()">
6565
</Test>
66-
<Test
67-
Identifier = "PassiveLocationDataSourceTests/testManualLocations()">
68-
</Test>
6966
</SkippedTests>
7067
</TestableReference>
7168
</Testables>

Tests/MapboxCoreNavigationTests/MapboxCoreNavigationTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class MapboxCoreNavigationTests: XCTestCase {
3232
override func tearDown() {
3333
super.tearDown()
3434
UserDefaults.resetStandardUserDefaults()
35+
try? Navigator.shared.navigator.resetRideSession()
3536
}
3637

3738
func testNavigationNotificationsInfoDict() {

Tests/MapboxCoreNavigationTests/NavigationServiceTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class NavigationServiceTests: XCTestCase {
5353
directionsClientSpy.reset()
5454
delegate.reset()
5555
}
56+
57+
override func tearDown() {
58+
super.tearDown()
59+
try? Navigator.shared.navigator.resetRideSession()
60+
}
5661

5762
func testDefaultUserInterfaceUsage() {
5863
XCTAssertTrue(!dependencies.navigationService.eventsManager.usesDefaultUserInterface, "MapboxCoreNavigationTests shouldn't have an implicit dependency on MapboxNavigation due to removing the Example application target as the test host.")

Tests/MapboxCoreNavigationTests/PassiveLocationDataSourceTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class PassiveLocationDataSourceTests: XCTestCase {
5050

5151
func passiveLocationDataSource(_ dataSource: PassiveLocationDataSource, didUpdateLocation location: CLLocation, rawLocation: CLLocation) {
5252
print("Got location: \(rawLocation.coordinate.latitude), \(rawLocation.coordinate.longitude)\(location.coordinate.latitude), \(location.coordinate.longitude)")
53-
print("Value: \(road.proximity(of: location.coordinate)) should be less \(road.proximity(of: rawLocation.coordinate))")
53+
print("Value: \(road.proximity(of: location.coordinate)) should be less or equal to \(road.proximity(of: rawLocation.coordinate))")
5454

55-
XCTAssert(road.proximity(of: location.coordinate) < road.proximity(of: rawLocation.coordinate), "Raw Location wasn't mapped to a road")
55+
XCTAssert(road.proximity(of: location.coordinate) <= road.proximity(of: rawLocation.coordinate), "Raw Location wasn't mapped to a road")
5656
}
5757

5858
func passiveLocationDataSource(_ dataSource: PassiveLocationDataSource, didUpdateHeading newHeading: CLHeading) {
@@ -67,6 +67,7 @@ class PassiveLocationDataSourceTests: XCTestCase {
6767

6868
// Configure the navigator (used by PassiveLocationDataSource) with the tiles version (version is used to find the tiles in the cache folder)
6969
let tilesVersion = "preloadedtiles" // any string
70+
Navigator.credentials = directions.credentials
7071
Navigator.tilesVersion = tilesVersion
7172

7273
let bundle = Bundle(for: Fixture.self)
@@ -75,8 +76,8 @@ class PassiveLocationDataSourceTests: XCTestCase {
7576
}
7677

7778
func testManualLocations() {
78-
let locationManager = PassiveLocationDataSource()
79-
79+
let locationManager = PassiveLocationDataSource(directions: directions)
80+
try? Navigator.shared.navigator.resetRideSession()
8081
let locationUpdateExpectation = expectation(description: "Location manager takes some time to start mapping locations to a road graph")
8182
locationUpdateExpectation.expectedFulfillmentCount = 1
8283

@@ -86,6 +87,7 @@ class PassiveLocationDataSourceTests: XCTestCase {
8687
locationManager.updateLocation(CLLocation(latitude: 47.208674, longitude: 9.524650, timestamp: date.addingTimeInterval(-5)))
8788
locationManager.delegate = delegate
8889
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
90+
try? Navigator.shared.navigator.resetRideSession()
8991
locationManager.updateLocation(CLLocation(latitude: 47.208943, longitude: 9.524707, timestamp: date.addingTimeInterval(-4)))
9092
locationManager.updateLocation(CLLocation(latitude: 47.209082, longitude: 9.524319, timestamp: date.addingTimeInterval(-3)))
9193
locationManager.updateLocation(CLLocation(latitude: 47.209229, longitude: 9.523838, timestamp: date.addingTimeInterval(-2)))

0 commit comments

Comments
 (0)