All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.daftmobile.efekt.test.ReducerTesterUtils.kt Maven / Gradle / Ivy

The newest version!
package com.daftmobile.efekt.test

import com.daftmobile.efekt.Action
import com.daftmobile.efekt.Effect
import com.daftmobile.efekt.ListEffect
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.test.assertIs
import kotlin.test.assertTrue

public inline fun  ReducerTesterScope<*>.shouldHaveSingleEffectOf(): T {
    assertHaveSingleEffect()
    return assertIs(effects.single())
}

public inline fun  ListEffect?.shouldHaveSingleActionOf(): T {
    assertHaveSingleAction()
    return assertIs(actions.single())
}

public inline fun  Effect?.shouldBeSingleActionOf(): T = assertIs(this)
    .run { shouldHaveSingleActionOf() }

public inline fun  ReducerTesterScope<*>.shouldDispatchSingleAction(block: (T) -> Unit = { }): T {
    return shouldHaveSingleEffectOf()
        .shouldHaveSingleActionOf()
        .apply(block)
}

@PublishedApi
internal fun ReducerTesterScope<*>.assertHaveSingleEffect() {
    assertTrue(actual = effects.size == 1, message = "Expected single effect! Effects: $effects")
}

@OptIn(ExperimentalContracts::class)
@PublishedApi
internal fun ListEffect?.assertHaveSingleAction() {
    contract { returns() implies (this@assertHaveSingleAction != null) }
    assertTrue(actual = this?.actions?.size == 1, message = "Expected single action! Effects: ${this?.actions}")
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy