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

commonMain.com.copperleaf.ballast.test.internal.BallastScenarioInputSequenceScopeImpl.kt Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package com.copperleaf.ballast.test.internal

import com.copperleaf.ballast.BallastLogger
import com.copperleaf.ballast.test.BallastScenarioInputSequenceScope
import com.copperleaf.ballast.test.internal.vm.TestViewModel
import kotlinx.coroutines.CompletableDeferred

internal class BallastScenarioInputSequenceScopeImpl(
    private val logger: BallastLogger,
    private val vm: TestViewModel
) : BallastScenarioInputSequenceScope {

    override suspend fun send(input: Inputs) {
        logger.debug("        before send ProcessInput")
        val deferred = CompletableDeferred()
        vm.send(
            TestViewModel.Inputs.ProcessInput(input, deferred)
        )
        logger.debug("        after send ProcessInput")
        deferred.await()
        logger.debug("        after await ProcessInput")
    }

    override suspend fun sendAndAwait(input: Inputs): State {
        logger.debug("        before send AwaitInput")
        val deferred = CompletableDeferred()
        vm.send(
            TestViewModel.Inputs.AwaitInput(input, deferred)
        )
        logger.debug("        after send AwaitInput")
        deferred.await()
        val latestStateAfterProcessing = vm.observeStates().value
        logger.debug("        after await AwaitInput: $latestStateAfterProcessing")
        return latestStateAfterProcessing
    }

    internal suspend fun finish() {
        logger.debug("        before send TestCompleted")
        val deferred = CompletableDeferred()
        vm.send(
            TestViewModel.Inputs.TestCompleted(deferred)
        )
        logger.debug("        after send TestCompleted")

        deferred.await()
        logger.debug("        after await TestCompleted")
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy