From 7628330f72cc442c4eb37c07e210773cb2968861 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 2 Jul 2026 16:10:45 -0400 Subject: [PATCH] test(android/library): stub SyncController.lastSyncError with a real StateFlow The VM now combines lastSyncError into uiState; a relaxed-mock flow never emits, so the combine never fired and the state sat at Loading. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01TsF3cNoKrqCYsU78cXC8U6 --- .../minstrel/library/ui/LibraryViewModelTest.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/android/app/src/test/java/com/fabledsword/minstrel/library/ui/LibraryViewModelTest.kt b/android/app/src/test/java/com/fabledsword/minstrel/library/ui/LibraryViewModelTest.kt index d726121f..494cb4cb 100644 --- a/android/app/src/test/java/com/fabledsword/minstrel/library/ui/LibraryViewModelTest.kt +++ b/android/app/src/test/java/com/fabledsword/minstrel/library/ui/LibraryViewModelTest.kt @@ -11,6 +11,7 @@ import com.fabledsword.minstrel.testutil.MainDispatcherExtension import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest @@ -21,6 +22,13 @@ import kotlin.test.assertEquals @ExtendWith(MainDispatcherExtension::class) class LibraryViewModelTest { + // lastSyncError needs a real StateFlow: the VM combines it into uiState, + // and a relaxed-mock flow never emits, so the combine would never fire. + private fun syncControllerMock(): SyncController = + mockk(relaxed = true) { + every { lastSyncError } returns MutableStateFlow(null) + } + @Test fun `initial state is Loading before any DAO emission`() = runTest { val repo = mockk() @@ -29,7 +37,7 @@ class LibraryViewModelTest { val vm = LibraryViewModel( repo, - mockk(relaxed = true), + syncControllerMock(), mockk(relaxed = true), ) @@ -51,7 +59,7 @@ class LibraryViewModelTest { val vm = LibraryViewModel( repo, - mockk(relaxed = true), + syncControllerMock(), mockk(relaxed = true), ) @@ -71,7 +79,7 @@ class LibraryViewModelTest { val vm = LibraryViewModel( repo, - mockk(relaxed = true), + syncControllerMock(), mockk(relaxed = true), ) @@ -94,7 +102,7 @@ class LibraryViewModelTest { val vm = LibraryViewModel( repo, - mockk(relaxed = true), + syncControllerMock(), mockk(relaxed = true), )