Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test

Expand Down Expand Up @@ -74,6 +75,21 @@ class ScheduleViewModelTest {
assertEquals("202", viewModel.uiState.value.selectedClassValue)
}

@Test
fun loadYearsErrorUpdatesState() = runTest(dispatcher) {
val repository = ControllableScheduleRepository()
val viewModel = ScheduleViewModel(repository)
runCurrent()

repository.yearsDeferred.completeExceptionally(RuntimeException("Network error"))
runCurrent()

val state = viewModel.uiState.value
assertFalse(state.isLoading)
assertTrue(state.isError)
assertEquals("Network error", state.errorMessage)
Comment on lines +88 to +90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

}

@Test
fun savingWidgetPreferencesLogsAnonymousAnalytics() = runTest(dispatcher) {
val repository = ControllableScheduleRepository()
Expand Down
Loading