@@ -6,6 +6,7 @@ import TestHelper
66import struct Polyline. Polyline
77import Turf
88@testable import MapboxCoreNavigation
9+ import MapboxNavigationNative
910
1011class RouteProgressTests : TestCase {
1112
@@ -297,6 +298,50 @@ class RouteProgressTests: TestCase {
297298 legProgress. currentStepProgress. distanceTraveled = lineString. distance ( to: coordinates [ 5 ] ) ! + ( lineString. distance ( ) ! - lineString. distance ( to: coordinates [ 5 ] ) !) / 2.0
298299 XCTAssertTrue ( legProgress. currentSpeedLimit? . value. isInfinite ?? false )
299300 }
301+
302+ func testDistanceToIntersection( ) {
303+ func navigationState( stepDistanceTraveled: CLLocationDistance ) -> NavigationStatus {
304+ . init(
305+ routeState: . tracking,
306+ locatedAlternativeRouteId: nil ,
307+ stale: false ,
308+ location: . init( . init( ) ) ,
309+ routeIndex: 0 ,
310+ legIndex: 0 ,
311+ step: 0 ,
312+ isFallback: false ,
313+ inTunnel: false ,
314+ predicted: 0 ,
315+ geometryIndex: 0 ,
316+ shapeIndex: 0 ,
317+ intersectionIndex: 0 ,
318+ roads: [ ] ,
319+ voiceInstruction: nil ,
320+ bannerInstruction: nil ,
321+ speedLimit: nil ,
322+ keyPoints: [ ] ,
323+ mapMatcherOutput: . init( matches: [ ] , isTeleport: false ) ,
324+ offRoadProba: 0 ,
325+ activeGuidanceInfo: . init(
326+ routeProgress: . init( distanceTraveled: 0 , fractionTraveled: 0 , remainingDistance: 0 , remainingDuration: 0 ) ,
327+ legProgress: . init( distanceTraveled: 0 , fractionTraveled: 0 , remainingDistance: 0 , remainingDuration: 0 ) ,
328+ step: . init( distanceTraveled: stepDistanceTraveled, fractionTraveled: 0 , remainingDistance: 0 , remainingDuration: 0 )
329+ ) ,
330+ upcomingRouteAlerts: [ ] ,
331+ nextWaypointIndex: 0 ,
332+ layer: nil
333+ )
334+ }
335+
336+ let routeProgress = RouteProgress ( route: route, options: routeOptions)
337+ routeProgress. updateDistanceTraveled ( navigationStatus: navigationState ( stepDistanceTraveled: 0 ) )
338+ XCTAssertEqual ( round ( routeProgress. currentLegProgress. currentStepProgress. userDistanceToUpcomingIntersection ?? 0 ) , 81 )
339+
340+ // `updateDistanceTraveled` only reads `activeGuidanceInfo.step.distanceTraveled`, so it is the only valid data
341+ // we must provide here.
342+ routeProgress. updateDistanceTraveled ( navigationStatus: navigationState ( stepDistanceTraveled: 50 ) )
343+ XCTAssertEqual ( round ( routeProgress. currentLegProgress. currentStepProgress. userDistanceToUpcomingIntersection ?? 0 ) , 31 )
344+ }
300345
301346 func testRouteProggressCodable( ) {
302347 let routeProgress = RouteProgress ( route: route,
0 commit comments