|
|
@ -17,12 +17,15 @@
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.foryou
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.foryou
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.SavedStateHandle
|
|
|
|
import androidx.lifecycle.SavedStateHandle
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsStreamUseCase
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetSaveableNewsResourcesStreamUseCase
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetSortedFollowableAuthorsStreamUseCase
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableAuthor
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Author
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Author
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthor
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.SaveableNewsResource
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestAuthorsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository
|
|
|
@ -57,6 +60,17 @@ class ForYouViewModelTest {
|
|
|
|
private val authorsRepository = TestAuthorsRepository()
|
|
|
|
private val authorsRepository = TestAuthorsRepository()
|
|
|
|
private val topicsRepository = TestTopicsRepository()
|
|
|
|
private val topicsRepository = TestTopicsRepository()
|
|
|
|
private val newsRepository = TestNewsRepository()
|
|
|
|
private val newsRepository = TestNewsRepository()
|
|
|
|
|
|
|
|
private val getSaveableNewsResourcesStreamUseCase = GetSaveableNewsResourcesStreamUseCase(
|
|
|
|
|
|
|
|
newsRepository = newsRepository,
|
|
|
|
|
|
|
|
userDataRepository = userDataRepository
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
private val getSortedFollowableAuthorsStream = GetSortedFollowableAuthorsStreamUseCase(
|
|
|
|
|
|
|
|
authorsRepository = authorsRepository
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
private val getFollowableTopicsStreamUseCase = GetFollowableTopicsStreamUseCase(
|
|
|
|
|
|
|
|
topicsRepository = topicsRepository,
|
|
|
|
|
|
|
|
userDataRepository = userDataRepository
|
|
|
|
|
|
|
|
)
|
|
|
|
private lateinit var viewModel: ForYouViewModel
|
|
|
|
private lateinit var viewModel: ForYouViewModel
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
@Before
|
|
|
@ -65,9 +79,9 @@ class ForYouViewModelTest {
|
|
|
|
networkMonitor = networkMonitor,
|
|
|
|
networkMonitor = networkMonitor,
|
|
|
|
syncStatusMonitor = syncStatusMonitor,
|
|
|
|
syncStatusMonitor = syncStatusMonitor,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
authorsRepository = authorsRepository,
|
|
|
|
getSaveableNewsResourcesStream = getSaveableNewsResourcesStreamUseCase,
|
|
|
|
topicsRepository = topicsRepository,
|
|
|
|
getSortedFollowableAuthorsStream = getSortedFollowableAuthorsStream,
|
|
|
|
newsRepository = newsRepository,
|
|
|
|
getFollowableTopicsStream = getFollowableTopicsStreamUseCase,
|
|
|
|
savedStateHandle = SavedStateHandle()
|
|
|
|
savedStateHandle = SavedStateHandle()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,7 +90,7 @@ class ForYouViewModelTest {
|
|
|
|
fun stateIsInitiallyLoading() = runTest {
|
|
|
|
fun stateIsInitiallyLoading() = runTest {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,14 +98,14 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsLoadingWhenFollowedTopicsAreLoading() = runTest {
|
|
|
|
fun stateIsLoadingWhenFollowedTopicsAreLoading() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
|
|
|
|
|
|
|
@ -117,14 +131,14 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsLoadingWhenFollowedAuthorsAreLoading() = runTest {
|
|
|
|
fun stateIsLoadingWhenFollowedAuthorsAreLoading() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
|
|
|
|
|
|
|
@ -135,14 +149,14 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsLoadingWhenTopicsAreLoading() = runTest {
|
|
|
|
fun stateIsLoadingWhenTopicsAreLoading() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value)
|
|
|
|
|
|
|
|
|
|
|
@ -153,14 +167,14 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsLoadingWhenAuthorsAreLoading() = runTest {
|
|
|
|
fun stateIsLoadingWhenAuthorsAreLoading() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
ForYouInterestsSelectionUiState.Loading,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value)
|
|
|
|
|
|
|
|
|
|
|
@ -171,7 +185,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsInterestsSelectionWhenNewsResourcesAreLoading() = runTest {
|
|
|
|
fun stateIsInterestsSelectionWhenNewsResourcesAreLoading() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -252,7 +266,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -268,7 +282,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsInterestsSelectionAfterLoadingEmptyFollowedTopicsAndAuthors() = runTest {
|
|
|
|
fun stateIsInterestsSelectionAfterLoadingEmptyFollowedTopicsAndAuthors() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -350,7 +364,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -367,7 +381,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsWithoutInterestsSelectionAfterLoadingFollowedTopics() = runTest {
|
|
|
|
fun stateIsWithoutInterestsSelectionAfterLoadingFollowedTopics() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
@ -377,7 +391,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value)
|
|
|
|
|
|
|
|
|
|
|
@ -385,7 +399,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -407,7 +421,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun stateIsWithoutInterestsSelectionAfterLoadingFollowedAuthors() = runTest {
|
|
|
|
fun stateIsWithoutInterestsSelectionAfterLoadingFollowedAuthors() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
@ -417,7 +431,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Loading,
|
|
|
|
NewsFeedUiState.Loading,
|
|
|
@ -428,7 +442,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -449,7 +463,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterSelectingTopic() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterSelectingTopic() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -531,7 +545,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -615,7 +629,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -640,7 +654,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterSelectingAuthor() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterSelectingAuthor() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -722,7 +736,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -806,7 +820,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -831,7 +845,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterUnselectingTopic() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterUnselectingTopic() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -916,7 +930,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -932,7 +946,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterUnselectingAuthor() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterUnselectingAuthor() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1017,7 +1031,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1033,7 +1047,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterSavingTopicsOnly() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterSavingTopicsOnly() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1047,7 +1061,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1074,7 +1088,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterSavingAuthorsOnly() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterSavingAuthorsOnly() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1088,7 +1102,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1111,7 +1125,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionUpdatesAfterSavingAuthorsAndTopics() = runTest {
|
|
|
|
fun topicSelectionUpdatesAfterSavingAuthorsAndTopics() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1126,7 +1140,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1153,7 +1167,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun topicSelectionIsResetAfterSavingTopicsAndRemovingThem() = runTest {
|
|
|
|
fun topicSelectionIsResetAfterSavingTopicsAndRemovingThem() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1239,7 +1253,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1255,7 +1269,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun authorSelectionIsResetAfterSavingAuthorsAndRemovingThem() = runTest {
|
|
|
|
fun authorSelectionIsResetAfterSavingAuthorsAndRemovingThem() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1341,7 +1355,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
@ -1357,7 +1371,7 @@ class ForYouViewModelTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest {
|
|
|
|
fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest {
|
|
|
|
val collectJob1 =
|
|
|
|
val collectJob1 =
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionState.collect() }
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.interestsSelectionUiState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
@ -1369,7 +1383,7 @@ class ForYouViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
ForYouInterestsSelectionUiState.NoInterestsSelection,
|
|
|
|
viewModel.interestsSelectionState.value
|
|
|
|
viewModel.interestsSelectionUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|