Fix TopicViewModel id

Change-Id: I5c58b58566f78abffb6621d5753986fe7d11e4f6
pull/2/head
Adetunji Dahunsi 3 years ago committed by Don Turner
parent 4774e6c9fc
commit e2c1bbe754

@ -53,7 +53,9 @@ class TopicViewModel @Inject constructor(
// Observe the News for this topic // Observe the News for this topic
private val newsStream: Flow<Result<List<NewsResource>>> = private val newsStream: Flow<Result<List<NewsResource>>> =
newsRepository.getNewsResourcesStream(setOf(topicId), emptySet()).asResult() newsRepository.getNewsResourcesStream(
filterTopicIds = setOf(element = topicId),
).asResult()
val uiState: StateFlow<TopicScreenUiState> = val uiState: StateFlow<TopicScreenUiState> =
combine( combine(

@ -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.repository.TestTopicsRepository
import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule
import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import org.junit.Assert.assertEquals 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 @Test
fun uiStateNews_whenInitialized_thenShowLoading() = runTest { fun uiStateNews_whenInitialized_thenShowLoading() = runTest {
viewModel.uiState.test { viewModel.uiState.test {

Loading…
Cancel
Save