Change navigation to not return to special folders screen

This commit is contained in:
Wolf-Martell Montwé 2024-01-26 13:30:00 +01:00
parent 0c1d3b0ca7
commit a1a36909c5
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
7 changed files with 28 additions and 11 deletions

View file

@ -129,8 +129,18 @@ fun AccountSetupNavHost(
composable(route = NESTED_NAVIGATION_SPECIAL_FOLDERS) { composable(route = NESTED_NAVIGATION_SPECIAL_FOLDERS) {
SpecialFoldersScreen( SpecialFoldersScreen(
onNext = { onNext = { isManualSetup ->
navController.navigate(NESTED_NAVIGATION_DISPLAY_OPTIONS) navController.navigate(NESTED_NAVIGATION_DISPLAY_OPTIONS) {
if (isManualSetup) {
popUpTo(NESTED_NAVIGATION_SPECIAL_FOLDERS)
} else {
if (isAutomaticConfig) {
popUpTo(NESTED_NAVIGATION_AUTO_CONFIG)
} else {
popUpTo(NESTED_NAVIGATION_OUTGOING_SERVER_CONFIG)
}
}
}
}, },
onBack = { navController.popBackStack() }, onBack = { navController.popBackStack() },
viewModel = koinViewModel<SpecialFoldersViewModel>(), viewModel = koinViewModel<SpecialFoldersViewModel>(),

View file

@ -15,6 +15,7 @@ interface SpecialFoldersContract {
data class State( data class State(
val formState: FormState = FormState(), val formState: FormState = FormState(),
val isManualSetup: Boolean = false,
val isSuccess: Boolean = false, val isSuccess: Boolean = false,
override val error: Failure? = null, override val error: Failure? = null,
override val isLoading: Boolean = true, override val isLoading: Boolean = true,
@ -50,7 +51,10 @@ interface SpecialFoldersContract {
} }
sealed interface Effect { sealed interface Effect {
data object NavigateNext : Effect data class NavigateNext(
val isManualSetup: Boolean,
) : Effect
data object NavigateBack : Effect data object NavigateBack : Effect
} }

View file

@ -17,14 +17,14 @@ import app.k9mail.feature.account.setup.ui.specialfolders.fake.FakeSpecialFolder
@Composable @Composable
fun SpecialFoldersScreen( fun SpecialFoldersScreen(
onNext: () -> Unit, onNext: (isManualSetup: Boolean) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
viewModel: ViewModel, viewModel: ViewModel,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val (state, dispatch) = viewModel.observe { effect -> val (state, dispatch) = viewModel.observe { effect ->
when (effect) { when (effect) {
Effect.NavigateNext -> onNext() is Effect.NavigateNext -> onNext(effect.isManualSetup)
Effect.NavigateBack -> onBack() Effect.NavigateBack -> onBack()
} }
} }

View file

@ -64,6 +64,7 @@ class SpecialFoldersViewModel(
is ValidationResult.Failure -> { is ValidationResult.Failure -> {
updateState { updateState {
it.copy( it.copy(
isManualSetup = true,
isSuccess = false, isSuccess = false,
isLoading = false, isLoading = false,
) )
@ -128,7 +129,7 @@ class SpecialFoldersViewModel(
private fun navigateNext() { private fun navigateNext() {
viewModelScope.coroutineContext.cancelChildren() viewModelScope.coroutineContext.cancelChildren()
emitEffect(Effect.NavigateNext) emitEffect(Effect.NavigateNext(isManualSetup = state.value.isManualSetup))
} }
private fun onBackClicked() { private fun onBackClicked() {

View file

@ -33,7 +33,7 @@ class SpecialFoldersScreenKtTest : ComposeTest() {
assertThat(onNextCounter).isEqualTo(0) assertThat(onNextCounter).isEqualTo(0)
assertThat(onBackCounter).isEqualTo(0) assertThat(onBackCounter).isEqualTo(0)
viewModel.effect(Effect.NavigateNext) viewModel.effect(Effect.NavigateNext(true))
assertThat(onNextCounter).isEqualTo(1) assertThat(onNextCounter).isEqualTo(1)
assertThat(onBackCounter).isEqualTo(0) assertThat(onBackCounter).isEqualTo(0)

View file

@ -16,6 +16,7 @@ class SpecialFoldersStateTest {
assertThat(state).isEqualTo( assertThat(state).isEqualTo(
State( State(
formState = FormState(), formState = FormState(),
isManualSetup = false,
isSuccess = false, isSuccess = false,
error = null, error = null,
isLoading = true, isLoading = true,

View file

@ -75,7 +75,7 @@ class SpecialFoldersViewModelTest {
} }
turbines.assertThatAndEffectTurbineConsumed { turbines.assertThatAndEffectTurbineConsumed {
isEqualTo(Effect.NavigateNext) isEqualTo(Effect.NavigateNext(false))
} }
assertThat(accountStateRepository.getState()).isEqualTo( assertThat(accountStateRepository.getState()).isEqualTo(
@ -108,6 +108,7 @@ class SpecialFoldersViewModelTest {
testSubject.event(Event.LoadSpecialFolderOptions) testSubject.event(Event.LoadSpecialFolderOptions)
val unvalidatedState = initialState.copy( val unvalidatedState = initialState.copy(
isManualSetup = true,
isLoading = false, isLoading = false,
isSuccess = false, isSuccess = false,
formState = FormState( formState = FormState(
@ -187,7 +188,7 @@ class SpecialFoldersViewModelTest {
@Test @Test
fun `should save form data and emit NavigateNext effect when OnNextClicked event received`() = runTest { fun `should save form data and emit NavigateNext effect when OnNextClicked event received`() = runTest {
val initialState = State(isSuccess = true) val initialState = State(isManualSetup = true)
val accountStateRepository = InMemoryAccountStateRepository() val accountStateRepository = InMemoryAccountStateRepository()
val testSubject = createTestSubject( val testSubject = createTestSubject(
initialState = initialState, initialState = initialState,
@ -200,7 +201,7 @@ class SpecialFoldersViewModelTest {
assertThat(turbines.awaitStateItem()).isEqualTo(initialState.copy(isLoading = false)) assertThat(turbines.awaitStateItem()).isEqualTo(initialState.copy(isLoading = false))
turbines.assertThatAndEffectTurbineConsumed { turbines.assertThatAndEffectTurbineConsumed {
isEqualTo(Effect.NavigateNext) isEqualTo(Effect.NavigateNext(true))
} }
assertThat(accountStateRepository.getState()).isEqualTo( assertThat(accountStateRepository.getState()).isEqualTo(
@ -268,7 +269,7 @@ class SpecialFoldersViewModelTest {
) )
turbines.assertThatAndEffectTurbineConsumed { turbines.assertThatAndEffectTurbineConsumed {
isEqualTo(Effect.NavigateNext) isEqualTo(Effect.NavigateNext(false))
} }
} }