Retry loading the folder list when 'retry' button was clicked

This commit is contained in:
cketti 2023-12-19 22:23:55 +01:00
parent 8b21d9a239
commit 19a064c15f
2 changed files with 35 additions and 2 deletions

View file

@ -150,8 +150,10 @@ class SpecialFoldersViewModel(
viewModelScope.coroutineContext.cancelChildren()
updateState {
it.copy(
isLoading = true,
error = null,
)
}
onLoadSpecialFolderOptions()
}
}

View file

@ -249,8 +249,39 @@ class SpecialFoldersViewModelTest {
testSubject.event(Event.OnRetryClicked)
turbines.assertThatAndStateTurbineConsumed {
isEqualTo(initialState.copy(error = null))
assertThat(turbines.awaitStateItem()).isEqualTo(
initialState.copy(
isLoading = true,
error = null,
),
)
// Turbine misses the intermediate state because we're using UnconfinedTestDispatcher and StateFlow.
// Here we need to make sure the coroutine used to load the special folder options has completed.
mainDispatcherRule.testDispatcher.scheduler.advanceUntilIdle()
assertThat(turbines.awaitStateItem()).isEqualTo(
State(
isLoading = false,
isSuccess = true,
formState = FormState(
archiveSpecialFolderOptions = SPECIAL_FOLDER_OPTIONS.archiveSpecialFolderOptions,
draftsSpecialFolderOptions = SPECIAL_FOLDER_OPTIONS.draftsSpecialFolderOptions,
sentSpecialFolderOptions = SPECIAL_FOLDER_OPTIONS.sentSpecialFolderOptions,
spamSpecialFolderOptions = SPECIAL_FOLDER_OPTIONS.spamSpecialFolderOptions,
trashSpecialFolderOptions = SPECIAL_FOLDER_OPTIONS.trashSpecialFolderOptions,
selectedArchiveSpecialFolderOption = SPECIAL_FOLDER_ARCHIVE.copy(isAutomatic = true),
selectedDraftsSpecialFolderOption = SPECIAL_FOLDER_DRAFTS.copy(isAutomatic = true),
selectedSentSpecialFolderOption = SPECIAL_FOLDER_SENT.copy(isAutomatic = true),
selectedSpamSpecialFolderOption = SPECIAL_FOLDER_SPAM.copy(isAutomatic = true),
selectedTrashSpecialFolderOption = SPECIAL_FOLDER_TRASH.copy(isAutomatic = true),
),
),
)
turbines.assertThatAndEffectTurbineConsumed {
isEqualTo(Effect.NavigateNext)
}
}