-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAVAND-1636: do not set routes to NN when starting a session
- Loading branch information
Showing
5 changed files
with
114 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
- Fixed an issue where the first voice instruction might have been played thrice when switching between regular session and replay with route being set. |
This file contains 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
98 changes: 98 additions & 0 deletions
98
.../androidTest/java/com/mapbox/navigation/instrumentation_tests/ui/VoiceInstructionsTest.kt
This file contains 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,98 @@ | ||
package com.mapbox.navigation.instrumentation_tests.ui | ||
|
||
import android.location.Location | ||
import androidx.test.espresso.Espresso | ||
import com.mapbox.api.directions.v5.models.VoiceInstructions | ||
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI | ||
import com.mapbox.navigation.base.options.NavigationOptions | ||
import com.mapbox.navigation.base.options.RoutingTilesOptions | ||
import com.mapbox.navigation.core.MapboxNavigation | ||
import com.mapbox.navigation.core.MapboxNavigationProvider | ||
import com.mapbox.navigation.core.replay.route.ReplayRouteSession | ||
import com.mapbox.navigation.core.trip.session.VoiceInstructionsObserver | ||
import com.mapbox.navigation.instrumentation_tests.utils.assertions.waitUntilHasSize | ||
import com.mapbox.navigation.instrumentation_tests.utils.history.MapboxHistoryTestRule | ||
import com.mapbox.navigation.instrumentation_tests.utils.location.MockLocationReplayerRule | ||
import com.mapbox.navigation.instrumentation_tests.utils.location.stayOnPosition | ||
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.BaseCoreNoCleanUpTest | ||
import com.mapbox.navigation.testing.ui.utils.MapboxNavigationRule | ||
import com.mapbox.navigation.testing.ui.utils.coroutines.sdkTest | ||
import com.mapbox.navigation.testing.ui.utils.coroutines.setNavigationRoutesAsync | ||
import com.mapbox.navigation.testing.ui.utils.getMapboxAccessTokenFromResources | ||
import org.junit.Assert | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.net.URI | ||
|
||
class VoiceInstructionsTest : BaseCoreNoCleanUpTest() { | ||
|
||
@get:Rule | ||
val mapboxNavigationRule = MapboxNavigationRule() | ||
|
||
@get:Rule | ||
val mockLocationReplayerRule = MockLocationReplayerRule(mockLocationUpdatesRule) | ||
|
||
@get:Rule | ||
val mapboxHistoryTestRule = MapboxHistoryTestRule() | ||
|
||
@Before | ||
fun setup() { | ||
Espresso.onIdle() | ||
} | ||
|
||
override fun setupMockLocation(): Location { | ||
val mockRoute = RoutesProvider.dc_very_short(context) | ||
return mockLocationUpdatesRule.generateLocationUpdate { | ||
latitude = mockRoute.routeWaypoints.first().latitude() | ||
longitude = mockRoute.routeWaypoints.first().longitude() | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class) | ||
@Test | ||
fun voiceInstructionIsDuplicatedOnceWhenReplayIsStarted() = sdkTest { | ||
val mockRoute = RoutesProvider.dc_very_short(context) | ||
mockWebServerRule.requestHandlers.addAll(mockRoute.mockRequestHandlers) | ||
val voiceInstructions = mutableListOf<VoiceInstructions>() | ||
val voiceInstructionsObserver = VoiceInstructionsObserver { | ||
voiceInstructions.add(it) | ||
} | ||
val mapboxNavigation = createMapboxNavigation() | ||
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver) | ||
stayOnPosition( | ||
mockRoute.routeWaypoints.first(), | ||
0f, | ||
) { | ||
mapboxNavigation.startTripSession() | ||
mapboxNavigation.setNavigationRoutesAsync(mockRoute.toNavigationRoutes()) | ||
voiceInstructions.waitUntilHasSize(1) | ||
} | ||
val relayRouteSession = ReplayRouteSession() | ||
relayRouteSession.onAttached(mapboxNavigation) | ||
voiceInstructions.waitUntilHasSize(3) | ||
|
||
// the first instruction is duplicated once as a result of starting replay session | ||
assertEquals(voiceInstructions[0], voiceInstructions[1]) | ||
// the first instruction id not duplicated anymore | ||
assertNotEquals(voiceInstructions[1], voiceInstructions[2]) | ||
} | ||
|
||
private fun createMapboxNavigation(): MapboxNavigation { | ||
val navigationOptions = NavigationOptions.Builder(context) | ||
.accessToken(getMapboxAccessTokenFromResources(context)) | ||
.routingTilesOptions( | ||
RoutingTilesOptions.Builder() | ||
.tilesBaseUri(URI(mockWebServerRule.baseUrl)) | ||
.build() | ||
) | ||
.build() | ||
return MapboxNavigationProvider.create(navigationOptions).also { | ||
mapboxHistoryTestRule.historyRecorder = it.historyRecorder | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...dTest/java/com/mapbox/navigation/instrumentation_tests/utils/assertions/ListAssertions.kt
This file contains 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,14 @@ | ||
package com.mapbox.navigation.instrumentation_tests.utils.assertions | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.withTimeout | ||
|
||
suspend fun List<*>.waitUntilHasSize(size: Int) { | ||
val list = this | ||
withTimeout(10000) { | ||
while (list.size < size) { | ||
delay(50) | ||
} | ||
} | ||
} | ||
|
This file contains 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