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,
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()) {

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

@ -78,22 +78,22 @@ 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 })
@ -101,7 +101,7 @@ class InterestsViewModelTest {
assertEquals(
false,
(viewModel.interestUiState.value as InterestsUiState.Interests)
(viewModel.interestsUiState.value as InterestsUiState.Interests)
.topics.first { it.topic.id == toggleTopicId }.isFollowed,
)
@ -112,7 +112,7 @@ class InterestsViewModelTest {
assertEquals(
InterestsUiState.Interests(topics = testOutputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value,
viewModel.interestsUiState.value,
)
collectJob.cancel()
@ -120,7 +120,7 @@ class InterestsViewModelTest {
@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
@ -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,
)
@ -142,7 +142,7 @@ class InterestsViewModelTest {
assertEquals(
InterestsUiState.Interests(topics = testInputTopics, selectedTopicId = selectedTopidId),
viewModel.interestUiState.value,
viewModel.interestsUiState.value,
)
collectJob.cancel()

Loading…
Cancel
Save