test(android/library): stub SyncController.lastSyncError with a real StateFlow
android / Build + lint + test (push) Successful in 3m45s
android / Build + lint + test (push) Successful in 3m45s
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsF3cNoKrqCYsU78cXC8U6
This commit is contained in:
+12
-4
@@ -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<SyncController>(relaxed = true) {
|
||||
every { lastSyncError } returns MutableStateFlow(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `initial state is Loading before any DAO emission`() = runTest {
|
||||
val repo = mockk<LibraryRepository>()
|
||||
@@ -29,7 +37,7 @@ class LibraryViewModelTest {
|
||||
|
||||
val vm = LibraryViewModel(
|
||||
repo,
|
||||
mockk<SyncController>(relaxed = true),
|
||||
syncControllerMock(),
|
||||
mockk<PlayerController>(relaxed = true),
|
||||
)
|
||||
|
||||
@@ -51,7 +59,7 @@ class LibraryViewModelTest {
|
||||
|
||||
val vm = LibraryViewModel(
|
||||
repo,
|
||||
mockk<SyncController>(relaxed = true),
|
||||
syncControllerMock(),
|
||||
mockk<PlayerController>(relaxed = true),
|
||||
)
|
||||
|
||||
@@ -71,7 +79,7 @@ class LibraryViewModelTest {
|
||||
|
||||
val vm = LibraryViewModel(
|
||||
repo,
|
||||
mockk<SyncController>(relaxed = true),
|
||||
syncControllerMock(),
|
||||
mockk<PlayerController>(relaxed = true),
|
||||
)
|
||||
|
||||
@@ -94,7 +102,7 @@ class LibraryViewModelTest {
|
||||
|
||||
val vm = LibraryViewModel(
|
||||
repo,
|
||||
mockk<SyncController>(relaxed = true),
|
||||
syncControllerMock(),
|
||||
mockk<PlayerController>(relaxed = true),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user