Skip to content

Commit 5af902d

Browse files
committed
Add start test for the view model
1 parent 8c76a46 commit 5af902d

1 file changed

Lines changed: 56 additions & 82 deletions

File tree

Lines changed: 56 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
package org.wordpress.android.ui.voicetocontent
22

33
import kotlinx.coroutines.ExperimentalCoroutinesApi
4+
import org.junit.Before
45
import org.junit.runner.RunWith
6+
import org.mockito.Mock
57
import org.mockito.junit.MockitoJUnitRunner
8+
import org.mockito.kotlin.verifyNoInteractions
9+
import org.mockito.kotlin.whenever
610
import org.wordpress.android.BaseUnitTest
11+
import org.wordpress.android.ui.mysite.SelectedSiteRepository
12+
import org.wordpress.android.viewmodel.ContextProvider
13+
import kotlin.test.Test
714

8-
//@ExperimentalCoroutinesApi
9-
//@RunWith(MockitoJUnitRunner::class)
10-
//class VoiceToContentViewModelTest : BaseUnitTest() {
11-
// @Mock
12-
// lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils
13-
//
14-
// @Mock
15-
// lateinit var voiceToContentUseCase: VoiceToContentUseCase
16-
//
17-
// @Mock
18-
// lateinit var recordingUseCase: RecordingUseCase
19-
//
20-
// @Mock
21-
// lateinit var selectedSiteRepository: SelectedSiteRepository
22-
//
23-
// @Mock
24-
// lateinit var jetpackAIStore: JetpackAIStore
25-
//
26-
// private lateinit var viewModel: VoiceToContentViewModel
27-
//
28-
// private lateinit var uiState: MutableList<VoiceToContentResult>
15+
@ExperimentalCoroutinesApi
16+
@RunWith(MockitoJUnitRunner::class)
17+
class VoiceToContentViewModelTest : BaseUnitTest() {
18+
@Mock
19+
lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils
20+
21+
@Mock
22+
lateinit var voiceToContentUseCase: VoiceToContentUseCase
23+
24+
@Mock
25+
lateinit var recordingUseCase: RecordingUseCase
2926

30-
/* private val jetpackAIAssistantFeature = JetpackAIAssistantFeature(
27+
@Mock
28+
lateinit var selectedSiteRepository: SelectedSiteRepository
29+
30+
@Mock
31+
lateinit var prepareVoiceToContentUseCase: PrepareVoiceToContentUseCase
32+
33+
@Mock
34+
lateinit var contextProvider: ContextProvider
35+
36+
private lateinit var viewModel: VoiceToContentViewModel
37+
38+
// private lateinit var uiState: MutableList<VoiceToContentResult>
39+
40+
/* private val jetpackAIAssistantFeature = JetpackAIAssistantFeature(
3141
hasFeature = true,
3242
isOverLimit = false,
3343
requestsCount = 0,
@@ -42,76 +52,40 @@ import org.wordpress.android.BaseUnitTest
4252
costs = null
4353
)*/
4454

45-
// @Before
46-
// fun setup() {
47-
// // Mock the recording updates to return a non-null flow before ViewModel instantiation
48-
// whenever(recordingUseCase.recordingUpdates()).thenReturn(createRecordingUpdateFlow())
49-
//
50-
// viewModel = VoiceToContentViewModel(
51-
// testDispatcher(),
52-
// voiceToContentFeatureUtils,
53-
// voiceToContentUseCase,
54-
// selectedSiteRepository,
55-
// jetpackAIStore,
56-
// recordingUseCase
57-
// )
58-
//
55+
@Before
56+
fun setup() {
57+
// Mock the recording updates to return a non-null flow before ViewModel instantiation
58+
//whenever(recordingUseCase.recordingUpdates()).thenReturn(createRecordingUpdateFlow())
59+
60+
viewModel = VoiceToContentViewModel(
61+
testDispatcher(),
62+
voiceToContentFeatureUtils,
63+
voiceToContentUseCase,
64+
selectedSiteRepository,
65+
recordingUseCase,
66+
contextProvider,
67+
prepareVoiceToContentUseCase
68+
)
5969
// uiState = mutableListOf()
6070
// viewModel.uiState.observeForever { event ->
6171
// event?.let { result ->
6272
// uiState.add(result)
6373
// }
6474
// }
65-
// }
66-
//
75+
}
76+
77+
//
6778
// // Helper function to create a consistent flow
6879
// private fun createRecordingUpdateFlow() = flow {
6980
// emit(RecordingUpdate(0, 0, false))
7081
// }
7182
//
72-
// @Test
73-
// fun `when site is null, then execute posts error state `() = test {
74-
// whenever(selectedSiteRepository.getSelectedSite()).thenReturn(null)
75-
// val dummyFile = File("dummy_path")
76-
// viewModel.executeVoiceToContent(dummyFile)
77-
//
78-
// val expectedState = VoiceToContentResult(isError = true)
79-
// assertThat(uiState.first()).isEqualTo(expectedState)
80-
// }
81-
//
82-
// /* @Test
83-
// fun `when voice to content is enabled, then execute invokes use case `() = test {
84-
// val site = SiteModel().apply { id = 1 }
85-
// val dummyFile = File("dummy_path")
86-
//
87-
// whenever(selectedSiteRepository.getSelectedSite()).thenReturn(site)
88-
// whenever(voiceToContentFeatureUtils.isVoiceToContentEnabled()).thenReturn(true)
89-
// whenever(jetpackAIStore.fetchJetpackAIAssistantFeature(site))
90-
// .thenReturn(JetpackAIAssistantFeatureResponse.Success(jetpackAIAssistantFeature))
91-
//
92-
// viewModel.executeVoiceToContent(dummyFile)
93-
//
94-
// verify(voiceToContentUseCase).execute(site, dummyFile)
95-
// }*/
96-
//
97-
//// @Test
98-
//// fun `when voice to content is disabled, then executeVoiceToContent does not invoke use case`() = runTest {
99-
//// val site = SiteModel().apply { id = 1 }
100-
//// whenever(selectedSiteRepository.getSelectedSite()).thenReturn(site)
101-
//// whenever(voiceToContentFeatureUtils.isVoiceToContentEnabled()).thenReturn(false)
102-
//// val dummyFile = File("dummy_path")
103-
////
104-
//// viewModel.executeVoiceToContent(dummyFile)
105-
////
106-
//// verifyNoInteractions(voiceToContentUseCase)
107-
//// }
108-
//
109-
// @Test
110-
// fun `when startRecording is called, then recordingUseCase starts recording`() {
111-
// viewModel.startRecording()
112-
//
113-
// verify(recordingUseCase).startRecording(any())
114-
// }
115-
//}
83+
@Test
84+
fun `when site is null, then execute posts error state `() = test {
85+
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(null)
11686

87+
viewModel.start()
11788

89+
verifyNoInteractions(prepareVoiceToContentUseCase)
90+
}
91+
}

0 commit comments

Comments
 (0)