forked from thunderbird/thunderbird-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Turbine 0.13.0 -> 1.1.0 and add runMviTest to combine runTest …
…with turbineScope (cherry picked from commit aff875374fb1a2a047b729019df973198b67e3de)
- Loading branch information
Showing
17 changed files
with
309 additions
and
540 deletions.
There are no files selected for viewing
28 changes: 7 additions & 21 deletions
28
...pose/testing/src/main/kotlin/app/k9mail/core/ui/compose/testing/mvi/EventStateTestUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
package app.k9mail.core.ui.compose.testing.mvi | ||
|
||
import app.cash.turbine.testIn | ||
import app.k9mail.core.ui.compose.common.mvi.UnidirectionalViewModel | ||
import assertk.assertions.assertThatAndTurbinesConsumed | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
suspend fun <STATE, EVENT, EFFECT> eventStateTest( | ||
/** | ||
* Tests that the state of the [viewModel] changes as expected when the [event] is sent. | ||
*/ | ||
suspend inline fun <reified STATE, EVENT, EFFECT> MviContext.eventStateTest( | ||
viewModel: UnidirectionalViewModel<STATE, EVENT, EFFECT>, | ||
initialState: STATE, | ||
event: EVENT, | ||
expectedState: STATE, | ||
coroutineScope: CoroutineScope, | ||
) { | ||
val stateTurbine = viewModel.state.testIn(coroutineScope) | ||
val effectTurbine = viewModel.effect.testIn(coroutineScope) | ||
val turbines = listOf(stateTurbine, effectTurbine) | ||
|
||
assertThatAndTurbinesConsumed( | ||
actual = stateTurbine.awaitItem(), | ||
turbines = turbines, | ||
) { | ||
isEqualTo(initialState) | ||
} | ||
val turbines = turbinesWithInitialStateCheck(viewModel, initialState) | ||
|
||
viewModel.event(event) | ||
|
||
assertThatAndTurbinesConsumed( | ||
actual = stateTurbine.awaitItem(), | ||
turbines = turbines, | ||
) { | ||
isEqualTo(expectedState) | ||
} | ||
assertThat(turbines.stateTurbine.awaitItem()).isEqualTo(expectedState) | ||
} |
56 changes: 49 additions & 7 deletions
56
...ose/testing/src/main/kotlin/app/k9mail/core/ui/compose/testing/mvi/MviTurbineExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.