|
| 1 | +package com.mapbox.navigation.dropin.component.recenter |
| 2 | + |
| 3 | +import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI |
| 4 | +import com.mapbox.navigation.dropin.util.TestStore |
| 5 | +import com.mapbox.navigation.testing.MainCoroutineRule |
| 6 | +import com.mapbox.navigation.ui.app.internal.camera.CameraAction |
| 7 | +import com.mapbox.navigation.ui.app.internal.camera.TargetCameraMode |
| 8 | +import com.mapbox.navigation.ui.app.internal.navigation.NavigationState |
| 9 | +import io.mockk.mockk |
| 10 | +import io.mockk.spyk |
| 11 | +import io.mockk.verify |
| 12 | +import kotlinx.coroutines.ExperimentalCoroutinesApi |
| 13 | +import kotlinx.coroutines.yield |
| 14 | +import org.junit.Assert.assertFalse |
| 15 | +import org.junit.Assert.assertTrue |
| 16 | +import org.junit.Before |
| 17 | +import org.junit.Rule |
| 18 | +import org.junit.Test |
| 19 | + |
| 20 | +@OptIn(ExperimentalPreviewMapboxNavigationAPI::class, ExperimentalCoroutinesApi::class) |
| 21 | +class RecenterButtonComponentContractImplTest { |
| 22 | + |
| 23 | + @get:Rule |
| 24 | + var coroutineRule = MainCoroutineRule() |
| 25 | + |
| 26 | + private lateinit var store: TestStore |
| 27 | + private lateinit var sut: RecenterButtonComponentContractImpl |
| 28 | + |
| 29 | + @Before |
| 30 | + fun setUp() { |
| 31 | + store = spyk(TestStore()) |
| 32 | + sut = RecenterButtonComponentContractImpl(coroutineRule.coroutineScope, store) |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun `isVisible - should return TRUE when camera is Idle and not in RoutePreview`() = |
| 37 | + coroutineRule.runBlockingTest { |
| 38 | + store.updateState { |
| 39 | + it.copy( |
| 40 | + camera = it.camera.copy(cameraMode = TargetCameraMode.Idle), |
| 41 | + navigation = NavigationState.FreeDrive |
| 42 | + ) |
| 43 | + } |
| 44 | + yield() // yielding to allow isVisible StateFlow run its logic |
| 45 | + assertTrue( |
| 46 | + "expected TRUE when camera is Idle and not in RoutePreview", |
| 47 | + sut.isVisible.value |
| 48 | + ) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + fun `isVisible - should return FALSE when camera not Idle or in RoutePreview`() = |
| 53 | + coroutineRule.runBlockingTest { |
| 54 | + store.updateState { |
| 55 | + it.copy( |
| 56 | + camera = it.camera.copy(cameraMode = TargetCameraMode.Following), |
| 57 | + navigation = NavigationState.FreeDrive |
| 58 | + ) |
| 59 | + } |
| 60 | + yield() // yielding to allow isVisible StateFlow run its logic |
| 61 | + assertFalse("expected FALSE when camera not Idle", sut.isVisible.value) |
| 62 | + |
| 63 | + store.updateState { |
| 64 | + it.copy( |
| 65 | + camera = it.camera.copy(cameraMode = TargetCameraMode.Idle), |
| 66 | + navigation = NavigationState.RoutePreview |
| 67 | + ) |
| 68 | + } |
| 69 | + yield() // yielding to allow isVisible StateFlow run its logic |
| 70 | + assertFalse("expected FALSE when NavigationState not RoutePreview", sut.isVisible.value) |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + fun `onClick should dispatch SetCameraMode action`() { |
| 75 | + sut.onClick(mockk()) |
| 76 | + |
| 77 | + verify { store.dispatch(CameraAction.SetCameraMode(TargetCameraMode.Following)) } |
| 78 | + } |
| 79 | +} |
0 commit comments