Skip to content

Commit

Permalink
added instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VysotskiVadim committed Oct 25, 2023
1 parent a5bd6af commit b34d8a2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import com.mapbox.api.directions.v5.models.RouteOptions
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions
import com.mapbox.navigation.base.options.LongRoutesOptimisationOptions
import com.mapbox.navigation.core.directions.session.RoutesExtra
import com.mapbox.navigation.core.internal.extensions.flowRouteProgress
import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.utils.DelayedResponseModifier
import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRequestHandler
import com.mapbox.navigation.instrumentation_tests.utils.location.stayOnPosition
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.instrumentation_tests.utils.routes.RoutesProvider
import com.mapbox.navigation.instrumentation_tests.utils.withMapboxNavigation
import com.mapbox.navigation.testing.ui.BaseCoreNoCleanUpTest
import com.mapbox.navigation.testing.ui.utils.coroutines.getSuccessfulResultOrThrowException
import com.mapbox.navigation.testing.ui.utils.coroutines.requestRoutes
import com.mapbox.navigation.testing.ui.utils.coroutines.routesPreviewUpdates
import com.mapbox.navigation.testing.ui.utils.coroutines.routesUpdates
import com.mapbox.navigation.testing.ui.utils.coroutines.sdkTest
import com.mapbox.navigation.testing.ui.utils.coroutines.setNavigationRoutesAsync
import kotlinx.coroutines.flow.filterNotNull
Expand Down Expand Up @@ -59,7 +63,8 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
val longRoutesOptions = setupLongRoutes()
val shortRoutesOptions = setupShortRoutes()
withMapboxNavigation(
longRoutesOptimisationOptions = LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
longRoutesOptimisationOptions =
LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
Expand All @@ -84,7 +89,8 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
val longRoutesOptions = setupLongRoutes()
val shortRoutesOptions = setupShortRoutes()
withMapboxNavigation(
longRoutesOptimisationOptions = LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
longRoutesOptimisationOptions =
LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
Expand Down Expand Up @@ -112,10 +118,47 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
}
}

@Test
fun rerouteOnLongRoute() = sdkTest(60_000) {
val longRoutesOptions = setupLongRoutes()
val longRoutesRerouteOptions = setupLongRoutesReroute()
withMapboxNavigation(
longRoutesOptimisationOptions =
LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
navigation.setNavigationRoutesAsync(
navigation
.requestRoutes(longRoutesOptions)
.getSuccessfulResultOrThrowException().routes
)
assertEquals(2, navigation.getNavigationRoutes().size)

val rerouteOrigin = longRoutesRerouteOptions.coordinatesList().first()
stayOnPosition(
latitude = rerouteOrigin.latitude(),
longitude = rerouteOrigin.longitude(),
bearing = 190.0f
) {
navigation.startTripSession()
navigation.flowRouteProgress().first()
val droppingAlternatives = navigation.routesUpdates().first {
it.reason == RoutesExtra.ROUTES_UPDATE_REASON_ALTERNATIVE
}
assertEquals(1, droppingAlternatives.navigationRoutes.size)
val reroute = navigation.routesUpdates().first {
it.reason == RoutesExtra.ROUTES_UPDATE_REASON_REROUTE
}
assertEquals(2, reroute.navigationRoutes.size)
}
}
}

private fun setupLongRoutes(): RouteOptions {
val routeOptions = longRouteOptions()
val handler = MockDirectionsRequestHandler(
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
profile = routeOptions.profile(),
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k) },
expectedCoordinates = routeOptions.coordinatesList()
)
Expand All @@ -141,6 +184,35 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
return routeOptions
}

private fun setupLongRoutesReroute(): RouteOptions {
val routeOptions = longRouteRerouteOptions()
val handler = MockDirectionsRequestHandler(
profile = routeOptions.profile(),
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k_reroute) },
expectedCoordinates = routeOptions.coordinatesList()
)
mockWebServerRule.requestHandlers.add(handler)
return routeOptions
}

private fun longRouteRerouteOptions(): RouteOptions {
val routeOptions = RouteOptions.builder()
.baseUrl(mockWebServerRule.baseUrl) // comment to use real Directions API
.applyDefaultNavigationOptions()
.coordinates(
"4.899038,52.373577" +
";5.359980783143584,43.280050656855906" +
";11.571179644010442,48.145540095763664" +
";13.394784408007155,52.51274942160785" +
";-9.143239539655042,38.70880224984026" +
";9.21595128801522,45.4694220491258"
)
.alternatives(true)
.enableRefresh(true)
.build()
return routeOptions
}

private fun setupShortRoutes(): RouteOptions {
val shortRoute = RoutesProvider.dc_very_short(context)
mockWebServerRule.requestHandlers.addAll(shortRoute.mockRequestHandlers)
Expand Down

Large diffs are not rendered by default.

0 comments on commit b34d8a2

Please sign in to comment.