🧪 [Testing Improvement] Add error state test for loadYears in ScheduleViewModel - #188
Conversation
Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request adds a new unit test, loadYearsErrorUpdatesState, to verify that the UI state updates correctly when a network error occurs during the loading of years. The review feedback suggests also asserting that isInitialLoading is set to false in this error state to prevent the UI from getting stuck in an infinite loading screen.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| assertFalse(state.isLoading) | ||
| assertTrue(state.isError) | ||
| assertEquals("Network error", state.errorMessage) |
There was a problem hiding this comment.
It is highly recommended to also assert that isInitialLoading is set to false. In ScheduleViewModel, isInitialLoading is updated to false before loadYears() is called. Verifying this in the error state test ensures that the UI doesn't get stuck in an infinite full-screen loading state when an error occurs.
assertFalse(state.isLoading)
assertFalse(state.isInitialLoading)
assertTrue(state.isError)
assertEquals("Network error", state.errorMessage)There was a problem hiding this comment.
Pull request overview
Adds a unit test to cover ScheduleViewModel.loadYears() error handling when ScheduleRepository.getScheduleYears() throws, ensuring ScheduleUiState transitions to an error state in that scenario.
Changes:
- Added
loadYearsErrorUpdatesStatetest to assertisLoading=false,isError=true, anderrorMessageis propagated when years loading fails. - Added the missing
assertTrueimport needed by the new assertion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🎯 What: Added test coverage for error state updates when
repository.getScheduleYears()throws an exception inScheduleViewModel.loadYears().📊 Coverage: Added
loadYearsErrorUpdatesStateto verify the UI state incorrectly setsisLoadingto false,isErrorto true, and captures the error message properly when the API fails.✨ Result: Improved confidence in
ScheduleViewModelerror handling and completed testing forScheduleUiStatetransitions.PR created automatically by Jules for task 11772296962705487162 started by @alvin000009238