Change navigation to not return to special folders screen
This commit is contained in:
parent
0c1d3b0ca7
commit
a1a36909c5
7 changed files with 28 additions and 11 deletions
|
@ -129,8 +129,18 @@ fun AccountSetupNavHost(
|
|||
|
||||
composable(route = NESTED_NAVIGATION_SPECIAL_FOLDERS) {
|
||||
SpecialFoldersScreen(
|
||||
onNext = {
|
||||
navController.navigate(NESTED_NAVIGATION_DISPLAY_OPTIONS)
|
||||
onNext = { isManualSetup ->
|
||||
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() },
|
||||
viewModel = koinViewModel<SpecialFoldersViewModel>(),
|
||||
|
|
|
@ -15,6 +15,7 @@ interface SpecialFoldersContract {
|
|||
data class State(
|
||||
val formState: FormState = FormState(),
|
||||
|
||||
val isManualSetup: Boolean = false,
|
||||
val isSuccess: Boolean = false,
|
||||
override val error: Failure? = null,
|
||||
override val isLoading: Boolean = true,
|
||||
|
@ -50,7 +51,10 @@ interface SpecialFoldersContract {
|
|||
}
|
||||
|
||||
sealed interface Effect {
|
||||
data object NavigateNext : Effect
|
||||
data class NavigateNext(
|
||||
val isManualSetup: Boolean,
|
||||
) : Effect
|
||||
|
||||
data object NavigateBack : Effect
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ import app.k9mail.feature.account.setup.ui.specialfolders.fake.FakeSpecialFolder
|
|||
|
||||
@Composable
|
||||
fun SpecialFoldersScreen(
|
||||
onNext: () -> Unit,
|
||||
onNext: (isManualSetup: Boolean) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
viewModel: ViewModel,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val (state, dispatch) = viewModel.observe { effect ->
|
||||
when (effect) {
|
||||
Effect.NavigateNext -> onNext()
|
||||
is Effect.NavigateNext -> onNext(effect.isManualSetup)
|
||||
Effect.NavigateBack -> onBack()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ class SpecialFoldersViewModel(
|
|||
is ValidationResult.Failure -> {
|
||||
updateState {
|
||||
it.copy(
|
||||
isManualSetup = true,
|
||||
isSuccess = false,
|
||||
isLoading = false,
|
||||
)
|
||||
|
@ -128,7 +129,7 @@ class SpecialFoldersViewModel(
|
|||
|
||||
private fun navigateNext() {
|
||||
viewModelScope.coroutineContext.cancelChildren()
|
||||
emitEffect(Effect.NavigateNext)
|
||||
emitEffect(Effect.NavigateNext(isManualSetup = state.value.isManualSetup))
|
||||
}
|
||||
|
||||
private fun onBackClicked() {
|
||||
|
|
|
@ -33,7 +33,7 @@ class SpecialFoldersScreenKtTest : ComposeTest() {
|
|||
assertThat(onNextCounter).isEqualTo(0)
|
||||
assertThat(onBackCounter).isEqualTo(0)
|
||||
|
||||
viewModel.effect(Effect.NavigateNext)
|
||||
viewModel.effect(Effect.NavigateNext(true))
|
||||
|
||||
assertThat(onNextCounter).isEqualTo(1)
|
||||
assertThat(onBackCounter).isEqualTo(0)
|
||||
|
|
|
@ -16,6 +16,7 @@ class SpecialFoldersStateTest {
|
|||
assertThat(state).isEqualTo(
|
||||
State(
|
||||
formState = FormState(),
|
||||
isManualSetup = false,
|
||||
isSuccess = false,
|
||||
error = null,
|
||||
isLoading = true,
|
||||
|
|
|
@ -75,7 +75,7 @@ class SpecialFoldersViewModelTest {
|
|||
}
|
||||
|
||||
turbines.assertThatAndEffectTurbineConsumed {
|
||||
isEqualTo(Effect.NavigateNext)
|
||||
isEqualTo(Effect.NavigateNext(false))
|
||||
}
|
||||
|
||||
assertThat(accountStateRepository.getState()).isEqualTo(
|
||||
|
@ -108,6 +108,7 @@ class SpecialFoldersViewModelTest {
|
|||
testSubject.event(Event.LoadSpecialFolderOptions)
|
||||
|
||||
val unvalidatedState = initialState.copy(
|
||||
isManualSetup = true,
|
||||
isLoading = false,
|
||||
isSuccess = false,
|
||||
formState = FormState(
|
||||
|
@ -187,7 +188,7 @@ class SpecialFoldersViewModelTest {
|
|||
|
||||
@Test
|
||||
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 testSubject = createTestSubject(
|
||||
initialState = initialState,
|
||||
|
@ -200,7 +201,7 @@ class SpecialFoldersViewModelTest {
|
|||
assertThat(turbines.awaitStateItem()).isEqualTo(initialState.copy(isLoading = false))
|
||||
|
||||
turbines.assertThatAndEffectTurbineConsumed {
|
||||
isEqualTo(Effect.NavigateNext)
|
||||
isEqualTo(Effect.NavigateNext(true))
|
||||
}
|
||||
|
||||
assertThat(accountStateRepository.getState()).isEqualTo(
|
||||
|
@ -268,7 +269,7 @@ class SpecialFoldersViewModelTest {
|
|||
)
|
||||
|
||||
turbines.assertThatAndEffectTurbineConsumed {
|
||||
isEqualTo(Effect.NavigateNext)
|
||||
isEqualTo(Effect.NavigateNext(false))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue