package com.freeletics.feature.notifications import com.freeletics.flowredux.dsl.ChangeState import com.freeletics.flowredux.dsl.reduce import io.kotest.matchers.shouldBe class FlowReduxInStateTestBuilder(private val state: InputState) { fun onEnter(handler: suspend (InputState) -> ChangeState): FlowReduxInStateOnEnterTestBuilder = FlowReduxInStateOnEnterTestBuilder(state = state, onEnter = handler) fun onAction( action: A, handler: suspend (A, InputState) -> ChangeState ): FlowReduxInStateOnActionTestBuilder = FlowReduxInStateOnActionTestBuilder(state, action, handler) } class FlowReduxInStateOnEnterTestBuilder( private val state: InputState, private val onEnter: suspend (InputState) -> ChangeState ) { suspend fun then(expectedState: S) { val newState = onEnter(state).reduce(state) newState shouldBe expectedState } } class FlowReduxInStateOnActionTestBuilder( private val state: InputState, private val action: A, private val onAction: suspend (A, InputState) -> ChangeState ) { suspend fun then(expectedState: S) { val newState = onAction(action, state).reduce(state) newState shouldBe expectedState } suspend fun then(assertionBlock: (S) -> Unit) { val newState = onAction(action, state).reduce(state) assertionBlock(newState) } } fun givenState(state: InputState): FlowReduxInStateTestBuilder = FlowReduxInStateTestBuilder(state)