Skip to content

Commit

Permalink
Retry loading the folder list when 'retry' button was clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
cketti committed Jan 2, 2024
1 parent 8b21d9a commit 19a064c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ class SpecialFoldersViewModel(
viewModelScope.coroutineContext.cancelChildren()
updateState {
it.copy(
isLoading = true,
error = null,
)
}
onLoadSpecialFolderOptions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 19a064c

Please sign in to comment.