diff --git a/feature-topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt b/feature-topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt index bf7806a39..f96b8d765 100644 --- a/feature-topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt +++ b/feature-topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt @@ -53,7 +53,9 @@ class TopicViewModel @Inject constructor( // Observe the News for this topic private val newsStream: Flow>> = - newsRepository.getNewsResourcesStream(setOf(topicId), emptySet()).asResult() + newsRepository.getNewsResourcesStream( + filterTopicIds = setOf(element = topicId), + ).asResult() val uiState: StateFlow = combine( diff --git a/feature-topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature-topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index bec7ed35c..891fbea0f 100644 --- a/feature-topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature-topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -26,6 +26,7 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepo import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG +import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant import org.junit.Assert.assertEquals @@ -52,6 +53,25 @@ class TopicViewModelTest { ) } + @Test + fun uiStateAuthor_whenSuccess_matchesTopicFromRepository() = runTest { + viewModel.uiState.test { + awaitItem() + topicsRepository.sendTopics(testInputTopics.map(FollowableTopic::topic)) + topicsRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) + val item = awaitItem() + assertTrue(item.topicState is TopicUiState.Success) + + val successTopicState = item.topicState as TopicUiState.Success + val topicFromRepository = topicsRepository.getTopic( + testInputTopics[0].topic.id + ).first() + + assertEquals(topicFromRepository, successTopicState.followableTopic.topic) + cancel() + } + } + @Test fun uiStateNews_whenInitialized_thenShowLoading() = runTest { viewModel.uiState.test {