Skip to content

Commit 0e32735

Browse files
tomaszrybakiewiczabhishek1508
authored andcommitted
More tests and minor tweaks
1 parent eb8b016 commit 0e32735

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/extendablebutton/ArrivalTextComponentTest.kt renamed to libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/arrival/ArrivalTextComponentTest.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mapbox.navigation.dropin.component.infopanel
1+
package com.mapbox.navigation.dropin.arrival
22

33
import android.content.Context
44
import android.os.Build
@@ -12,6 +12,7 @@ import io.mockk.spyk
1212
import io.mockk.verify
1313
import kotlinx.coroutines.ExperimentalCoroutinesApi
1414
import kotlinx.coroutines.flow.MutableStateFlow
15+
import kotlinx.coroutines.runBlocking
1516
import org.junit.Before
1617
import org.junit.Rule
1718
import org.junit.Test
@@ -25,7 +26,7 @@ import org.robolectric.annotation.Config
2526
class ArrivalTextComponentTest {
2627

2728
@get:Rule
28-
var coroutineRule = MainCoroutineRule()
29+
val coroutineRule = MainCoroutineRule()
2930

3031
private lateinit var textView: AppCompatTextView
3132
private lateinit var textAppearance: MutableStateFlow<Int>
@@ -45,4 +46,19 @@ class ArrivalTextComponentTest {
4546

4647
verify { textView.setTextAppearance(textAppearance.value) }
4748
}
49+
50+
@Test
51+
fun `onAttached should observe apply textAppearance style to the textView`() = runBlocking {
52+
sut.onAttached(mockk())
53+
54+
textAppearance.value = R.style.TextAppearance_AppCompat_Small
55+
56+
verify { textView.setTextAppearance(R.style.TextAppearance_AppCompat_Small) }
57+
}
58+
59+
@Test
60+
fun `onAttached not crash when wrong style resource id is used`() {
61+
textAppearance.value = Int.MAX_VALUE
62+
sut.onAttached(mockk())
63+
}
4864
}

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/camera/CameraLayoutObserverTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@file:Suppress("PrivatePropertyName", "MaxLineLength")
22

3-
package com.mapbox.navigation.dropin.component.camera
3+
package com.mapbox.navigation.dropin.camera
44

55
import android.app.Service
66
import android.content.Context

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/recenter/RecenterButtonComponentContractImplTest.kt renamed to libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/camera/RecenterButtonComponentContractImplTest.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mapbox.navigation.dropin.component.recenter
1+
package com.mapbox.navigation.dropin.camera
22

33
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
44
import com.mapbox.navigation.dropin.util.TestStore
@@ -10,7 +10,6 @@ import io.mockk.mockk
1010
import io.mockk.spyk
1111
import io.mockk.verify
1212
import kotlinx.coroutines.ExperimentalCoroutinesApi
13-
import kotlinx.coroutines.yield
1413
import org.junit.Assert.assertFalse
1514
import org.junit.Assert.assertTrue
1615
import org.junit.Before
@@ -21,7 +20,7 @@ import org.junit.Test
2120
class RecenterButtonComponentContractImplTest {
2221

2322
@get:Rule
24-
var coroutineRule = MainCoroutineRule()
23+
val coroutineRule = MainCoroutineRule()
2524

2625
private lateinit var store: TestStore
2726
private lateinit var sut: RecenterButtonComponentContractImpl
@@ -41,32 +40,36 @@ class RecenterButtonComponentContractImplTest {
4140
navigation = NavigationState.FreeDrive
4241
)
4342
}
44-
yield() // yielding to allow isVisible StateFlow run its logic
43+
coroutineRule.testDispatcher.advanceUntilIdle()
4544
assertTrue(
4645
"expected TRUE when camera is Idle and not in RoutePreview",
4746
sut.isVisible.value
4847
)
4948
}
5049

5150
@Test
52-
fun `isVisible - should return FALSE when camera not Idle or in RoutePreview`() =
51+
fun `isVisible - should return FALSE when camera not Idle`() =
5352
coroutineRule.runBlockingTest {
5453
store.updateState {
5554
it.copy(
5655
camera = it.camera.copy(cameraMode = TargetCameraMode.Following),
5756
navigation = NavigationState.FreeDrive
5857
)
5958
}
60-
yield() // yielding to allow isVisible StateFlow run its logic
59+
coroutineRule.testDispatcher.advanceUntilIdle()
6160
assertFalse("expected FALSE when camera not Idle", sut.isVisible.value)
61+
}
6262

63+
@Test
64+
fun `isVisible - should return FALSE when camera in RoutePreview`() =
65+
coroutineRule.runBlockingTest {
6366
store.updateState {
6467
it.copy(
6568
camera = it.camera.copy(cameraMode = TargetCameraMode.Idle),
6669
navigation = NavigationState.RoutePreview
6770
)
6871
}
69-
yield() // yielding to allow isVisible StateFlow run its logic
72+
coroutineRule.testDispatcher.advanceUntilIdle()
7073
assertFalse("expected FALSE when NavigationState not RoutePreview", sut.isVisible.value)
7174
}
7275

0 commit comments

Comments
 (0)