|
| 1 | +package com.mapbox.navigation.dropin.navigationview |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import androidx.core.content.ContextCompat |
| 5 | +import androidx.test.core.app.ApplicationProvider |
| 6 | +import com.mapbox.maps.plugin.LocationPuck2D |
| 7 | +import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions |
| 8 | +import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI |
| 9 | +import com.mapbox.navigation.dropin.R |
| 10 | +import com.mapbox.navigation.dropin.ViewStyleCustomization |
| 11 | +import com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions |
| 12 | +import org.junit.Assert.assertEquals |
| 13 | +import org.junit.Before |
| 14 | +import org.junit.Test |
| 15 | +import org.junit.runner.RunWith |
| 16 | +import org.robolectric.RobolectricTestRunner |
| 17 | + |
| 18 | +@OptIn(ExperimentalPreviewMapboxNavigationAPI::class) |
| 19 | +@RunWith(RobolectricTestRunner::class) |
| 20 | +class NavigationViewStylesTest { |
| 21 | + |
| 22 | + private lateinit var ctx: Context |
| 23 | + private lateinit var sut: NavigationViewStyles |
| 24 | + |
| 25 | + @Before |
| 26 | + fun setUp() { |
| 27 | + ctx = ApplicationProvider.getApplicationContext() |
| 28 | + sut = NavigationViewStyles(ctx) |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + fun `applyCustomization should update NON NULL values`() { |
| 33 | + val c = customization() |
| 34 | + |
| 35 | + sut.applyCustomization(c) |
| 36 | + |
| 37 | + assertEquals(c.infoPanelPeekHeight, sut.infoPanelPeekHeight.value) |
| 38 | + assertEquals(c.infoPanelMarginStart, sut.infoPanelMarginStart.value) |
| 39 | + assertEquals(c.infoPanelMarginEnd, sut.infoPanelMarginEnd.value) |
| 40 | + assertEquals(c.infoPanelBackground, sut.infoPanelBackground.value) |
| 41 | + assertEquals(c.poiNameTextAppearance, sut.poiNameTextAppearance.value) |
| 42 | + assertEquals(c.tripProgressStyle, sut.tripProgressStyle.value) |
| 43 | + assertEquals(c.compassButtonStyle, sut.compassButtonStyle.value) |
| 44 | + assertEquals(c.recenterButtonStyle, sut.recenterButtonStyle.value) |
| 45 | + assertEquals(c.audioGuidanceButtonStyle, sut.audioGuidanceButtonStyle.value) |
| 46 | + assertEquals(c.cameraModeButtonStyle, sut.cameraModeButtonStyle.value) |
| 47 | + assertEquals(c.routePreviewButtonStyle, sut.routePreviewButtonStyle.value) |
| 48 | + assertEquals(c.endNavigationButtonStyle, sut.endNavigationButtonStyle.value) |
| 49 | + assertEquals(c.startNavigationButtonStyle, sut.startNavigationButtonStyle.value) |
| 50 | + assertEquals(c.speedLimitStyle, sut.speedLimitStyle.value) |
| 51 | + assertEquals(c.maneuverViewOptions, sut.maneuverViewOptions.value) |
| 52 | + assertEquals(c.speedLimitTextAppearance, sut.speedLimitTextAppearance.value) |
| 53 | + assertEquals( |
| 54 | + c.destinationMarkerAnnotationOptions, |
| 55 | + sut.destinationMarkerAnnotationOptions.value |
| 56 | + ) |
| 57 | + assertEquals(c.roadNameBackground, sut.roadNameBackground.value) |
| 58 | + assertEquals(c.roadNameTextAppearance, sut.roadNameTextAppearance.value) |
| 59 | + assertEquals(c.arrivalTextAppearance, sut.arrivalTextAppearance.value) |
| 60 | + assertEquals(c.locationPuck, sut.locationPuck.value) |
| 61 | + } |
| 62 | + |
| 63 | + private fun customization() = ViewStyleCustomization().apply { |
| 64 | + infoPanelPeekHeight = 1 |
| 65 | + infoPanelMarginStart = 2 |
| 66 | + infoPanelMarginEnd = 3 |
| 67 | + infoPanelBackground = android.R.drawable.spinner_background |
| 68 | + poiNameTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large |
| 69 | + tripProgressStyle = R.style.MapboxStyleTripProgressView |
| 70 | + compassButtonStyle = R.style.MapboxStyleExtendableButton_Circle |
| 71 | + recenterButtonStyle = R.style.MapboxStyleExtendableButton_Circle |
| 72 | + audioGuidanceButtonStyle = R.style.MapboxStyleAudioGuidanceButton_Circle |
| 73 | + cameraModeButtonStyle = R.style.MapboxStyleCameraModeButton_Circle |
| 74 | + routePreviewButtonStyle = R.style.MapboxStyleExtendableButton_Circle |
| 75 | + endNavigationButtonStyle = R.style.MapboxStyleExtendableButton_Circle |
| 76 | + startNavigationButtonStyle = R.style.MapboxStyleExtendableButton_Circle |
| 77 | + speedLimitStyle = R.style.MapboxStyleSpeedLimit |
| 78 | + maneuverViewOptions = ManeuverViewOptions.Builder().build() |
| 79 | + speedLimitTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large |
| 80 | + destinationMarkerAnnotationOptions = PointAnnotationOptions() |
| 81 | + roadNameBackground = android.R.drawable.spinner_background |
| 82 | + roadNameTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large |
| 83 | + arrivalTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large |
| 84 | + locationPuck = LocationPuck2D( |
| 85 | + bearingImage = ContextCompat.getDrawable( |
| 86 | + ctx, |
| 87 | + android.R.drawable.ic_media_play |
| 88 | + ) |
| 89 | + ) |
| 90 | + } |
| 91 | +} |
0 commit comments