Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit c29bc905 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Add assertThatAndStateTurbineConsumed and assertThatAndEffectTurbineConsumed for simpler test setup

parent f0632d6c
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -72,6 +72,36 @@ fun <T, STATE, EFFECT> assertThatAndMviTurbinesConsumed(
    turbines.effectTurbine.ensureAllEventsConsumed()
}

/**
 * The `assertThatAndStateTurbineConsumed` function ensures that the assertion passed and
 * all events in the state turbine have been consumed.
 */
suspend fun <STATE, EFFECT> MviTurbines<STATE, EFFECT>.assertThatAndStateTurbineConsumed(
    assertion: Assert<STATE>.() -> Unit,
) {
    assertThat(stateTurbine.awaitItem()).all {
        assertion()
    }

    stateTurbine.ensureAllEventsConsumed()
    effectTurbine.ensureAllEventsConsumed()
}

/**
 * The `assertThatAndEffectTurbineConsumed` function ensures that the assertion passed and
 * all events in the effect turbine have been consumed.
 */
suspend fun <STATE, EFFECT> MviTurbines<STATE, EFFECT>.assertThatAndEffectTurbineConsumed(
    assertion: Assert<EFFECT>.() -> Unit,
) {
    assertThat(effectTurbine.awaitItem()).all {
        assertion()
    }

    stateTurbine.ensureAllEventsConsumed()
    effectTurbine.ensureAllEventsConsumed()
}

/**
 * A container class for the state and effect turbines of an MVI ViewModel.
 */