-
Notifications
You must be signed in to change notification settings - Fork 319
Route preview iteration 2 #6495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8985c19
implemented experimental route preview
VysotskiVadim 66bff78
clarified docs for alternative id which is 0
VysotskiVadim 8c050f3
fixed lint issues
VysotskiVadim b641284
mote checks in test
VysotskiVadim 532a0ad
more tests
VysotskiVadim dd6bc7a
more tests
VysotskiVadim d831c68
test multiple cleanup
VysotskiVadim 285402e
more docs
VysotskiVadim 2714fb5
improve docs
VysotskiVadim 4ea0748
added unit test for unsubscribing on destroy
VysotskiVadim 0a0bf9c
added routes preview example to the qa app
VysotskiVadim 88752d9
reverted changes in the examples
VysotskiVadim 0558e06
fixed changelog
VysotskiVadim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...rc/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RoutesPreviewTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| package com.mapbox.navigation.instrumentation_tests.core | ||
|
|
||
| import android.location.Location | ||
| import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI | ||
| import com.mapbox.navigation.base.options.NavigationOptions | ||
| import com.mapbox.navigation.base.route.NavigationRoute | ||
| import com.mapbox.navigation.base.trip.model.RouteProgressState | ||
| import com.mapbox.navigation.core.MapboxNavigation | ||
| import com.mapbox.navigation.core.MapboxNavigationProvider | ||
| import com.mapbox.navigation.core.directions.session.RoutesExtra | ||
| import com.mapbox.navigation.core.directions.session.RoutesUpdatedResult | ||
| import com.mapbox.navigation.core.preview.RoutesPreviewExtra | ||
| import com.mapbox.navigation.core.preview.RoutesPreviewUpdate | ||
| import com.mapbox.navigation.instrumentation_tests.activity.EmptyTestActivity | ||
| import com.mapbox.navigation.instrumentation_tests.utils.MapboxNavigationRule | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routeProgressUpdates | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routesPreviewUpdates | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routesUpdates | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.sdkTest | ||
| import com.mapbox.navigation.instrumentation_tests.utils.routes.RoutesProvider | ||
| import com.mapbox.navigation.instrumentation_tests.utils.routes.RoutesProvider.toNavigationRoutes | ||
| import com.mapbox.navigation.testing.ui.BaseTest | ||
| import com.mapbox.navigation.testing.ui.utils.getMapboxAccessTokenFromResources | ||
| import com.mapbox.navigation.testing.ui.utils.runOnMainSync | ||
| import kotlinx.coroutines.flow.first | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNotEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| @OptIn(ExperimentalPreviewMapboxNavigationAPI::class) | ||
| class RoutesPreviewTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.java) { | ||
|
|
||
| override fun setupMockLocation(): Location = mockLocationUpdatesRule.generateLocationUpdate { | ||
| latitude = 38.894721 | ||
| longitude = -77.031991 | ||
| } | ||
|
|
||
| @get:Rule | ||
| val mapboxNavigationRule = MapboxNavigationRule() | ||
| private lateinit var mapboxNavigation: MapboxNavigation | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| runOnMainSync { | ||
| mapboxNavigation = MapboxNavigationProvider.create( | ||
| NavigationOptions.Builder(activity) | ||
| .accessToken(getMapboxAccessTokenFromResources(activity)) | ||
| .build() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun transitions_free_drive_to_preview_to_active_guidance_to_free_drive() = sdkTest { | ||
| var currentRoutesPreview: RoutesPreviewUpdate? = null | ||
| mapboxNavigation.registerRoutesPreviewObserver { update -> | ||
| currentRoutesPreview = update | ||
| } | ||
| var currentRoutes: RoutesUpdatedResult? = null | ||
| mapboxNavigation.registerRoutesObserver { update -> | ||
| currentRoutes = update | ||
| } | ||
| // initial free drive | ||
| mapboxNavigation.startTripSession() | ||
| assertNull(currentRoutesPreview) | ||
| assertNull(currentRoutes) | ||
| // set routes preview | ||
| val routes = RoutesProvider.dc_very_short(activity).toNavigationRoutes() | ||
| mapboxNavigation.setRoutesPreview(routes) | ||
| mapboxNavigation.routesPreviewUpdates() | ||
| .first { it.reason == RoutesPreviewExtra.PREVIEW_NEW } | ||
| assertEquals(RoutesPreviewExtra.PREVIEW_NEW, currentRoutesPreview?.reason) | ||
| assertEquals(routes, currentRoutesPreview!!.routesPreview!!.routesList) | ||
| assertNull(currentRoutes) | ||
| // start active guidance | ||
| mapboxNavigation.setNavigationRoutes(currentRoutesPreview!!.routesPreview!!.routesList) | ||
| mapboxNavigation.setRoutesPreview(emptyList()) | ||
| mapboxNavigation.routesUpdates() | ||
| .first { it.reason == RoutesExtra.ROUTES_UPDATE_REASON_NEW } | ||
| mapboxNavigation.routeProgressUpdates() | ||
| .first { it.currentState == RouteProgressState.TRACKING } | ||
| mapboxNavigation.routesPreviewUpdates() | ||
| .first { it.reason == RoutesPreviewExtra.PREVIEW_CLEAN_UP } | ||
| assertEquals(RoutesPreviewExtra.PREVIEW_CLEAN_UP, currentRoutesPreview?.reason) | ||
| assertNull(currentRoutesPreview!!.routesPreview) | ||
| assertEquals(RoutesExtra.ROUTES_UPDATE_REASON_NEW, currentRoutes!!.reason) | ||
| assertEquals(routes, currentRoutes!!.navigationRoutes) | ||
| // back to free drive | ||
| mapboxNavigation.setNavigationRoutes(emptyList()) | ||
| mapboxNavigation.routesUpdates() | ||
| .first { it.reason == RoutesExtra.ROUTES_UPDATE_REASON_CLEAN_UP } | ||
| assertEquals(RoutesPreviewExtra.PREVIEW_CLEAN_UP, currentRoutesPreview?.reason) | ||
| assertNull(currentRoutesPreview!!.routesPreview) | ||
| assertEquals(RoutesExtra.ROUTES_UPDATE_REASON_CLEAN_UP, currentRoutes!!.reason) | ||
| assertEquals(emptyList<NavigationRoute>(), currentRoutes!!.navigationRoutes) | ||
| } | ||
|
|
||
| @Test | ||
| fun route_preview_in_parallel_to_active_guidance() = sdkTest { | ||
| var currentRoutesPreview: RoutesPreviewUpdate? = null | ||
| mapboxNavigation.registerRoutesPreviewObserver { update -> | ||
| currentRoutesPreview = update | ||
| } | ||
| var currentRoutes: RoutesUpdatedResult? = null | ||
| mapboxNavigation.registerRoutesObserver { update -> | ||
| currentRoutes = update | ||
| } | ||
| // initial free drive | ||
| mapboxNavigation.startTripSession() | ||
| assertNull(currentRoutesPreview) | ||
| assertNull(currentRoutes) | ||
| // set routes preview | ||
| val initialRoutes = RoutesProvider.dc_very_short(activity).toNavigationRoutes() | ||
| mapboxNavigation.setRoutesPreview(initialRoutes) | ||
| mapboxNavigation.routesPreviewUpdates() | ||
| .first { it.reason == RoutesPreviewExtra.PREVIEW_NEW } | ||
| // start active guidance | ||
| mapboxNavigation.setNavigationRoutes(currentRoutesPreview!!.routesPreview!!.routesList) | ||
| mapboxNavigation.setRoutesPreview(emptyList()) | ||
| mapboxNavigation.routeProgressUpdates() | ||
| .first { it.currentState == RouteProgressState.TRACKING } | ||
| // preview a different route not leaving action guidance | ||
| val updatedRoutes = RoutesProvider.dc_very_short_two_legs(activity).toNavigationRoutes() | ||
| mapboxNavigation.setRoutesPreview(updatedRoutes) | ||
| mapboxNavigation.routesPreviewUpdates() | ||
| .first { it.routesPreview?.routesList == updatedRoutes } | ||
| assertEquals( | ||
| "active guidance should track initial routes", | ||
| initialRoutes, | ||
| currentRoutes?.navigationRoutes | ||
| ) | ||
| // user decided to switch to previewed routes | ||
| mapboxNavigation.setNavigationRoutes(currentRoutesPreview!!.routesPreview!!.routesList) | ||
| mapboxNavigation.setRoutesPreview(emptyList()) | ||
VysotskiVadim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mapboxNavigation.routeProgressUpdates().first { | ||
| it.navigationRoute == updatedRoutes[0] | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun start_active_guidance_from_previewed_alternative_route() = sdkTest { | ||
| // set routes preview | ||
| val routes = RoutesProvider.dc_short_with_alternative(activity).toNavigationRoutes() | ||
| mapboxNavigation.setRoutesPreview(routes) | ||
| val preview = mapboxNavigation.routesPreviewUpdates() | ||
| .first { it.reason == RoutesPreviewExtra.PREVIEW_NEW } | ||
| // switch to alternative route | ||
| mapboxNavigation.changeRoutesPreviewPrimaryRoute( | ||
| preview.routesPreview!!.originalRoutesList[1] | ||
| ) | ||
| val updatedPreview = mapboxNavigation.routesPreviewUpdates() | ||
| .first { it != preview } | ||
| // start active guidance | ||
| mapboxNavigation.setNavigationRoutes(updatedPreview.routesPreview!!.routesList) | ||
| mapboxNavigation.setRoutesPreview(emptyList()) | ||
| val routesUpdate = mapboxNavigation.routesUpdates() | ||
| .first { it.reason == RoutesExtra.ROUTES_UPDATE_REASON_NEW } | ||
| assertEquals( | ||
| listOf( | ||
| routes[1], | ||
| routes[0] | ||
| ), | ||
| routesUpdate.navigationRoutes | ||
| ) | ||
| val previewAlternativeMetadata = updatedPreview.routesPreview!!.alternativesMetadata.first() | ||
| val activeGuidanceAlternativeMetadata = mapboxNavigation | ||
| .getAlternativeMetadataFor(routes[0])!! | ||
| assertEquals( | ||
| 0, | ||
| previewAlternativeMetadata.alternativeId | ||
| ) | ||
| assertNotEquals( | ||
| previewAlternativeMetadata.alternativeId, | ||
| activeGuidanceAlternativeMetadata.alternativeId | ||
| ) | ||
| assertEquals( | ||
| previewAlternativeMetadata.infoFromStartOfPrimary, | ||
| activeGuidanceAlternativeMetadata.infoFromStartOfPrimary | ||
| ) | ||
| assertEquals( | ||
| previewAlternativeMetadata.forkIntersectionOfAlternativeRoute, | ||
| activeGuidanceAlternativeMetadata.forkIntersectionOfAlternativeRoute | ||
| ) | ||
| assertEquals( | ||
| previewAlternativeMetadata.infoFromFork, | ||
| activeGuidanceAlternativeMetadata.infoFromFork | ||
| ) | ||
| assertEquals( | ||
| previewAlternativeMetadata.forkIntersectionOfPrimaryRoute, | ||
| activeGuidanceAlternativeMetadata.forkIntersectionOfPrimaryRoute | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting approach for verifying callback invocations. I've used the other 2 so far:
CopilotIntegrationTest;HistoryRecordingStateChangeObserverTest);I'd suggest trying channels here. This way you won't have to wait until data updates with flows and then separately check the current value. Because now it's a bit more difficult to keep in mind when to wait for what and there's a risk of introducing inconsistencies and flakiness.
I mean that code like this:
can be reduced to sth like:
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main point of those listeners is to verify the case when callbacks weren't called https://github.com/mapbox/mapbox-navigation-android/pull/6495/files#diff-dd6f2bb7ffbeeccc5232ca194ae7b4ed2aecb887a9b87e497ab332e5d2b831c8R67
If I didn't need it at the beginning of the test I could have verify current state like this:
but as I already have
currentRoutesPreviewI just use it