mvrx-mocking / com.airbnb.mvrx.mocking / SingleViewModelMockBuilder

SingleViewModelMockBuilder

class SingleViewModelMockBuilder<V : MockableMavericksView, Args : Parcelable, S : MavericksState> : MockBuilder<V, Args>

Provides a DSL for defining variations to the default mock state.

Inherited Properties

mocks

open val mocks: MutableList<MavericksMock<V, Args>>

A list of mocks to use when testing a view. Each mock represents a unique state to be tested.

Functions

state

fun state(name: String, args: (Args.() -> Args)? = null, stateBuilder: S.() -> S): Unit

Provide a state object via the lambda for the view model being mocked. The receiver of the lambda is the default state provided in the top level mock method. For simplicity you can modify the receiver directly.

stateForLoadingAndFailure

fun <T, A : Async<T>> stateForLoadingAndFailure(state: S = defaultState, asyncPropertyBlock: S.() -> KProperty0<A>): Unit

Helper to mock the loading and failure state of an Async property on your state. Creates two different mocked states stemmed from the given state - one where the async property is set to Loading and one where it is set to Fail.

Inherited Functions

addState

fun addState(name: String, argsProvider: () -> Args? = { defaultArgs }, statesProvider: () -> List<MockState<V, *>> = { defaultStates }, forInitialization: Boolean = false, type: MavericksMock.Type = MavericksMock.Type.Custom): Unit

args

fun args(name: String, builder: Args.() -> Args): Unit

Provide an instance of arguments to use when initializing a view and creating initial view model state. It is only valid to call this if you defined default arguments in the top level mock method. For convenience, the receiver of the lambda is the default arguments.