@@ -13,6 +13,7 @@ import com.mapbox.navigation.ui.voice.view.MapboxAudioGuidanceButton
1313import io.mockk.every
1414import io.mockk.mockk
1515import io.mockk.mockkObject
16+ import io.mockk.slot
1617import io.mockk.spyk
1718import io.mockk.unmockkAll
1819import io.mockk.verify
@@ -21,6 +22,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
2122import kotlinx.coroutines.flow.MutableStateFlow
2223import org.junit.After
2324import org.junit.Assert.assertFalse
25+ import org.junit.Assert.assertTrue
2426import org.junit.Before
2527import org.junit.Rule
2628import org.junit.Test
@@ -112,8 +114,8 @@ class AudioGuidanceButtonComponentTest {
112114 every { toggle() } returns Unit
113115 }
114116 every {
115- MapboxNavigationApp .getObserver (MapboxAudioGuidance ::class )
116- } returns mockAudioGuidance
117+ MapboxNavigationApp .getObservers (MapboxAudioGuidance ::class )
118+ } returns listOf ( mockAudioGuidance)
117119
118120 val sut = AudioGuidanceButtonComponent (button)
119121 sut.onAttached(mapboxNavigation)
@@ -122,6 +124,23 @@ class AudioGuidanceButtonComponentTest {
122124 verify { mockAudioGuidance.mute() }
123125 }
124126
127+ @Test
128+ fun `onAttach - create MapboxAudioGuidance if none exists` () {
129+ val slotAudioGuidance = slot<MapboxAudioGuidance >()
130+ every {
131+ MapboxNavigationApp .getObservers(MapboxAudioGuidance ::class )
132+ } returns emptyList()
133+ every {
134+ MapboxNavigationApp .registerObserver(capture(slotAudioGuidance))
135+ } returns MapboxNavigationApp
136+
137+ val sut = AudioGuidanceButtonComponent (button)
138+ sut.onAttached(mapboxNavigation)
139+ button.performClick()
140+
141+ assertTrue(slotAudioGuidance.isCaptured)
142+ }
143+
125144 @Test
126145 fun `onDetached - should not handle button on click events` () {
127146 sut.onAttached(mapboxNavigation)
0 commit comments