Merge pull request #7105 from thundernest/fix_timer_based_navigation

Fix timer based navigation
This commit is contained in:
Wolf-Martell Montwé 2023-08-01 07:49:38 +00:00 committed by GitHub
commit 7da66f1867
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 48 deletions

View file

@ -8,6 +8,7 @@ import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract.
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract.Event
import app.k9mail.feature.account.setup.ui.validation.AccountValidationContract.State
import com.fsck.k9.mail.server.ServerSettingsValidationResult
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -109,21 +110,7 @@ internal class AccountValidationViewModel(
}
private fun onBack() {
if (state.value.isSuccess) {
updateState {
it.copy(
isSuccess = false,
)
}
} else if (state.value.error != null) {
updateState {
it.copy(
error = null,
)
}
} else {
navigateBack()
}
navigateBack()
}
private fun onRetry() {
@ -135,9 +122,13 @@ internal class AccountValidationViewModel(
onValidateConfig()
}
private fun navigateBack() = emitEffect(Effect.NavigateBack)
private fun navigateBack() {
viewModelScope.coroutineContext.cancelChildren()
emitEffect(Effect.NavigateBack)
}
private fun navigateNext() {
viewModelScope.coroutineContext.cancelChildren()
emitEffect(Effect.NavigateNext)
}
}

View file

@ -163,38 +163,6 @@ class AccountValidationViewModelTest {
}
}
@Test
fun `should clear isSuccess when OnBackClicked event received when in success state`() = runTest {
val initialState = State(isSuccess = true)
val testSubject = createTestSubject(initialState = initialState)
val turbines = turbinesWithInitialStateCheck(testSubject, initialState)
testSubject.event(Event.OnBackClicked)
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(initialState.copy(isSuccess = false))
}
}
@Test
fun `should clear error when OnBackClicked event received when in error state`() = runTest {
val initialState = State(error = Error.ServerError("server error"))
val testSubject = createTestSubject(initialState = initialState)
val turbines = turbinesWithInitialStateCheck(testSubject, initialState)
testSubject.event(Event.OnBackClicked)
assertThatAndMviTurbinesConsumed(
actual = turbines.stateTurbine.awaitItem(),
turbines = turbines,
) {
isEqualTo(initialState.copy(error = null))
}
}
@Test
fun `should clear error and trigger check settings when OnRetryClicked event received`() = runTest {
val initialState = State(