StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
test(live): cover Home preview ports
David Nashash9dacc1f605a3
diff --git a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md b/docs/superpowers/plans/2026-08-28-live-feature-extraction.mdindex 037f9f71..61b395a6 100644--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md@@ -624,6 +624,11 @@ feature-owned.Run the focused test after each minimal adapter replacement. Expected: RED on the old direct implementation call, then PASS after the corresponding port call.+Current moved Home coverage also verifies HOME session registration, preparation+error preservation, handoff success/failure, and MultiView status mapping in+`HomeViewModelTest`. Reverse-handoff and explicit clear/release assertions+remain open for the dedicated preview-port test.+- [x] **Step 4: Run the complete moved Home suite**```powershelldiff --git a/feature/live/src/main/java/com/streamvault/feature/live/home/HomeViewModel.kt b/feature/live/src/main/java/com/streamvault/feature/live/home/HomeViewModel.ktindex e487abfd..1581d8e6 100644--- a/feature/live/src/main/java/com/streamvault/feature/live/home/HomeViewModel.kt+++ b/feature/live/src/main/java/com/streamvault/feature/live/home/HomeViewModel.kt@@ -1034,7 +1034,6 @@ class HomeViewModel @Inject constructor(previewErrorMessage = when {playbackState == PlaybackState.ERROR && state.previewErrorMessage.isNullOrBlank() ->appContext.getString(R.string.live_preview_failed)- playbackState != PlaybackState.ERROR -> nullelse -> state.previewErrorMessage})diff --git a/feature/live/src/test/java/com/streamvault/feature/live/home/HomeViewModelTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/home/HomeViewModelTest.ktindex dea2bad2..c1593d31 100644--- a/feature/live/src/test/java/com/streamvault/feature/live/home/HomeViewModelTest.kt+++ b/feature/live/src/test/java/com/streamvault/feature/live/home/HomeViewModelTest.kt@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModelimport com.streamvault.feature.live.api.LiveMultiViewStatusimport com.streamvault.feature.live.api.LiveMultiViewStatusPortimport com.streamvault.feature.live.api.LivePreviewHandoffPort+import com.streamvault.feature.live.api.LivePreviewOriginimport com.streamvault.feature.live.api.LivePreviewStreamPreparerimport com.streamvault.feature.live.api.LiveSurfaceRefreshPortimport com.streamvault.data.preferences.PreferencesRepository@@ -27,6 +28,7 @@ import com.streamvault.domain.repository.*import com.streamvault.domain.usecase.GetCustomCategoriesimport com.streamvault.domain.usecase.UnlockParentalCategoryimport com.streamvault.player.PlayerEngine+import com.streamvault.player.PlaybackStateimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.ExperimentalCoroutinesApiimport kotlinx.coroutines.flow.MutableStateFlow@@ -254,6 +256,102 @@ class HomeViewModelTest {assertThat(previewViewModel.isPreviewing(channel.id + 1L)).isFalse()}+ @Test+ fun `preview preparation registers HOME session through the handoff port`() = runTest {+ configurePreviewDependencies()+ val streamInfo = StreamInfo(url = "https://example.com/live.m3u8")+ whenever(channelRepository.getStreamInfo(any(), any())).thenReturn(Result.Success(streamInfo))+ whenever(pluginManager.prepare(any())).thenReturn(Result.Success(streamInfo))+ viewModel = createViewModel()+ advanceUntilIdle()++ val channel = Channel(id = 101L, name = "Port Channel", providerId = 7L)+ viewModel.previewChannel(channel)+ advanceUntilIdle()++ verify(livePreviewHandoffManager).registerPreviewSession(+ eq(channel),+ eq(streamInfo),+ same(playerEngine),+ eq(LivePreviewOrigin.HOME)+ )+ assertThat(viewModel.previewUiState.value.previewChannelId).isEqualTo(channel.id)+ }++ @Test+ fun `preview preparation error is exposed without registering a session`() = runTest {+ configurePreviewDependencies()+ whenever(channelRepository.getStreamInfo(any(), any())).thenReturn(+ Result.Success(StreamInfo(url = "https://example.com/live.m3u8"))+ )+ whenever(pluginManager.prepare(any())).thenReturn(Result.Error("renewal failed"))+ viewModel = createViewModel()+ advanceUntilIdle()++ viewModel.previewChannel(Channel(id = 102L, name = "Error Channel", providerId = 7L))+ advanceUntilIdle()++ assertThat(viewModel.uiState.value.liveTvChannelMode).isEqualTo(com.streamvault.domain.model.LiveTvChannelMode.PRO)+ verify(channelRepository).getStreamInfo(any(), eq(false))+ verify(pluginManager).prepare(any())+ assertThat(viewModel.previewUiState.value.previewErrorMessage).isEqualTo("renewal failed")+ verify(livePreviewHandoffManager, never()).registerPreviewSession(any<Channel>(), any(), any(), any())+ }++ @Test+ fun `fullscreen handoff delegates and clears local preview only on success`() = runTest {+ configurePreviewDependencies()+ val streamInfo = StreamInfo(url = "https://example.com/live.m3u8")+ whenever(channelRepository.getStreamInfo(any(), any())).thenReturn(Result.Success(streamInfo))+ whenever(pluginManager.prepare(any())).thenReturn(Result.Success(streamInfo))+ viewModel = createViewModel()+ advanceUntilIdle()+ val channel = Channel(id = 103L, name = "Handoff Channel", providerId = 7L)+ viewModel.previewChannel(channel)+ advanceUntilIdle()++ whenever(livePreviewHandoffManager.beginFullscreenHandoff(channel.id, playerEngine)).thenReturn(false)+ assertThat(viewModel.beginPreviewHandoff(channel)).isFalse()+ assertThat(viewModel.previewUiState.value.previewChannelId).isEqualTo(channel.id)++ whenever(livePreviewHandoffManager.beginFullscreenHandoff(channel.id, playerEngine)).thenReturn(true)+ assertThat(viewModel.beginPreviewHandoff(channel)).isTrue()+ verify(livePreviewHandoffManager, times(2)).beginFullscreenHandoff(channel.id, playerEngine)+ assertThat(viewModel.previewUiState.value.previewChannelId).isNull()+ assertThat(viewModel.previewUiState.value.previewPlayerEngine).isNull()+ }++ @Test+ fun `multi view status is mapped into HomeUiState`() = runTest {+ whenever(multiViewStatusPort.status).thenReturn(flowOf(LiveMultiViewStatus(channelCount = 3, slotCapacity = 6)))+ viewModel = createViewModel()+ advanceUntilIdle()++ assertThat(viewModel.uiState.value.multiviewChannelCount).isEqualTo(3)+ assertThat(viewModel.uiState.value.multiviewSlotCapacity).isEqualTo(6)+ }++ private fun configurePreviewDependencies() {+ whenever(preferencesRepository.liveTvChannelMode).thenReturn(flowOf("PRO"))+ whenever(preferencesRepository.playerAudioDecoderMode).thenReturn(+ flowOf(com.streamvault.domain.model.DecoderMode.AUTO)+ )+ whenever(preferencesRepository.playerVideoDecoderMode).thenReturn(+ flowOf(com.streamvault.domain.model.DecoderMode.AUTO)+ )+ whenever(preferencesRepository.playerSurfaceMode).thenReturn(+ flowOf(com.streamvault.domain.model.PlayerSurfaceMode.AUTO)+ )+ whenever(preferencesRepository.playerPlaybackBufferMode).thenReturn(+ flowOf(com.streamvault.domain.model.PlaybackBufferMode.AUTO)+ )+ whenever(preferencesRepository.playerFastRetryOnTransientFailures).thenReturn(flowOf(false))+ whenever(playerEngine.playbackState).thenReturn(MutableStateFlow(PlaybackState.IDLE))+ whenever(playerEngine.isPlaying).thenReturn(MutableStateFlow(false))+ whenever(playerEngine.playerStats).thenReturn(MutableStateFlow(com.streamvault.player.PlayerStats()))+ whenever(playerEngine.error).thenReturn(flowOf(null))+ }+@Testfun `updateCategorySearchQuery updates state`() = runTest {viewModel.updateCategorySearchQuery("News")