Fix clear completed tasks being undone by immediate refresh#1067
Fix clear completed tasks being undone by immediate refresh#1067saadkhalidkhan wants to merge 2 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request removes an unnecessary manual refresh call in the TasksViewModel after clearing completed tasks and updates the associated test to use advanceUntilIdle(). Feedback suggests improving the test's robustness by waiting for a specific state condition instead of using uiState.first(), which can be prone to race conditions when testing StateFlow.
|
I signed it! |
The tasks list already updates via Room Flow after clearing completed tasks. Calling refresh() immediately reloads stale network data before saveTasksToNetwork() finishes, which can restore deleted tasks.
Use uiState.first { !it.isLoading } instead of first() to avoid inspecting stale StateFlow values.
d977426 to
a76293f
Compare
Summary
refresh()afterclearCompletedTasks()inTasksViewModel.Flow.saveTasksToNetwork()finishes (the fake network has a 2s delay), which can restore completed tasks the user just cleared.Test plan
:app:testDebugUnitTest(TasksViewModelTest)