Skip to content
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

add disableContinuousAlternatives test #7481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mapbox.navigation.base.trip.model.RouteProgress
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.directions.session.RoutesExtra
import com.mapbox.navigation.core.internal.extensions.flowLocationMatcherResult
import com.mapbox.navigation.core.internal.extensions.flowOnFinalDestinationArrival
import com.mapbox.navigation.core.routealternatives.NavigationRouteAlternativesObserver
import com.mapbox.navigation.core.routealternatives.RouteAlternativesError
import com.mapbox.navigation.instrumentation_tests.R
Expand Down Expand Up @@ -301,6 +302,55 @@ class RouteAlternativesTest : BaseCoreNoCleanUpTest() {
}
}

@Test // NN-1023
fun disableContinuousAlternatives() = sdkTest {
setupMockRequestHandlers()
withMapboxNavigation(
customConfig = """{"navigation":{"alternativeRoutes":{"maxAlternatives":0}}}""",
historyRecorderRule = mapboxHistoryTestRule
) { mapboxNavigation ->
val routes = mapboxNavigation.requestNavigationRoutes(startCoordinates)

mockWebServerRule.requestHandlers.clear()
mockWebServerRule.requestHandlers.add(
MockDirectionsRequestHandler(
"driving-traffic",
readRawFileText(context, R.raw.route_response_alternative_during_navigation),
startCoordinates,
relaxedExpectedCoordinates = true
)
)
stayOnPosition(
startCoordinates.first().latitude(),
startCoordinates.first().longitude(),
30f
) {
mapboxNavigation.startTripSession()
mapboxNavigation.flowLocationMatcherResult().first()
}
mapboxNavigation.setNavigationRoutesAsync(routes)
var alternativeUpdates = 0
mapboxNavigation.registerRouteAlternativesObserver(
object : NavigationRouteAlternativesObserver {
override fun onRouteAlternatives(
routeProgress: RouteProgress,
alternatives: List<NavigationRoute>,
routerOrigin: RouterOrigin
) {
alternativeUpdates++
}

override fun onRouteAlternativesError(error: RouteAlternativesError) {
}
}
)
mockLocationReplayerRule.playRoute(routes.first().directionsRoute)

mapboxNavigation.flowOnFinalDestinationArrival().first()
assertEquals(0, alternativeUpdates)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expect 1 update which removes passed alternative?

}
}

private fun createExternalAlternatives(): List<NavigationRoute> {
return NavigationRoute.create(
readRawFileText(context, R.raw.route_response_alternative_continue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mapbox.bindgen.Value
import com.mapbox.common.TileDataDomain
import com.mapbox.common.TileStore
import com.mapbox.common.TileStoreOptions
import com.mapbox.navigation.base.options.DeviceProfile
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.base.options.RoutingTilesOptions
import com.mapbox.navigation.core.MapboxNavigation
Expand All @@ -17,6 +18,7 @@ import java.net.URI
suspend inline fun BaseCoreNoCleanUpTest.withMapboxNavigation(
useRealTiles: Boolean = false,
tileStore: TileStore? = null,
customConfig: String? = null,
historyRecorderRule: MapboxHistoryTestRule? = null, // TODO: copy features to new infra
block: (navigation: MapboxNavigation) -> Unit
) {
Expand All @@ -37,6 +39,9 @@ suspend inline fun BaseCoreNoCleanUpTest.withMapboxNavigation(
.tileStore(tileStore)
.build()
routingTilesOptions(routingTilesOptions)
customConfig?.let {
deviceProfile(DeviceProfile.Builder().customConfig(it).build())
}
}
.build()
)
Expand Down