Skip to content

Commit 53db8fc

Browse files
committed
addtests
1 parent a341f8a commit 53db8fc

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

feature-main/src/test/java/com/hoc/flowmvi/ui/main/MainVMTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.mockk.mockk
1212
import io.mockk.verify
1313
import kotlinx.coroutines.ExperimentalCoroutinesApi
1414
import kotlinx.coroutines.FlowPreview
15+
import kotlinx.coroutines.flow.emptyFlow
1516
import kotlinx.coroutines.flow.flow
1617
import kotlinx.coroutines.flow.flowOf
1718
import java.io.IOException
@@ -232,4 +233,18 @@ class MainVMTest : BaseMviViewModelTest<
232233
delayAfterDispatchingIntents = Duration.milliseconds(100),
233234
) { coVerify(exactly = 0) { refreshGetUsersUseCase() } }
234235
}
236+
237+
@Test
238+
fun test_withRetryIntent_ignoredWhenHavingNoError() {
239+
test(
240+
vmProducer = {
241+
every { getUserUseCase() } returns emptyFlow()
242+
vm
243+
},
244+
intents = flowOf(ViewIntent.Retry),
245+
expectedStates = listOf(ViewState.initial()),
246+
expectedEvents = emptyList(),
247+
delayAfterDispatchingIntents = Duration.milliseconds(100),
248+
) { coVerify(exactly = 0) { getUserUseCase() } }
249+
}
235250
}

mvi/mvi-testing/src/main/java/com/flowmvi/mvi_testing/BaseMviViewModelTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ abstract class BaseMviViewModelTest<
4646
intents: Flow<I>,
4747
expectedStates: List<S>,
4848
expectedEvents: List<E>,
49-
delayAfterDispatchingIntents: Duration = Duration.milliseconds(50),
49+
delayAfterDispatchingIntents: Duration = Duration.ZERO,
50+
logging: Boolean = true,
5051
intentsBeforeCollecting: Flow<I>? = null,
5152
otherAssertions: (suspend () -> Unit)? = null,
5253
) = testDispatcher.runBlockingTest {
@@ -62,8 +63,10 @@ abstract class BaseMviViewModelTest<
6263
intents.collect { vm.processIntent(it) }
6364
delay(delayAfterDispatchingIntents)
6465

65-
println(states)
66-
println(events)
66+
if (logging) {
67+
println(states)
68+
println(events)
69+
}
6770

6871
assertEquals(expectedStates.size, states.size)
6972
assertContentEquals(

0 commit comments

Comments
 (0)