Skip to content

Commit fc5a2d6

Browse files
committed
addtests
1 parent 53db8fc commit fc5a2d6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,43 @@ class MainVMTest : BaseMviViewModelTest<
247247
delayAfterDispatchingIntents = Duration.milliseconds(100),
248248
) { coVerify(exactly = 0) { getUserUseCase() } }
249249
}
250+
251+
@Test
252+
fun test_withRetryIntentWhenSuccess_returnsUserItems() {
253+
val ioException = IOException()
254+
test(
255+
vmProducer = {
256+
every { getUserUseCase() } returnsMany listOf(
257+
flow { throw ioException },
258+
flowOf(USERS),
259+
)
260+
vm
261+
},
262+
intentsBeforeCollecting = flowOf(ViewIntent.Initial),
263+
intents = flowOf(ViewIntent.Retry),
264+
expectedStates = listOf(
265+
ViewState(
266+
userItems = emptyList(),
267+
isLoading = false,
268+
error = ioException,
269+
isRefreshing = false,
270+
),
271+
ViewState(
272+
userItems = emptyList(),
273+
isLoading = true,
274+
error = null,
275+
isRefreshing = false,
276+
),
277+
ViewState(
278+
userItems = USER_ITEMS,
279+
isLoading = false,
280+
error = null,
281+
isRefreshing = false,
282+
)
283+
),
284+
expectedEvents = listOf(
285+
SingleEvent.GetUsersError(ioException),
286+
),
287+
) { verify(exactly = 2) { getUserUseCase() } }
288+
}
250289
}

0 commit comments

Comments
 (0)