Skip to content

Commit

Permalink
Address failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Jun 11, 2024
1 parent 7859334 commit fbc2040
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.wordpress.android.ui.voicetocontent

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.verifyNoInteractions
import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.util.audio.RecordingUpdate
import org.wordpress.android.viewmodel.ContextProvider
import kotlin.test.Test

@ExperimentalCoroutinesApi
@RunWith(MockitoJUnitRunner::class)
class VoiceToContentViewModelTest : BaseUnitTest() {
@Mock
lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils
Expand All @@ -35,8 +37,22 @@ class VoiceToContentViewModelTest : BaseUnitTest() {

private lateinit var viewModel: VoiceToContentViewModel

// private lateinit var uiState: MutableList<VoiceToContentResult>
private var uiStateChanges = mutableListOf<VoiceToContentUiState>()
private val uiState
get() = viewModel.state.value

private fun <T> testUiStateChanges(
block: suspend CoroutineScope.() -> T
) {
test {
uiStateChanges.clear()
val job = launch(testDispatcher()) {
viewModel.state.toList(uiStateChanges)
}
this.block()
job.cancel()
}
}
/* private val jetpackAIAssistantFeature = JetpackAIAssistantFeature(
hasFeature = true,
isOverLimit = false,
Expand All @@ -55,7 +71,7 @@ class VoiceToContentViewModelTest : BaseUnitTest() {
@Before
fun setup() {
// Mock the recording updates to return a non-null flow before ViewModel instantiation
// whenever(recordingUseCase.recordingUpdates()).thenReturn(createRecordingUpdateFlow())
whenever(recordingUseCase.recordingUpdates()).thenReturn(createRecordingUpdateFlow())

viewModel = VoiceToContentViewModel(
testDispatcher(),
Expand All @@ -66,20 +82,13 @@ class VoiceToContentViewModelTest : BaseUnitTest() {
contextProvider,
prepareVoiceToContentUseCase
)
// uiState = mutableListOf()
// viewModel.uiState.observeForever { event ->
// event?.let { result ->
// uiState.add(result)
// }
// }
}

//
// // Helper function to create a consistent flow
// private fun createRecordingUpdateFlow() = flow {
// emit(RecordingUpdate(0, 0, false))
// }
//
// Helper function to create a consistent flow
private fun createRecordingUpdateFlow() = flow {
emit(RecordingUpdate(0, 0, false))
}

@Test
fun `when site is null, then execute posts error state `() = test {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(null)
Expand Down

0 comments on commit fbc2040

Please sign in to comment.