mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 02:36:24 -04:00
Fixed: Emission with data+failure moves state from InProgress to Failed
was sometimes fails on CI.
This commit is contained in:
parent
2e9417c3ac
commit
f3f3f224c0
@ -50,6 +50,8 @@ import org.kiwix.kiwixmobile.custom.download.effects.NavigateToCustomReader
|
||||
import org.kiwix.kiwixmobile.custom.download.effects.SetPreferredStorageWithMostSpace
|
||||
import org.kiwix.sharedFunctions.InstantExecutorExtension
|
||||
import org.kiwix.sharedFunctions.downloadItem
|
||||
import kotlin.time.DurationUnit
|
||||
import kotlin.time.toDuration
|
||||
|
||||
@ExtendWith(InstantExecutorExtension::class)
|
||||
internal class CustomDownloadViewModelTest {
|
||||
@ -70,7 +72,9 @@ internal class CustomDownloadViewModelTest {
|
||||
setPreferredStorageWithMostSpace,
|
||||
downloadCustom,
|
||||
navigateToCustomReader
|
||||
)
|
||||
).also {
|
||||
it.getStateForTesting().value = DownloadRequired
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -187,15 +191,16 @@ internal class CustomDownloadViewModelTest {
|
||||
initialState: State,
|
||||
action: DatabaseEmission,
|
||||
endState: State,
|
||||
awaitItemCount: Int = 1
|
||||
awaitItemCount: Int = 1,
|
||||
) {
|
||||
customDownloadViewModel.getStateForTesting().value = initialState
|
||||
testScope.testFlow(
|
||||
flow = customDownloadViewModel.state,
|
||||
triggerAction = { customDownloadViewModel.actions.emit(action) },
|
||||
triggerAction = { customDownloadViewModel.actions.tryEmit(action) },
|
||||
assert = {
|
||||
val items = (1..awaitItemCount).map { awaitItem() }
|
||||
assertThat(items.last()).isEqualTo(endState)
|
||||
print("items = $items")
|
||||
assertThat(items).contains(endState)
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -232,7 +237,7 @@ suspend fun <T> TestScope.testFlow(
|
||||
assert: suspend TurbineTestContext<T>.() -> Unit
|
||||
) {
|
||||
val job = launch {
|
||||
flow.test {
|
||||
flow.test(timeout = TURBINE_TIMEOUT) {
|
||||
triggerAction()
|
||||
assert()
|
||||
cancelAndIgnoreRemainingEvents()
|
||||
@ -240,3 +245,5 @@ suspend fun <T> TestScope.testFlow(
|
||||
}
|
||||
job.join()
|
||||
}
|
||||
|
||||
val TURBINE_TIMEOUT = 5000.toDuration(DurationUnit.MILLISECONDS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user