Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
Change-Id: Ie4a782e2c26576098aff87ca164968886821cdcc
  • Loading branch information
mmoczkowski committed May 31, 2023
1 parent 5205f13 commit 96c80f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal fun InterestsRoute(
modifier: Modifier = Modifier,
viewModel: InterestsViewModel = hiltViewModel(),
) {
val interestUiState by viewModel.interestUiState.collectAsStateWithLifecycle()
val interestUiState by viewModel.interestsUiState.collectAsStateWithLifecycle()
val topicUiState by viewModel.topicUiState.collectAsStateWithLifecycle()

Row(modifier = modifier.fillMaxSize()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class InterestsViewModel @Inject constructor(
private val topicId: StateFlow<String?> =
savedStateHandle.getStateFlow(topicIdArg, null)

val interestUiState: StateFlow<InterestsUiState> = combine(
val interestsUiState: StateFlow<InterestsUiState> = combine(
getFollowableTopics(sortBy = TopicSortField.NAME),
topicId,
) { topics, selectedTopicId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ class InterestsViewModelTest {

@Test
fun uiState_whenInitialized_thenShowLoading() = runTest {
assertEquals(InterestsUiState.Loading, viewModel.interestUiState.value)
assertEquals(InterestsUiState.Loading, viewModel.interestsUiState.value)
}

@Test
fun uiState_whenFollowedTopicsAreLoading_thenShowLoading() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestUiState.collect() }
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.interestsUiState.collect() }

userDataRepository.setFollowedTopicIds(emptySet())
assertEquals(InterestsUiState.Loading, viewModel.interestUiState.value)
assertEquals(InterestsUiState.Loading, viewModel.interestsUiState.value)

collectJob.cancel()
}

@Test
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
topicsRepository.sendTopics(testInputTopics.map { it.topic })
userDataRepository.setFollowedTopicIds(setOf(testInputTopics[0].topic.id))

assertEquals(
false,
(viewModel.interestUiState.value as InterestsUiState.Interests)
(viewModel.interestsUiState.value as InterestsUiState.Interests)
.topics.first { it.topic.id == toggleTopicId }.isFollowed,
)

Expand All @@ -112,15 +112,15 @@ class InterestsViewModelTest {

assertEquals(
InterestsUiState.Interests(topics = testOutputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value,
viewModel.interestsUiState.value,
)

collectJob.cancel()
}

@Test
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

Expand All @@ -131,7 +131,7 @@ class InterestsViewModelTest {

assertEquals(
true,
(viewModel.interestUiState.value as InterestsUiState.Interests)
(viewModel.interestsUiState.value as InterestsUiState.Interests)
.topics.first { it.topic.id == toggleTopicId }.isFollowed,
)

Expand All @@ -142,7 +142,7 @@ class InterestsViewModelTest {

assertEquals(
InterestsUiState.Interests(topics = testInputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value,
viewModel.interestsUiState.value,
)

collectJob.cancel()
Expand Down

0 comments on commit 96c80f2

Please sign in to comment.