Add validation flow to account setup
This commit is contained in:
parent
eec5a358e9
commit
a00ca56f8e
15 changed files with 235 additions and 27 deletions
|
@ -22,6 +22,7 @@ import app.k9mail.feature.account.setup.ui.options.AccountOptionsViewModel
|
|||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigContract
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigValidator
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigViewModel
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationViewModel
|
||||
import com.fsck.k9.mail.store.imap.ImapServerSettingsValidator
|
||||
import com.fsck.k9.mail.store.pop3.Pop3ServerSettingsValidator
|
||||
|
@ -29,6 +30,7 @@ import com.fsck.k9.mail.transport.smtp.SmtpServerSettingsValidator
|
|||
import okhttp3.OkHttpClient
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.qualifier.named
|
||||
import org.koin.dsl.module
|
||||
|
||||
val featureAccountSetupModule: Module = module {
|
||||
|
@ -110,24 +112,38 @@ val featureAccountSetupModule: Module = module {
|
|||
getAutoDiscovery = get(),
|
||||
)
|
||||
}
|
||||
viewModel {
|
||||
AccountValidationViewModel(
|
||||
validateServerSettings = get(),
|
||||
)
|
||||
}
|
||||
viewModel {
|
||||
AccountIncomingConfigViewModel(
|
||||
validator = get(),
|
||||
)
|
||||
}
|
||||
viewModel(named(NAME_INCOMING_VALIDATION)) {
|
||||
AccountValidationViewModel(
|
||||
validateServerSettings = get(),
|
||||
initialState = AccountValidationContract.State(
|
||||
isIncomingValidation = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
viewModel {
|
||||
AccountOutgoingConfigViewModel(
|
||||
validator = get(),
|
||||
)
|
||||
}
|
||||
viewModel(named(NAME_OUTGOING_VALIDATION)) {
|
||||
AccountValidationViewModel(
|
||||
validateServerSettings = get(),
|
||||
initialState = AccountValidationContract.State(
|
||||
isIncomingValidation = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
viewModel {
|
||||
AccountOptionsViewModel(
|
||||
validator = get(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal const val NAME_INCOMING_VALIDATION = "incoming_validation"
|
||||
internal const val NAME_OUTGOING_VALIDATION = "outgoing_validation"
|
||||
|
|
|
@ -11,7 +11,9 @@ interface AccountSetupContract {
|
|||
enum class SetupStep {
|
||||
AUTO_CONFIG,
|
||||
INCOMING_CONFIG,
|
||||
INCOMING_VALIDATION,
|
||||
OUTGOING_CONFIG,
|
||||
OUTGOING_VALIDATION,
|
||||
OPTIONS,
|
||||
}
|
||||
|
||||
|
@ -19,6 +21,7 @@ interface AccountSetupContract {
|
|||
|
||||
data class State(
|
||||
val setupStep: SetupStep = SetupStep.AUTO_CONFIG,
|
||||
val isAutomaticConfig: Boolean = false,
|
||||
)
|
||||
|
||||
sealed interface Event {
|
||||
|
@ -26,6 +29,7 @@ interface AccountSetupContract {
|
|||
|
||||
data class OnAutoDiscoveryFinished(
|
||||
val state: AccountAutoDiscoveryContract.State,
|
||||
val isAutomaticConfig: Boolean,
|
||||
) : Event
|
||||
|
||||
data class OnStateCollected(
|
||||
|
@ -44,10 +48,14 @@ interface AccountSetupContract {
|
|||
val state: AccountIncomingConfigContract.State,
|
||||
) : Effect
|
||||
|
||||
object UpdateIncomingConfigValidation : Effect
|
||||
|
||||
data class UpdateOutgoingConfig(
|
||||
val state: AccountOutgoingConfigContract.State,
|
||||
) : Effect
|
||||
|
||||
object UpdateOutgoingConfigValidation : Effect
|
||||
|
||||
data class UpdateOptions(
|
||||
val state: AccountOptionsContract.State,
|
||||
) : Effect
|
||||
|
|
|
@ -3,6 +3,8 @@ package app.k9mail.feature.account.setup.ui
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import app.k9mail.core.ui.compose.common.mvi.observe
|
||||
import app.k9mail.feature.account.setup.NAME_INCOMING_VALIDATION
|
||||
import app.k9mail.feature.account.setup.NAME_OUTGOING_VALIDATION
|
||||
import app.k9mail.feature.account.setup.ui.AccountSetupContract.Effect
|
||||
import app.k9mail.feature.account.setup.ui.AccountSetupContract.Event
|
||||
import app.k9mail.feature.account.setup.ui.AccountSetupContract.SetupStep
|
||||
|
@ -13,14 +15,21 @@ import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryVie
|
|||
import app.k9mail.feature.account.setup.ui.incoming.AccountIncomingConfigContract
|
||||
import app.k9mail.feature.account.setup.ui.incoming.AccountIncomingConfigScreen
|
||||
import app.k9mail.feature.account.setup.ui.incoming.AccountIncomingConfigViewModel
|
||||
import app.k9mail.feature.account.setup.ui.incoming.toValidationState
|
||||
import app.k9mail.feature.account.setup.ui.options.AccountOptionsContract
|
||||
import app.k9mail.feature.account.setup.ui.options.AccountOptionsScreen
|
||||
import app.k9mail.feature.account.setup.ui.options.AccountOptionsViewModel
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigContract
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigScreen
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.AccountOutgoingConfigViewModel
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.toValidationState
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationScreen
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationViewModel
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import org.koin.core.qualifier.named
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
@Composable
|
||||
fun AccountSetupScreen(
|
||||
onFinish: (String) -> Unit,
|
||||
|
@ -28,13 +37,31 @@ fun AccountSetupScreen(
|
|||
viewModel: ViewModel = koinViewModel<AccountSetupViewModel>(),
|
||||
autoDiscoveryViewModel: AccountAutoDiscoveryContract.ViewModel = koinViewModel<AccountAutoDiscoveryViewModel>(),
|
||||
incomingViewModel: AccountIncomingConfigContract.ViewModel = koinViewModel<AccountIncomingConfigViewModel>(),
|
||||
incomingValidationViewModel: AccountValidationContract.ViewModel = koinViewModel<AccountValidationViewModel>(
|
||||
named(
|
||||
NAME_INCOMING_VALIDATION,
|
||||
),
|
||||
),
|
||||
outgoingViewModel: AccountOutgoingConfigContract.ViewModel = koinViewModel<AccountOutgoingConfigViewModel>(),
|
||||
outgoingValidationViewModel: AccountValidationContract.ViewModel = koinViewModel<AccountValidationViewModel>(
|
||||
named(
|
||||
NAME_OUTGOING_VALIDATION,
|
||||
),
|
||||
),
|
||||
optionsViewModel: AccountOptionsContract.ViewModel = koinViewModel<AccountOptionsViewModel>(),
|
||||
) {
|
||||
val (state, dispatch) = viewModel.observe { effect ->
|
||||
when (effect) {
|
||||
is Effect.UpdateIncomingConfig -> incomingViewModel.initState(effect.state)
|
||||
is Effect.UpdateIncomingConfigValidation -> {
|
||||
incomingValidationViewModel.initState(incomingViewModel.state.value.toValidationState())
|
||||
}
|
||||
|
||||
is Effect.UpdateOutgoingConfig -> outgoingViewModel.initState(effect.state)
|
||||
is Effect.UpdateOutgoingConfigValidation -> {
|
||||
outgoingValidationViewModel.initState(outgoingViewModel.state.value.toValidationState())
|
||||
}
|
||||
|
||||
is Effect.UpdateOptions -> optionsViewModel.initState(effect.state)
|
||||
is Effect.CollectExternalStates -> viewModel.event(
|
||||
Event.OnStateCollected(
|
||||
|
@ -53,7 +80,14 @@ fun AccountSetupScreen(
|
|||
when (state.value.setupStep) {
|
||||
SetupStep.AUTO_CONFIG -> {
|
||||
AccountAutoDiscoveryScreen(
|
||||
onNext = { dispatch(Event.OnAutoDiscoveryFinished(it)) },
|
||||
onNext = { autoDiscoveryState, isAutomaticConfig ->
|
||||
dispatch(
|
||||
Event.OnAutoDiscoveryFinished(
|
||||
autoDiscoveryState,
|
||||
isAutomaticConfig,
|
||||
),
|
||||
)
|
||||
},
|
||||
onBack = { dispatch(Event.OnBack) },
|
||||
viewModel = autoDiscoveryViewModel,
|
||||
)
|
||||
|
@ -67,6 +101,14 @@ fun AccountSetupScreen(
|
|||
)
|
||||
}
|
||||
|
||||
SetupStep.INCOMING_VALIDATION -> {
|
||||
AccountValidationScreen(
|
||||
onNext = { dispatch(Event.OnNext) },
|
||||
onBack = { dispatch(Event.OnBack) },
|
||||
viewModel = incomingValidationViewModel,
|
||||
)
|
||||
}
|
||||
|
||||
SetupStep.OUTGOING_CONFIG -> {
|
||||
AccountOutgoingConfigScreen(
|
||||
onNext = { dispatch(Event.OnNext) },
|
||||
|
@ -75,6 +117,14 @@ fun AccountSetupScreen(
|
|||
)
|
||||
}
|
||||
|
||||
SetupStep.OUTGOING_VALIDATION -> {
|
||||
AccountValidationScreen(
|
||||
onNext = { dispatch(Event.OnNext) },
|
||||
onBack = { dispatch(Event.OnBack) },
|
||||
viewModel = outgoingValidationViewModel,
|
||||
)
|
||||
}
|
||||
|
||||
SetupStep.OPTIONS -> {
|
||||
AccountOptionsScreen(
|
||||
onNext = { dispatch(Event.OnNext) },
|
||||
|
|
|
@ -27,7 +27,15 @@ class AccountSetupViewModel(
|
|||
|
||||
override fun event(event: Event) {
|
||||
when (event) {
|
||||
is Event.OnAutoDiscoveryFinished -> onAutoDiscoveryFinished(event.state)
|
||||
is Event.OnAutoDiscoveryFinished -> {
|
||||
updateState {
|
||||
it.copy(
|
||||
isAutomaticConfig = event.isAutomaticConfig,
|
||||
)
|
||||
}
|
||||
onAutoDiscoveryFinished(event.state)
|
||||
}
|
||||
|
||||
is Event.OnStateCollected -> onStateCollected(
|
||||
autoDiscoveryState = event.autoDiscoveryState,
|
||||
incomingState = event.incomingState,
|
||||
|
@ -40,7 +48,9 @@ class AccountSetupViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun onAutoDiscoveryFinished(autoDiscoveryState: AccountAutoDiscoveryContract.State) {
|
||||
private fun onAutoDiscoveryFinished(
|
||||
autoDiscoveryState: AccountAutoDiscoveryContract.State,
|
||||
) {
|
||||
emitEffect(Effect.UpdateIncomingConfig(autoDiscoveryState.toIncomingConfigState()))
|
||||
emitEffect(Effect.UpdateOutgoingConfig(autoDiscoveryState.toOutgoingConfigState()))
|
||||
emitEffect(Effect.UpdateOptions(autoDiscoveryState.toOptionsState()))
|
||||
|
@ -51,16 +61,61 @@ class AccountSetupViewModel(
|
|||
when (state.value.setupStep) {
|
||||
SetupStep.AUTO_CONFIG -> navigateBack()
|
||||
SetupStep.INCOMING_CONFIG -> changeToSetupStep(SetupStep.AUTO_CONFIG)
|
||||
SetupStep.OUTGOING_CONFIG -> changeToSetupStep(SetupStep.INCOMING_CONFIG)
|
||||
SetupStep.OPTIONS -> changeToSetupStep(SetupStep.OUTGOING_CONFIG)
|
||||
SetupStep.INCOMING_VALIDATION -> {
|
||||
if (state.value.isAutomaticConfig) {
|
||||
changeToSetupStep(SetupStep.AUTO_CONFIG)
|
||||
} else {
|
||||
changeToSetupStep(SetupStep.INCOMING_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
SetupStep.OUTGOING_CONFIG -> changeToSetupStep(SetupStep.INCOMING_VALIDATION)
|
||||
SetupStep.OUTGOING_VALIDATION -> {
|
||||
if (state.value.isAutomaticConfig) {
|
||||
changeToSetupStep(SetupStep.AUTO_CONFIG)
|
||||
} else {
|
||||
changeToSetupStep(SetupStep.OUTGOING_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
SetupStep.OPTIONS -> changeToSetupStep(SetupStep.OUTGOING_VALIDATION)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onNext() {
|
||||
when (state.value.setupStep) {
|
||||
SetupStep.AUTO_CONFIG -> changeToSetupStep(SetupStep.INCOMING_CONFIG)
|
||||
SetupStep.INCOMING_CONFIG -> changeToSetupStep(SetupStep.OUTGOING_CONFIG)
|
||||
SetupStep.OUTGOING_CONFIG -> changeToSetupStep(SetupStep.OPTIONS)
|
||||
SetupStep.AUTO_CONFIG -> {
|
||||
if (state.value.isAutomaticConfig) {
|
||||
emitEffect(Effect.UpdateIncomingConfigValidation)
|
||||
emitEffect(Effect.UpdateOutgoingConfigValidation)
|
||||
changeToSetupStep(SetupStep.INCOMING_VALIDATION)
|
||||
} else {
|
||||
changeToSetupStep(SetupStep.INCOMING_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
SetupStep.INCOMING_CONFIG -> {
|
||||
emitEffect(Effect.UpdateIncomingConfigValidation)
|
||||
changeToSetupStep(SetupStep.INCOMING_VALIDATION)
|
||||
}
|
||||
|
||||
SetupStep.INCOMING_VALIDATION -> {
|
||||
if (state.value.isAutomaticConfig) {
|
||||
changeToSetupStep(SetupStep.OUTGOING_VALIDATION)
|
||||
} else {
|
||||
changeToSetupStep(SetupStep.OUTGOING_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
SetupStep.OUTGOING_CONFIG -> {
|
||||
emitEffect(Effect.UpdateOutgoingConfigValidation)
|
||||
changeToSetupStep(SetupStep.OUTGOING_VALIDATION)
|
||||
}
|
||||
|
||||
SetupStep.OUTGOING_VALIDATION -> {
|
||||
changeToSetupStep(SetupStep.OPTIONS)
|
||||
}
|
||||
|
||||
SetupStep.OPTIONS -> onFinish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ interface AccountAutoDiscoveryContract {
|
|||
}
|
||||
|
||||
sealed class Effect {
|
||||
object NavigateNext : Effect()
|
||||
data class NavigateNext(
|
||||
val isAutomaticConfig: Boolean,
|
||||
) : Effect()
|
||||
object NavigateBack : Effect()
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryCon
|
|||
|
||||
@Composable
|
||||
internal fun AccountAutoDiscoveryScreen(
|
||||
onNext: (State) -> Unit,
|
||||
onNext: (state: State, isAutomaticConfig: Boolean) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
viewModel: ViewModel,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -28,7 +28,7 @@ internal fun AccountAutoDiscoveryScreen(
|
|||
val (state, dispatch) = viewModel.observe { effect ->
|
||||
when (effect) {
|
||||
Effect.NavigateBack -> onBack()
|
||||
Effect.NavigateNext -> onNext(viewModel.state.value)
|
||||
is Effect.NavigateNext -> onNext(viewModel.state.value, effect.isAutomaticConfig)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ internal fun AccountAutoDiscoveryScreen(
|
|||
internal fun AccountAutoDiscoveryScreenK9Preview() {
|
||||
K9Theme {
|
||||
AccountAutoDiscoveryScreen(
|
||||
onNext = {},
|
||||
onNext = { _, _ -> },
|
||||
onBack = {},
|
||||
viewModel = AccountAutoDiscoveryViewModel(
|
||||
validator = AccountAutoDiscoveryValidator(),
|
||||
|
@ -80,7 +80,7 @@ internal fun AccountAutoDiscoveryScreenK9Preview() {
|
|||
internal fun AccountAutoDiscoveryScreenThunderbirdPreview() {
|
||||
ThunderbirdTheme {
|
||||
AccountAutoDiscoveryScreen(
|
||||
onNext = {},
|
||||
onNext = { _, _ -> },
|
||||
onBack = {},
|
||||
viewModel = AccountAutoDiscoveryViewModel(
|
||||
validator = AccountAutoDiscoveryValidator(),
|
||||
|
|
|
@ -37,7 +37,9 @@ internal class AccountAutoDiscoveryViewModel(
|
|||
Event.OnNextClicked -> onNext()
|
||||
Event.OnBackClicked -> onBack()
|
||||
Event.OnRetryClicked -> onRetry()
|
||||
Event.OnEditConfigurationClicked -> navigateNext()
|
||||
Event.OnEditConfigurationClicked -> {
|
||||
navigateNext(isAutomaticConfig = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +172,7 @@ internal class AccountAutoDiscoveryViewModel(
|
|||
}
|
||||
|
||||
if (!hasError) {
|
||||
navigateNext()
|
||||
navigateNext(state.value.autoDiscoverySettings != null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,5 +202,7 @@ internal class AccountAutoDiscoveryViewModel(
|
|||
|
||||
private fun navigateBack() = emitEffect(Effect.NavigateBack)
|
||||
|
||||
private fun navigateNext() = emitEffect(Effect.NavigateNext)
|
||||
private fun navigateNext(isAutomaticConfig: Boolean) {
|
||||
emitEffect(Effect.NavigateNext(isAutomaticConfig))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package app.k9mail.feature.account.setup.ui.incoming
|
|||
import app.k9mail.feature.account.setup.domain.entity.IncomingProtocolType
|
||||
import app.k9mail.feature.account.setup.domain.entity.toAuthType
|
||||
import app.k9mail.feature.account.setup.domain.entity.toMailConnectionSecurity
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings
|
||||
|
||||
|
@ -32,3 +33,10 @@ private fun AccountIncomingConfigContract.State.createExtras(): Map<String, Stri
|
|||
emptyMap()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun AccountIncomingConfigContract.State.toValidationState(): AccountValidationContract.State {
|
||||
return AccountValidationContract.State(
|
||||
serverSettings = toServerSettings(),
|
||||
// TODO add authorization state
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package app.k9mail.feature.account.setup.ui.outgoing
|
|||
|
||||
import app.k9mail.feature.account.setup.domain.entity.toAuthType
|
||||
import app.k9mail.feature.account.setup.domain.entity.toMailConnectionSecurity
|
||||
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
|
||||
internal fun AccountOutgoingConfigContract.State.toServerSettings(): ServerSettings {
|
||||
|
@ -16,3 +17,10 @@ internal fun AccountOutgoingConfigContract.State.toServerSettings(): ServerSetti
|
|||
clientCertificateAlias = clientCertificateAlias,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun AccountOutgoingConfigContract.State.toValidationState(): AccountValidationContract.State {
|
||||
return AccountValidationContract.State(
|
||||
serverSettings = toServerSettings(),
|
||||
// TODO add authorization state
|
||||
)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ internal fun AccountValidationContent(
|
|||
|
||||
ResponsiveWidthContainer(
|
||||
modifier = Modifier
|
||||
.testTag("AccountIncomingConfigContent")
|
||||
.testTag("AccountValidationContent")
|
||||
.padding(contentPadding)
|
||||
.fillMaxWidth()
|
||||
.then(modifier),
|
||||
|
|
|
@ -22,6 +22,7 @@ internal class AccountValidationViewModel(
|
|||
override fun initState(state: State) {
|
||||
updateState {
|
||||
state.copy(
|
||||
isIncomingValidation = it.isIncomingValidation,
|
||||
isLoading = false,
|
||||
error = null,
|
||||
isSuccess = false,
|
||||
|
|
|
@ -11,6 +11,7 @@ import app.k9mail.feature.account.setup.ui.autodiscovery.FakeAccountAutoDiscover
|
|||
import app.k9mail.feature.account.setup.ui.incoming.FakeAccountIncomingConfigViewModel
|
||||
import app.k9mail.feature.account.setup.ui.options.FakeAccountOptionsViewModel
|
||||
import app.k9mail.feature.account.setup.ui.outgoing.FakeAccountOutgoingConfigViewModel
|
||||
import app.k9mail.feature.account.setup.ui.validation.FakeAccountValidationViewModel
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
@ -23,7 +24,9 @@ class AccountSetupScreenKtTest : ComposeTest() {
|
|||
val viewModel = FakeAccountSetupViewModel()
|
||||
val autoDiscoveryViewModel = FakeAccountAutoDiscoveryViewModel()
|
||||
val incomingViewModel = FakeAccountIncomingConfigViewModel()
|
||||
val incomingValidationViewModel = FakeAccountValidationViewModel()
|
||||
val outgoingViewModel = FakeAccountOutgoingConfigViewModel()
|
||||
val outgoingValidationViewModel = FakeAccountValidationViewModel()
|
||||
val optionsViewModel = FakeAccountOptionsViewModel()
|
||||
|
||||
setContent {
|
||||
|
@ -34,7 +37,9 @@ class AccountSetupScreenKtTest : ComposeTest() {
|
|||
viewModel = viewModel,
|
||||
autoDiscoveryViewModel = autoDiscoveryViewModel,
|
||||
incomingViewModel = incomingViewModel,
|
||||
incomingValidationViewModel = incomingValidationViewModel,
|
||||
outgoingViewModel = outgoingViewModel,
|
||||
outgoingValidationViewModel = outgoingValidationViewModel,
|
||||
optionsViewModel = optionsViewModel,
|
||||
)
|
||||
}
|
||||
|
@ -52,7 +57,9 @@ class AccountSetupScreenKtTest : ComposeTest() {
|
|||
val viewModel = FakeAccountSetupViewModel(initialState)
|
||||
val autoDiscoveryViewModel = FakeAccountAutoDiscoveryViewModel()
|
||||
val incomingViewModel = FakeAccountIncomingConfigViewModel()
|
||||
val incomingValidationViewModel = FakeAccountValidationViewModel()
|
||||
val outgoingViewModel = FakeAccountOutgoingConfigViewModel()
|
||||
val outgoingValidationViewModel = FakeAccountValidationViewModel()
|
||||
val optionsViewModel = FakeAccountOptionsViewModel()
|
||||
var onFinishCounter = 0
|
||||
var onBackCounter = 0
|
||||
|
@ -65,7 +72,9 @@ class AccountSetupScreenKtTest : ComposeTest() {
|
|||
viewModel = viewModel,
|
||||
autoDiscoveryViewModel = autoDiscoveryViewModel,
|
||||
incomingViewModel = incomingViewModel,
|
||||
incomingValidationViewModel = incomingValidationViewModel,
|
||||
outgoingViewModel = outgoingViewModel,
|
||||
outgoingValidationViewModel = outgoingValidationViewModel,
|
||||
optionsViewModel = optionsViewModel,
|
||||
)
|
||||
}
|
||||
|
@ -88,7 +97,9 @@ class AccountSetupScreenKtTest : ComposeTest() {
|
|||
private fun getTagForStep(step: SetupStep): String = when (step) {
|
||||
SetupStep.AUTO_CONFIG -> "AccountAutoDiscoveryContent"
|
||||
SetupStep.INCOMING_CONFIG -> "AccountIncomingConfigContent"
|
||||
SetupStep.INCOMING_VALIDATION -> "AccountValidationContent"
|
||||
SetupStep.OUTGOING_CONFIG -> "AccountOutgoingConfigContent"
|
||||
SetupStep.OUTGOING_VALIDATION -> "AccountValidationContent"
|
||||
SetupStep.OPTIONS -> "AccountOptionsContent"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,12 @@ class AccountSetupViewModelTest {
|
|||
prop(State::setupStep).isEqualTo(SetupStep.AUTO_CONFIG)
|
||||
}
|
||||
|
||||
viewModel.event(AccountSetupContract.Event.OnAutoDiscoveryFinished(AccountAutoDiscoveryContract.State()))
|
||||
viewModel.event(
|
||||
AccountSetupContract.Event.OnAutoDiscoveryFinished(
|
||||
state = AccountAutoDiscoveryContract.State(),
|
||||
isAutomaticConfig = false,
|
||||
),
|
||||
)
|
||||
|
||||
assertThat(effectTurbine.awaitItem())
|
||||
.isEqualTo(Effect.UpdateIncomingConfig(AccountIncomingConfigContract.State()))
|
||||
|
@ -60,6 +65,17 @@ class AccountSetupViewModelTest {
|
|||
|
||||
viewModel.event(AccountSetupContract.Event.OnNext)
|
||||
|
||||
assertThat(effectTurbine.awaitItem()).isEqualTo(Effect.UpdateIncomingConfigValidation)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
prop(State::setupStep).isEqualTo(SetupStep.INCOMING_VALIDATION)
|
||||
}
|
||||
|
||||
viewModel.event(AccountSetupContract.Event.OnNext)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
|
@ -69,6 +85,17 @@ class AccountSetupViewModelTest {
|
|||
|
||||
viewModel.event(AccountSetupContract.Event.OnNext)
|
||||
|
||||
assertThat(effectTurbine.awaitItem()).isEqualTo(Effect.UpdateOutgoingConfigValidation)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
prop(State::setupStep).isEqualTo(SetupStep.OUTGOING_VALIDATION)
|
||||
}
|
||||
|
||||
viewModel.event(AccountSetupContract.Event.OnNext)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
|
@ -123,6 +150,15 @@ class AccountSetupViewModelTest {
|
|||
|
||||
viewModel.event(AccountSetupContract.Event.OnBack)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
prop(State::setupStep).isEqualTo(SetupStep.OUTGOING_VALIDATION)
|
||||
}
|
||||
|
||||
viewModel.event(AccountSetupContract.Event.OnBack)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
|
@ -132,6 +168,15 @@ class AccountSetupViewModelTest {
|
|||
|
||||
viewModel.event(AccountSetupContract.Event.OnBack)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
prop(State::setupStep).isEqualTo(SetupStep.INCOMING_VALIDATION)
|
||||
}
|
||||
|
||||
viewModel.event(AccountSetupContract.Event.OnBack)
|
||||
|
||||
assertThatAndTurbinesConsumed(
|
||||
actual = stateTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
|
|
|
@ -22,7 +22,7 @@ class AccountAutoDiscoveryScreenKtTest : ComposeTest() {
|
|||
setContent {
|
||||
ThunderbirdTheme {
|
||||
AccountAutoDiscoveryScreen(
|
||||
onNext = { onNextCounter++ },
|
||||
onNext = { _, _ -> onNextCounter++ },
|
||||
onBack = { onBackCounter++ },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ class AccountAutoDiscoveryScreenKtTest : ComposeTest() {
|
|||
assertThat(onNextCounter).isEqualTo(0)
|
||||
assertThat(onBackCounter).isEqualTo(0)
|
||||
|
||||
viewModel.effect(Effect.NavigateNext)
|
||||
viewModel.effect(Effect.NavigateNext(isAutomaticConfig = false))
|
||||
|
||||
assertThat(onNextCounter).isEqualTo(1)
|
||||
assertThat(onBackCounter).isEqualTo(0)
|
||||
|
|
|
@ -300,7 +300,7 @@ class AccountAutoDiscoveryViewModelTest {
|
|||
actual = effectTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
isEqualTo(Effect.NavigateNext)
|
||||
isEqualTo(Effect.NavigateNext(isAutomaticConfig = false))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,7 @@ class AccountAutoDiscoveryViewModelTest {
|
|||
actual = effectTurbine.awaitItem(),
|
||||
turbines = turbines,
|
||||
) {
|
||||
isEqualTo(Effect.NavigateNext)
|
||||
isEqualTo(Effect.NavigateNext(isAutomaticConfig = false))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue