-
Notifications
You must be signed in to change notification settings - Fork 319
Route preview state #6107
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
Closed
Closed
Route preview state #6107
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3c323da
prototyping
VysotskiVadim cf35d73
test switch from route preview to active guidance
VysotskiVadim ea4008d
fixed route progress in preview state
VysotskiVadim 16af4e3
fixed event during active guidance -> preview switch
VysotskiVadim c6bfad8
fixed fixed route refresh
VysotskiVadim e087d2f
fixed subscription in direction session
VysotskiVadim 1c8e8eb
cleanup tests
VysotskiVadim 522537b
test cleanup
VysotskiVadim 55fc923
tests cleanup
VysotskiVadim db24a1c
tests cleanup
VysotskiVadim 7b43599
test idle -> preview
VysotskiVadim 25708e0
added some documentation
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
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
171 changes: 171 additions & 0 deletions
171
...rc/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/PreviewRoutesTest.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,171 @@ | ||
| package com.mapbox.navigation.instrumentation_tests.core | ||
|
|
||
| import android.location.Location | ||
| import com.mapbox.navigation.base.options.NavigationOptions | ||
| import com.mapbox.navigation.base.route.NavigationRoute | ||
| 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.trip.session.NavigationSessionState | ||
| import com.mapbox.navigation.core.trip.session.NavigationSessionStateV2 | ||
| 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.routesUpdates | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.sdkTest | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.waitForNewRoute | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.waitForPreviewRoute | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.waitForRoutesCleanUp | ||
| 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.CoroutineStart | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.firstOrNull | ||
| import kotlinx.coroutines.flow.takeWhile | ||
| import kotlinx.coroutines.flow.toList | ||
| import kotlinx.coroutines.withTimeoutOrNull | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import java.util.Objects | ||
| import kotlin.reflect.typeOf | ||
|
|
||
| class PreviewRoutesTest : 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 preview_route_from_free_drive() = sdkTest { | ||
| val routes = RoutesProvider.dc_very_short(activity).toNavigationRoutes() | ||
| pushPrimaryRouteOriginAsLocation(routes) | ||
| mapboxNavigation.startTripSession() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also add tests:
|
||
|
|
||
| mapboxNavigation.previewNavigationRoutes(routes) | ||
| val previewRouteUpdate = mapboxNavigation.waitForPreviewRoute() | ||
|
|
||
| assertEquals(routes, previewRouteUpdate.navigationRoutes) | ||
VysotskiVadim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertEquals(routes, mapboxNavigation.getPreviewedNavigationRoutes()) | ||
| assertEquals(emptyList<NavigationRoute>(), mapboxNavigation.getNavigationRoutes()) | ||
| assertIs<NavigationSessionState.FreeDrive>(mapboxNavigation.getNavigationSessionState()) | ||
| assertIs<NavigationSessionStateV2.RoutePreview>(mapboxNavigation.getNavigationSessionStateV2()) | ||
| } | ||
|
|
||
| @Test | ||
| fun preview_route_with_alternative_from_idle() = sdkTest { | ||
| val routes = RoutesProvider.dc_short_with_alternative(activity).toNavigationRoutes() | ||
| pushPrimaryRouteOriginAsLocation(routes) | ||
|
|
||
| mapboxNavigation.previewNavigationRoutes(routes) | ||
| val previewRouteUpdate = mapboxNavigation.waitForPreviewRoute() | ||
| val previewedRouteMetadata = mapboxNavigation.getAlternativeMetadataFor( | ||
| previewRouteUpdate.navigationRoutes[1] | ||
| ) | ||
|
|
||
| assertNotNull(previewedRouteMetadata) | ||
| } | ||
|
|
||
| @Test | ||
| fun start_active_guidance_after_preview() = sdkTest { | ||
| val routes = RoutesProvider.dc_short_with_alternative(activity).toNavigationRoutes() | ||
| pushPrimaryRouteOriginAsLocation(routes) | ||
| mapboxNavigation.startTripSession() | ||
| mapboxNavigation.previewNavigationRoutes(routes) | ||
| mapboxNavigation.waitForPreviewRoute() | ||
|
|
||
| mapboxNavigation.setNavigationRoutes(mapboxNavigation.getPreviewedNavigationRoutes()) | ||
| val activeGuidanceRouteUpdate = mapboxNavigation.waitForNewRoute() | ||
|
|
||
| assertEquals(routes, activeGuidanceRouteUpdate.navigationRoutes) | ||
| assertIs<NavigationSessionState.ActiveGuidance>(mapboxNavigation.getNavigationSessionState()) | ||
| assertIs<NavigationSessionStateV2.ActiveGuidance>(mapboxNavigation.getNavigationSessionStateV2()) | ||
| } | ||
|
|
||
| @Test | ||
| fun switch_to_free_drive_after_preview() = sdkTest { | ||
| val routes = RoutesProvider.dc_very_short(activity).toNavigationRoutes() | ||
| pushPrimaryRouteOriginAsLocation(routes) | ||
| mapboxNavigation.startTripSession() | ||
| mapboxNavigation.previewNavigationRoutes(routes) | ||
| mapboxNavigation.waitForPreviewRoute() | ||
|
|
||
| mapboxNavigation.clearRoutes() | ||
| val freeDriveRoutesUpdate = mapboxNavigation.waitForRoutesCleanUp() | ||
|
|
||
| assertEquals(emptyList<NavigationRoute>(), freeDriveRoutesUpdate.navigationRoutes) | ||
| assertEquals(emptyList<NavigationRoute>(), mapboxNavigation.getNavigationRoutes()) | ||
| assertIs<NavigationSessionState.FreeDrive>(mapboxNavigation.getNavigationSessionState()) | ||
| assertIs<NavigationSessionStateV2.FreeDrive>(mapboxNavigation.getNavigationSessionStateV2()) | ||
| } | ||
|
|
||
| @Test | ||
| fun start_preview_after_active_guidance() = sdkTest { | ||
| val routes = RoutesProvider.dc_short_with_alternative(activity).toNavigationRoutes() | ||
| pushPrimaryRouteOriginAsLocation(routes) | ||
| mapboxNavigation.startTripSession() | ||
| mapboxNavigation.setNavigationRoutes(routes) | ||
| mapboxNavigation.waitForNewRoute() | ||
| val activeGuidanceRouteProgress = mapboxNavigation.routeProgressUpdates().first() | ||
|
|
||
| val routeUpdates = mutableListOf<RoutesUpdatedResult>() | ||
| mapboxNavigation.registerRoutesObserver { | ||
| routeUpdates.add(it) | ||
| } | ||
| mapboxNavigation.previewNavigationRoutes(mapboxNavigation.getNavigationRoutes()) | ||
| mapboxNavigation.waitForPreviewRoute() | ||
| val previewRouteProgress = withTimeoutOrNull(1) { | ||
| mapboxNavigation.routeProgressUpdates().first() | ||
| } | ||
|
|
||
| assertEquals( | ||
| listOf(RoutesExtra.ROUTES_UPDATE_REASON_NEW, RoutesExtra.ROUTES_UPDATE_REASON_PREVIEW), | ||
| routeUpdates.map { it.reason } | ||
| ) | ||
| assertNotNull(activeGuidanceRouteProgress) | ||
| assertNull(previewRouteProgress) | ||
| assertIs<NavigationSessionState.FreeDrive>(mapboxNavigation.getNavigationSessionState()) | ||
| assertIs<NavigationSessionStateV2.RoutePreview>(mapboxNavigation.getNavigationSessionStateV2()) | ||
| } | ||
|
|
||
| private fun pushPrimaryRouteOriginAsLocation(routes: List<NavigationRoute>) { | ||
| val origin = routes.first().routeOptions.coordinatesList().first() | ||
| mockLocationUpdatesRule.pushLocationUpdate { | ||
| latitude = origin.latitude() | ||
| longitude = origin.longitude() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private inline fun <reified T> assertIs(obj: Any) { | ||
| assertTrue( | ||
| "expected an instance of ${T::class.java.name}, but it is $obj (${obj.javaClass.name})", | ||
| obj is T | ||
| ) | ||
| } | ||
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.
Why INVISIBLE, not GONE? The same question for xml.