Skip to content

Commit

Permalink
added test for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
VysotskiVadim committed Oct 25, 2023
1 parent 043e438 commit 04b729b
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ 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.sdkTest
import com.mapbox.navigation.testing.ui.utils.coroutines.setNavigationRoutesAsync
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -76,6 +80,41 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
}
}

@Test
fun requestNewRoutesWhileLongRoutesArePreviewed() = sdkTest {
val routeOptions = longRouteOptions()
val handler = MockDirectionsRequestHandler(
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k) },
expectedCoordinates = routeOptions.coordinatesList()
)
mockWebServerRule.requestHandlers.add(handler)
withMapboxNavigation(
longRoutesOptimisationOptions = LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
navigation.setRoutesPreview(
navigation
.requestRoutes(routeOptions)
.getSuccessfulResultOrThrowException().routes
)

assertEquals(
2,
navigation.routesPreviewUpdates()
.map { it.routesPreview }
.filterNotNull()
.first()
.routesList.size
)

val newRoutes = navigation.requestRoutes(routeOptions)
.getSuccessfulResultOrThrowException()
assertEquals(1, navigation.getRoutesPreview()?.routesList?.size)
}
}

private fun longRouteOptions(): RouteOptions {
val routeOptions = RouteOptions.builder()
.baseUrl(mockWebServerRule.baseUrl) // comment to use real Directions API
Expand Down

0 comments on commit 04b729b

Please sign in to comment.