@@ -7,9 +7,6 @@ import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
77import com.mapbox.navigation.core.MapboxNavigation
88import com.mapbox.navigation.dropin.MapboxMapScalebarParams
99import com.mapbox.navigation.testing.MainCoroutineRule
10- import com.mapbox.navigation.ui.app.internal.State
11- import com.mapbox.navigation.ui.app.internal.navigation.NavigationState
12- import com.mapbox.navigation.ui.app.internal.routefetch.RoutePreviewState
1310import io.mockk.clearMocks
1411import io.mockk.mockk
1512import io.mockk.verify
@@ -30,39 +27,26 @@ class ScalebarPlaceholderComponentTest {
3027 private val context = ApplicationProvider .getApplicationContext<Context >()
3128 private val mapboxNavigation = mockk<MapboxNavigation >()
3229 private val scalebarPlaceholderView = mockk<View >(relaxed = true )
33- private val stateFlow = MutableStateFlow (
34- State (
35- navigation = NavigationState .FreeDrive ,
36- previewRoutes = RoutePreviewState .Ready (emptyList())
37- )
30+ private val initialHeight = 7
31+ private val heightFlow = MutableStateFlow (initialHeight)
32+ private val mapScalebarParams = MutableStateFlow (
33+ MapboxMapScalebarParams .Builder (context).build()
34+ )
35+ private val component = ScalebarPlaceholderComponent (
36+ scalebarPlaceholderView,
37+ mapScalebarParams,
38+ heightFlow
3839 )
39- private val mapScalebarParams = MutableStateFlow (MapboxMapScalebarParams .Builder (context).build())
40- private val component = ScalebarPlaceholderComponent (scalebarPlaceholderView, mapScalebarParams, stateFlow)
41-
42- @Test
43- fun visibilityIsChangedOnOnAttachedActiveGuidance () {
44- stateFlow.tryEmit(State (navigation = NavigationState .FreeDrive ))
45- component.onAttached(mapboxNavigation)
46- verify { scalebarPlaceholderView.visibility = View .GONE }
47- }
48-
49- @Test
50- fun visibilityIsChangedOnOnAttachedFreeDrive () {
51- stateFlow.tryEmit(State (navigation = NavigationState .FreeDrive ))
52- component.onAttached(mapboxNavigation)
53- verify { scalebarPlaceholderView.visibility = View .GONE }
54- }
5540
5641 @Test
57- fun visibilityIsChangedOnOnAttachedRoutePreview () {
58- stateFlow.tryEmit(State (navigation = NavigationState .RoutePreview ))
42+ fun visibilityIsChangedOnOnAttachedHasHeight () {
5943 component.onAttached(mapboxNavigation)
6044 verify { scalebarPlaceholderView.visibility = View .GONE }
6145 }
6246
6347 @Test
64- fun visibilityIsChangedOnOnAttachedDestinationPreview () {
65- stateFlow .tryEmit(State (navigation = NavigationState . RoutePreview ) )
48+ fun visibilityIsChangedOnOnAttachedNoHeight () {
49+ heightFlow .tryEmit(0 )
6650 component.onAttached(mapboxNavigation)
6751 verify { scalebarPlaceholderView.visibility = View .GONE }
6852 }
@@ -74,80 +58,43 @@ class ScalebarPlaceholderComponentTest {
7458 }
7559
7660 @Test
77- fun stateChangeBeforeOnAttached () {
78- stateFlow .tryEmit(State (navigation = NavigationState . RoutePreview ) )
61+ fun heightChangeBeforeOnAttached () {
62+ heightFlow .tryEmit(8 )
7963 verify(exactly = 0 ) { scalebarPlaceholderView.visibility = any() }
8064 }
8165
8266 @Test
83- fun mapScalebarParamsChangeAfterOnAttachedActiveGuidance () {
84- stateFlow.tryEmit(State (navigation = NavigationState .ActiveNavigation ))
85- component.onAttached(mapboxNavigation)
86- clearMocks(scalebarPlaceholderView)
87- mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
88- verify { scalebarPlaceholderView.visibility = View .GONE }
89- }
90-
91- @Test
92- fun mapScalebarParamsChangeAfterOnAttachedFreeDrive () {
93- stateFlow.tryEmit(State (navigation = NavigationState .ActiveNavigation ))
67+ fun mapScalebarParamsChangeAfterOnAttachedHasHeight () {
9468 component.onAttached(mapboxNavigation)
9569 clearMocks(scalebarPlaceholderView)
9670 mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
9771 verify { scalebarPlaceholderView.visibility = View .GONE }
9872 }
9973
10074 @Test
101- fun mapScalebarParamsChangeAfterOnAttachedRoutePreview () {
102- stateFlow .tryEmit(State (navigation = NavigationState . RoutePreview ) )
75+ fun mapScalebarParamsChangeAfterOnAttachedNoHeight () {
76+ heightFlow .tryEmit(0 )
10377 component.onAttached(mapboxNavigation)
10478 clearMocks(scalebarPlaceholderView)
10579 mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
10680 verify { scalebarPlaceholderView.visibility = View .VISIBLE }
10781 }
10882
10983 @Test
110- fun mapScalebarParamsChangeAfterOnAttachedDestinationPreview () {
111- stateFlow.tryEmit(State (navigation = NavigationState .DestinationPreview ))
112- component.onAttached(mapboxNavigation)
113- clearMocks(scalebarPlaceholderView)
114- mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
115- verify { scalebarPlaceholderView.visibility = View .VISIBLE }
116- }
117-
118- @Test
119- fun stateChangeAfterOnAttachedActiveGuidance () {
84+ fun heightChangeAfterOnAttachedHasHeight () {
12085 mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
12186 component.onAttached(mapboxNavigation)
12287 clearMocks(scalebarPlaceholderView)
123- stateFlow .tryEmit(State (navigation = NavigationState . ActiveNavigation ) )
88+ heightFlow .tryEmit(8 )
12489 verify { scalebarPlaceholderView.visibility = View .GONE }
12590 }
12691
12792 @Test
128- fun stateChangeAfterOnAttachedFreeDrive () {
129- mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
130- component.onAttached(mapboxNavigation)
131- clearMocks(scalebarPlaceholderView)
132- stateFlow.tryEmit(State (navigation = NavigationState .FreeDrive ))
133- verify { scalebarPlaceholderView.visibility = View .VISIBLE }
134- }
135-
136- @Test
137- fun stateChangeAfterOnAttachedRoutePreview () {
138- mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
139- component.onAttached(mapboxNavigation)
140- clearMocks(scalebarPlaceholderView)
141- stateFlow.tryEmit(State (navigation = NavigationState .RoutePreview ))
142- verify { scalebarPlaceholderView.visibility = View .VISIBLE }
143- }
144-
145- @Test
146- fun stateChangeAfterOnAttachedDestinationPreview () {
93+ fun heightChangeAfterOnAttachedNoHeight () {
14794 mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
14895 component.onAttached(mapboxNavigation)
14996 clearMocks(scalebarPlaceholderView)
150- stateFlow .tryEmit(State (navigation = NavigationState . DestinationPreview ) )
97+ heightFlow .tryEmit(0 )
15198 verify { scalebarPlaceholderView.visibility = View .VISIBLE }
15299 }
153100
@@ -161,12 +108,12 @@ class ScalebarPlaceholderComponentTest {
161108 }
162109
163110 @Test
164- fun stateChangeAfterOnDetached () {
111+ fun heightChangeAfterOnDetached () {
165112 mapScalebarParams.tryEmit(MapboxMapScalebarParams .Builder (context).enabled(true ).build())
166113 component.onAttached(mapboxNavigation)
167114 clearMocks(scalebarPlaceholderView)
168115 component.onDetached(mapboxNavigation)
169- stateFlow .tryEmit(State (navigation = NavigationState . FreeDrive ) )
116+ heightFlow .tryEmit(9 )
170117 verify(exactly = 0 ) { scalebarPlaceholderView.visibility = any() }
171118 }
172119}
0 commit comments