Fix account setup back navigation flow

This commit is contained in:
Wolf-Martell Montwé 2023-07-31 16:35:07 +02:00
parent 660f183607
commit 8cd96d2e77
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
2 changed files with 131 additions and 39 deletions

View file

@ -74,7 +74,7 @@ class AccountSetupViewModel(
}
}
SetupStep.OUTGOING_CONFIG -> changeToSetupStep(SetupStep.INCOMING_VALIDATION)
SetupStep.OUTGOING_CONFIG -> changeToSetupStep(SetupStep.INCOMING_CONFIG)
SetupStep.OUTGOING_VALIDATION -> {
if (state.value.isAutomaticConfig) {
changeToSetupStep(SetupStep.AUTO_CONFIG)
@ -83,7 +83,11 @@ class AccountSetupViewModel(
}
}
SetupStep.OPTIONS -> changeToSetupStep(SetupStep.OUTGOING_VALIDATION)
SetupStep.OPTIONS -> if (state.value.isAutomaticConfig) {
changeToSetupStep(SetupStep.AUTO_CONFIG)
} else {
changeToSetupStep(SetupStep.OUTGOING_CONFIG)
}
}
}

View file

@ -7,6 +7,8 @@ import app.k9mail.autodiscovery.api.SmtpServerSettings
import app.k9mail.core.common.net.toHostname
import app.k9mail.core.common.net.toPort
import app.k9mail.core.ui.compose.testing.MainDispatcherRule
import app.k9mail.core.ui.compose.testing.mvi.assertThatAndMviTurbinesConsumed
import app.k9mail.core.ui.compose.testing.mvi.turbinesWithInitialStateCheck
import app.k9mail.feature.account.setup.domain.entity.AccountOptions
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType
import app.k9mail.feature.account.setup.domain.entity.ConnectionSecurity
@ -227,31 +229,12 @@ class AccountSetupViewModelTest {
authStateStorage = authStateStorage,
initialState = initialState,
)
val stateTurbine = viewModel.state.testIn(backgroundScope)
val effectTurbine = viewModel.effect.testIn(backgroundScope)
val turbines = listOf(stateTurbine, effectTurbine)
// Initial state
assertThatAndTurbinesConsumed(
actual = stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.OPTIONS)
}
val turbines = turbinesWithInitialStateCheck(viewModel, initialState,)
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(),
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.OUTGOING_CONFIG)
@ -259,17 +242,8 @@ 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(),
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.INCOMING_CONFIG)
@ -277,8 +251,8 @@ class AccountSetupViewModelTest {
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndTurbinesConsumed(
actual = stateTurbine.awaitItem(),
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.AUTO_CONFIG)
@ -286,8 +260,122 @@ class AccountSetupViewModelTest {
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndTurbinesConsumed(
actual = effectTurbine.awaitItem(),
assertThatAndMviTurbinesConsumed(
actual = turbines.effectTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(Effect.NavigateBack)
}
}
@Test
fun `should go back from OPTIONS step on back event when isAutomaticConfig enabled`() = runTest {
val initialState = State(
setupStep = SetupStep.OPTIONS,
isAutomaticConfig = true,
)
val viewModel = AccountSetupViewModel(
createAccount = { _, _, _, _, _ -> "accountUuid" },
autoDiscoveryViewModel = autoDiscoveryViewModel,
incomingViewModel = FakeAccountIncomingConfigViewModel(),
incomingValidationViewModel = FakeAccountValidationViewModel(),
outgoingViewModel = FakeAccountOutgoingConfigViewModel(),
outgoingValidationViewModel = FakeAccountValidationViewModel(),
optionsViewModel = FakeAccountOptionsViewModel(),
authStateStorage = authStateStorage,
initialState = initialState,
)
val turbines = turbinesWithInitialStateCheck(viewModel, initialState)
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.AUTO_CONFIG)
}
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.effectTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(Effect.NavigateBack)
}
}
@Test
fun `should go back from OUTGOING_VALIDATION step state on back event when isAutomaticConfig enabled`() = runTest {
val initialState = State(
setupStep = SetupStep.OUTGOING_VALIDATION,
isAutomaticConfig = true,
)
val viewModel = AccountSetupViewModel(
createAccount = { _, _, _, _, _ -> "accountUuid" },
autoDiscoveryViewModel = autoDiscoveryViewModel,
incomingViewModel = FakeAccountIncomingConfigViewModel(),
incomingValidationViewModel = FakeAccountValidationViewModel(),
outgoingViewModel = FakeAccountOutgoingConfigViewModel(),
outgoingValidationViewModel = FakeAccountValidationViewModel(),
optionsViewModel = FakeAccountOptionsViewModel(),
authStateStorage = authStateStorage,
initialState = initialState,
)
val turbines = turbinesWithInitialStateCheck(viewModel, initialState)
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.AUTO_CONFIG)
}
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.effectTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(Effect.NavigateBack)
}
}
@Test
fun `should go back from INCOMING_VALIDATION step state on back event when isAutomaticConfig enabled`() = runTest {
val initialState = State(
setupStep = SetupStep.OUTGOING_VALIDATION,
isAutomaticConfig = true,
)
val viewModel = AccountSetupViewModel(
createAccount = { _, _, _, _, _ -> "accountUuid" },
autoDiscoveryViewModel = autoDiscoveryViewModel,
incomingViewModel = FakeAccountIncomingConfigViewModel(),
incomingValidationViewModel = FakeAccountValidationViewModel(),
outgoingViewModel = FakeAccountOutgoingConfigViewModel(),
outgoingValidationViewModel = FakeAccountValidationViewModel(),
optionsViewModel = FakeAccountOptionsViewModel(),
authStateStorage = authStateStorage,
initialState = initialState,
)
val turbines = turbinesWithInitialStateCheck(viewModel, initialState)
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
prop(State::setupStep).isEqualTo(SetupStep.AUTO_CONFIG)
}
viewModel.event(AccountSetupContract.Event.OnBack)
assertThatAndMviTurbinesConsumed(
actual = turbines.effectTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(Effect.NavigateBack)