Skip to content

Commit f892cd9

Browse files
committed
NAVAND-646: adjust incidents and closures indices after refresh
1 parent 92ae2eb commit f892cd9

File tree

8 files changed

+71476
-40
lines changed

8 files changed

+71476
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Mapbox welcomes participation and contributions from everyone.
1313
- Marked `Binder`, `MapboxExtendableButton` methods and `MapboxNavigation#installComponents` methods with `@UiThread` annotation. [#6268](https://github.com/mapbox/mapbox-navigation-android/pull/6268)
1414
- Fixed an issue with `NavigationView` that caused `ViewOptionsCustomization.routeArrowOptions` to be ignored, if arrows have already been drawn on the map. [#6333](https://github.com/mapbox/mapbox-navigation-android/pull/6333)
1515
- Replaced `ViewStyleCustomization.defaultMarkerAnnotationOptions` with `ViewStyleCustomization.defaultDestinationMarkerAnnotationOptions`. [#6365](https://github.com/mapbox/mapbox-navigation-android/pull/6365)
16+
- Fixed the issue with incorrect geometry indices for `RouteLeg#incidents` and `RouteLeg#closures` after refresh. [#6364](https://github.com/mapbox/mapbox-navigation-android/pull/6364)
1617

1718
## Mapbox Navigation SDK 2.9.0-alpha.2 - 16 September, 2022
1819
### Changelog

instrumentation-tests/src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteRefreshTest.kt

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.location.Location
44
import androidx.annotation.IntegerRes
55
import com.mapbox.api.directions.v5.DirectionsCriteria
66
import com.mapbox.api.directions.v5.models.Closure
7+
import com.mapbox.api.directions.v5.models.Incident
78
import com.mapbox.api.directions.v5.models.RouteOptions
89
import com.mapbox.geojson.Point
910
import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions
@@ -73,6 +74,11 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja
7374
Point.fromLngLat(-121.480279, 38.57674),
7475
Point.fromLngLat(-121.468434, 38.58225)
7576
)
77+
private val threeCoordinatesWithIncidents = listOf(
78+
Point.fromLngLat(-75.474061, 38.546280),
79+
Point.fromLngLat(-75.525486, 38.772959),
80+
Point.fromLngLat(-74.698765, 39.822911)
81+
)
7682

7783
private lateinit var failByRequestRouteRefreshResponse: FailByRequestMockRequestHandler
7884

@@ -359,7 +365,7 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja
359365
}
360366

361367
@Test
362-
fun expect_route_refresh_to_update_annotations_for_truncated_next_leg() =
368+
fun expect_route_refresh_to_update_annotations_incidents_and_closures_for_truncated_next_leg() =
363369
sdkTest {
364370
setupMockRequestHandlers(
365371
threeCoordinates,
@@ -387,10 +393,127 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja
387393
.first()
388394
.navigationRoutes
389395

396+
// annotations
390397
assertEquals(201.673, requestedRoutes[0].getSumOfDurationAnnotationsFromLeg(1), 0.0001)
391398
assertEquals(189.086, refreshedRoutes[0].getSumOfDurationAnnotationsFromLeg(1), 0.0001)
399+
400+
// incidents
401+
assertEquals(
402+
listOf(listOf("9457146989091490", 400, 405)),
403+
requestedRoutes[0].directionsRoute.legs()!![1].incidents()!!
404+
.extract({ id() }, { geometryIndexStart() }, { geometryIndexEnd() })
405+
)
406+
assertEquals(
407+
listOf(listOf("9457146989091490", 396, 401)),
408+
refreshedRoutes[0].directionsRoute.legs()!![1].incidents()!!
409+
.extract({ id() }, { geometryIndexStart() }, { geometryIndexEnd() })
410+
)
411+
412+
// closures
413+
assertEquals(
414+
listOf(
415+
Closure.builder()
416+
.geometryIndexStart(312)
417+
.geometryIndexEnd(313)
418+
.build()
419+
),
420+
requestedRoutes[0].directionsRoute.legs()!![1].closures()
421+
)
422+
assertEquals(
423+
listOf(
424+
Closure.builder()
425+
.geometryIndexStart(313)
426+
.geometryIndexEnd(314)
427+
.build()
428+
),
429+
refreshedRoutes[0].directionsRoute.legs()!![1].closures()
430+
)
392431
}
393432

433+
@Test
434+
fun expect_route_refresh_to_update_annotations_incidents_and_closures_for_second_leg() =
435+
sdkTest {
436+
val currentRouteGeometryIndex = 2000
437+
// 437 points in leg #0, so currentLegGeometryIndex = 2000 - 437 + 1 (points are duplicated on the start and end of steps and legs) = 1564
438+
setupMockRequestHandlers(
439+
threeCoordinatesWithIncidents,
440+
R.raw.route_response_multileg_with_incidents,
441+
R.raw.route_response_route_refresh_multileg_with_incidents,
442+
"route_response_multileg_with_incidents",
443+
acceptedGeometryIndex = currentRouteGeometryIndex
444+
)
445+
val routeOptions = generateRouteOptions(threeCoordinatesWithIncidents)
446+
val requestedRoutes = mapboxNavigation.requestRoutes(routeOptions)
447+
.getSuccessfulResultOrThrowException()
448+
.routes
449+
450+
mapboxNavigation.setNavigationRoutes(requestedRoutes, initialLegIndex = 1)
451+
mapboxNavigation.startTripSession()
452+
// corresponds to currentRouteGeometryIndex = 2000, currentLeg = 1
453+
stayOnPosition(39.80965, -75.281163)
454+
mapboxNavigation.routeProgressUpdates()
455+
.filter {
456+
it.currentRouteGeometryIndex == currentRouteGeometryIndex
457+
}
458+
.first()
459+
val refreshedRoutes = mapboxNavigation.routesUpdates()
460+
.filter {
461+
it.reason == ROUTES_UPDATE_REASON_REFRESH
462+
}
463+
.first()
464+
.navigationRoutes
465+
466+
// annotations
467+
assertEquals(8595.694, requestedRoutes[0].getSumOfDurationAnnotationsFromLeg(1), 0.0001)
468+
assertEquals(8571.824, refreshedRoutes[0].getSumOfDurationAnnotationsFromLeg(1), 0.0001)
469+
470+
// incidents
471+
assertEquals(
472+
listOf(
473+
listOf("9457146989091490", 2019, 2024),
474+
listOf("5945491930714919", 2044, 2126)
475+
),
476+
requestedRoutes[0].directionsRoute.legs()!![1].incidents()!!
477+
.extract({ id() }, { geometryIndexStart() }, { geometryIndexEnd() })
478+
)
479+
assertEquals(
480+
listOf(
481+
listOf("9457146989091490", 2019, 2024),
482+
listOf("5945491930714919", 2048, 2130)
483+
),
484+
refreshedRoutes[0].directionsRoute.legs()!![1].incidents()!!
485+
.extract({ id() }, { geometryIndexStart() }, { geometryIndexEnd() })
486+
)
487+
488+
// closures
489+
assertEquals(
490+
listOf(
491+
Closure.builder()
492+
.geometryIndexStart(2001)
493+
.geometryIndexEnd(2020)
494+
.build()
495+
),
496+
requestedRoutes[0].directionsRoute.legs()!![1].closures()
497+
)
498+
assertEquals(
499+
listOf(
500+
Closure.builder()
501+
.geometryIndexStart(2054)
502+
.geometryIndexEnd(2061)
503+
.build()
504+
),
505+
refreshedRoutes[0].directionsRoute.legs()!![1].closures()
506+
)
507+
}
508+
509+
private fun List<Incident>.extract(vararg extractors: Incident.() -> Any?): List<List<Any?>> {
510+
return map { incident ->
511+
extractors.map { extractor ->
512+
incident.extractor()
513+
}
514+
}
515+
}
516+
394517
private fun stayOnInitialPosition() {
395518
mockLocationReplayerRule.loopUpdate(
396519
mockLocationUpdatesRule.generateLocationUpdate {

0 commit comments

Comments
 (0)