|
|
@ -64,15 +64,15 @@ class TopicViewModelTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateAuthor_whenSuccess_matchesTopicFromRepository() = runTest {
|
|
|
|
fun uiStateTopic_whenSuccess_matchesTopicFromRepository() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() }
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map(FollowableTopic::topic))
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map(FollowableTopic::topic))
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
val item = viewModel.uiState.value
|
|
|
|
val item = viewModel.topicUiState.value
|
|
|
|
assertTrue(item.topicState is TopicUiState.Success)
|
|
|
|
assertTrue(item is TopicUiState.Success)
|
|
|
|
|
|
|
|
|
|
|
|
val successTopicState = item.topicState as TopicUiState.Success
|
|
|
|
val successTopicState = item as TopicUiState.Success
|
|
|
|
val topicFromRepository = topicsRepository.getTopic(
|
|
|
|
val topicFromRepository = topicsRepository.getTopic(
|
|
|
|
testInputTopics[0].topic.id
|
|
|
|
testInputTopics[0].topic.id
|
|
|
|
).first()
|
|
|
|
).first()
|
|
|
@ -84,20 +84,20 @@ class TopicViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateNews_whenInitialized_thenShowLoading() = runTest {
|
|
|
|
fun uiStateNews_whenInitialized_thenShowLoading() = runTest {
|
|
|
|
assertEquals(NewsUiState.Loading, viewModel.uiState.value.newsState)
|
|
|
|
assertEquals(NewsUiState.Loading, viewModel.newUiState.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateTopic_whenInitialized_thenShowLoading() = runTest {
|
|
|
|
fun uiStateTopic_whenInitialized_thenShowLoading() = runTest {
|
|
|
|
assertEquals(TopicUiState.Loading, viewModel.uiState.value.topicState)
|
|
|
|
assertEquals(TopicUiState.Loading, viewModel.topicUiState.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicLoading_thenShowLoading() = runTest {
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicLoading_thenShowLoading() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() }
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
assertEquals(TopicUiState.Loading, viewModel.uiState.value.topicState)
|
|
|
|
assertEquals(TopicUiState.Loading, viewModel.topicUiState.value)
|
|
|
|
|
|
|
|
|
|
|
|
collectJob.cancel()
|
|
|
|
collectJob.cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -105,13 +105,15 @@ class TopicViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccess_thenTopicSuccessAndNewsLoading() =
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccess_thenTopicSuccessAndNewsLoading() =
|
|
|
|
runTest {
|
|
|
|
runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() }
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
val item = viewModel.uiState.value
|
|
|
|
val topicUiState = viewModel.topicUiState.value
|
|
|
|
assertTrue(item.topicState is TopicUiState.Success)
|
|
|
|
val newsUiState = viewModel.newUiState.value
|
|
|
|
assertTrue(item.newsState is NewsUiState.Loading)
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(topicUiState is TopicUiState.Success)
|
|
|
|
|
|
|
|
assertTrue(newsUiState is NewsUiState.Loading)
|
|
|
|
|
|
|
|
|
|
|
|
collectJob.cancel()
|
|
|
|
collectJob.cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,21 +121,23 @@ class TopicViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccessAndNewsIsSuccess_thenAllSuccess() =
|
|
|
|
fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccessAndNewsIsSuccess_thenAllSuccess() =
|
|
|
|
runTest {
|
|
|
|
runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() }
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id))
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
val item = viewModel.uiState.value
|
|
|
|
val topicUiState = viewModel.topicUiState.value
|
|
|
|
assertTrue(item.topicState is TopicUiState.Success)
|
|
|
|
val newsUiState = viewModel.newUiState.value
|
|
|
|
assertTrue(item.newsState is NewsUiState.Success)
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(topicUiState is TopicUiState.Success)
|
|
|
|
|
|
|
|
assertTrue(newsUiState is NewsUiState.Success)
|
|
|
|
|
|
|
|
|
|
|
|
collectJob.cancel()
|
|
|
|
collectJob.cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun uiStateTopic_whenFollowingTopic_thenShowUpdatedTopic() = runTest {
|
|
|
|
fun uiStateTopic_whenFollowingTopic_thenShowUpdatedTopic() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() }
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
topicsRepository.sendTopics(testInputTopics.map { it.topic })
|
|
|
|
// Set which topic IDs are followed, not including 0.
|
|
|
|
// Set which topic IDs are followed, not including 0.
|
|
|
@ -143,7 +147,7 @@ class TopicViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
TopicUiState.Success(followableTopic = testOutputTopics[0]),
|
|
|
|
TopicUiState.Success(followableTopic = testOutputTopics[0]),
|
|
|
|
viewModel.uiState.value.topicState
|
|
|
|
viewModel.topicUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
collectJob.cancel()
|
|
|
|
collectJob.cancel()
|
|
|
|