Improvements

Change-Id: Ie4a782e2c26576098aff87ca164968886821cdcc
feature/interests-list-detail
Miłosz Moczkowski 2 years ago
parent 9d16265649
commit cd0b0925b8

@ -42,7 +42,7 @@ internal fun InterestsRoute(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
viewModel: InterestsViewModel = hiltViewModel(), viewModel: InterestsViewModel = hiltViewModel(),
) { ) {
val interestUiState by viewModel.interestUiState.collectAsStateWithLifecycle() val interestUiState by viewModel.interestsUiState.collectAsStateWithLifecycle()
val topicUiState by viewModel.topicUiState.collectAsStateWithLifecycle() val topicUiState by viewModel.topicUiState.collectAsStateWithLifecycle()
Row(modifier = modifier.fillMaxSize()) { Row(modifier = modifier.fillMaxSize()) {

@ -55,7 +55,7 @@ class InterestsViewModel @Inject constructor(
private val topicId: StateFlow<String?> = private val topicId: StateFlow<String?> =
savedStateHandle.getStateFlow(topicIdArg, null) savedStateHandle.getStateFlow(topicIdArg, null)
val interestUiState: StateFlow<InterestsUiState> = combine( val interestsUiState: StateFlow<InterestsUiState> = combine(
getFollowableTopics(sortBy = TopicSortField.NAME), getFollowableTopics(sortBy = TopicSortField.NAME),
topicId, topicId,
) { topics, selectedTopicId -> ) { topics, selectedTopicId ->

@ -78,22 +78,22 @@ class InterestsViewModelTest {
@Test @Test
fun uiState_whenInitialized_thenShowLoading() = runTest { fun uiState_whenInitialized_thenShowLoading() = runTest {
assertEquals(InterestsUiState.Loading, viewModel.interestUiState.value) assertEquals(InterestsUiState.Loading, viewModel.interestsUiState.value)
} }
@Test @Test
fun uiState_whenFollowedTopicsAreLoading_thenShowLoading() = runTest { fun uiState_whenFollowedTopicsAreLoading_thenShowLoading() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestUiState.collect() } val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestsUiState.collect() }
userDataRepository.setFollowedTopicIds(emptySet()) userDataRepository.setFollowedTopicIds(emptySet())
assertEquals(InterestsUiState.Loading, viewModel.interestUiState.value) assertEquals(InterestsUiState.Loading, viewModel.interestsUiState.value)
collectJob.cancel() collectJob.cancel()
} }
@Test @Test
fun uiState_whenFollowingNewTopic_thenShowUpdatedTopics() = runTest { fun uiState_whenFollowingNewTopic_thenShowUpdatedTopics() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestUiState.collect() } val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestsUiState.collect() }
val toggleTopicId = testOutputTopics[1].topic.id val toggleTopicId = testOutputTopics[1].topic.id
topicsRepository.sendTopics(testInputTopics.map { it.topic }) topicsRepository.sendTopics(testInputTopics.map { it.topic })
@ -101,7 +101,7 @@ class InterestsViewModelTest {
assertEquals( assertEquals(
false, false,
(viewModel.interestUiState.value as InterestsUiState.Interests) (viewModel.interestsUiState.value as InterestsUiState.Interests)
.topics.first { it.topic.id == toggleTopicId }.isFollowed, .topics.first { it.topic.id == toggleTopicId }.isFollowed,
) )
@ -112,7 +112,7 @@ class InterestsViewModelTest {
assertEquals( assertEquals(
InterestsUiState.Interests(topics = testOutputTopics, selectedTopicId = selectedTopidId), InterestsUiState.Interests(topics = testOutputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value, viewModel.interestsUiState.value,
) )
collectJob.cancel() collectJob.cancel()
@ -120,7 +120,7 @@ class InterestsViewModelTest {
@Test @Test
fun uiState_whenUnfollowingTopics_thenShowUpdatedTopics() = runTest { fun uiState_whenUnfollowingTopics_thenShowUpdatedTopics() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestUiState.collect() } val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestsUiState.collect() }
val toggleTopicId = testOutputTopics[1].topic.id val toggleTopicId = testOutputTopics[1].topic.id
@ -131,7 +131,7 @@ class InterestsViewModelTest {
assertEquals( assertEquals(
true, true,
(viewModel.interestUiState.value as InterestsUiState.Interests) (viewModel.interestsUiState.value as InterestsUiState.Interests)
.topics.first { it.topic.id == toggleTopicId }.isFollowed, .topics.first { it.topic.id == toggleTopicId }.isFollowed,
) )
@ -142,7 +142,7 @@ class InterestsViewModelTest {
assertEquals( assertEquals(
InterestsUiState.Interests(topics = testInputTopics, selectedTopicId = selectedTopidId), InterestsUiState.Interests(topics = testInputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value, viewModel.interestsUiState.value,
) )
collectJob.cancel() collectJob.cancel()

Loading…
Cancel
Save