mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -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.kiwixmobile.custom.download.effects.SetPreferredStorageWithMostSpace
|
||||||
import org.kiwix.sharedFunctions.InstantExecutorExtension
|
import org.kiwix.sharedFunctions.InstantExecutorExtension
|
||||||
import org.kiwix.sharedFunctions.downloadItem
|
import org.kiwix.sharedFunctions.downloadItem
|
||||||
|
import kotlin.time.DurationUnit
|
||||||
|
import kotlin.time.toDuration
|
||||||
|
|
||||||
@ExtendWith(InstantExecutorExtension::class)
|
@ExtendWith(InstantExecutorExtension::class)
|
||||||
internal class CustomDownloadViewModelTest {
|
internal class CustomDownloadViewModelTest {
|
||||||
@ -70,7 +72,9 @@ internal class CustomDownloadViewModelTest {
|
|||||||
setPreferredStorageWithMostSpace,
|
setPreferredStorageWithMostSpace,
|
||||||
downloadCustom,
|
downloadCustom,
|
||||||
navigateToCustomReader
|
navigateToCustomReader
|
||||||
)
|
).also {
|
||||||
|
it.getStateForTesting().value = DownloadRequired
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -187,15 +191,16 @@ internal class CustomDownloadViewModelTest {
|
|||||||
initialState: State,
|
initialState: State,
|
||||||
action: DatabaseEmission,
|
action: DatabaseEmission,
|
||||||
endState: State,
|
endState: State,
|
||||||
awaitItemCount: Int = 1
|
awaitItemCount: Int = 1,
|
||||||
) {
|
) {
|
||||||
customDownloadViewModel.getStateForTesting().value = initialState
|
customDownloadViewModel.getStateForTesting().value = initialState
|
||||||
testScope.testFlow(
|
testScope.testFlow(
|
||||||
flow = customDownloadViewModel.state,
|
flow = customDownloadViewModel.state,
|
||||||
triggerAction = { customDownloadViewModel.actions.emit(action) },
|
triggerAction = { customDownloadViewModel.actions.tryEmit(action) },
|
||||||
assert = {
|
assert = {
|
||||||
val items = (1..awaitItemCount).map { awaitItem() }
|
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
|
assert: suspend TurbineTestContext<T>.() -> Unit
|
||||||
) {
|
) {
|
||||||
val job = launch {
|
val job = launch {
|
||||||
flow.test {
|
flow.test(timeout = TURBINE_TIMEOUT) {
|
||||||
triggerAction()
|
triggerAction()
|
||||||
assert()
|
assert()
|
||||||
cancelAndIgnoreRemainingEvents()
|
cancelAndIgnoreRemainingEvents()
|
||||||
@ -240,3 +245,5 @@ suspend fun <T> TestScope.testFlow(
|
|||||||
}
|
}
|
||||||
job.join()
|
job.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val TURBINE_TIMEOUT = 5000.toDuration(DurationUnit.MILLISECONDS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user