|
|
|
@ -28,6 +28,7 @@ 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.TestNewsRepository
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule
|
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
|
import kotlinx.coroutines.test.advanceUntilIdle
|
|
|
|
@ -42,6 +43,7 @@ class ForYouViewModelTest {
|
|
|
|
|
@get:Rule
|
|
|
|
|
val dispatcherRule = TestDispatcherRule()
|
|
|
|
|
|
|
|
|
|
private val userDataRepository = TestUserDataRepository()
|
|
|
|
|
private val authorsRepository = TestAuthorsRepository()
|
|
|
|
|
private val topicsRepository = TestTopicsRepository()
|
|
|
|
|
private val newsRepository = TestNewsRepository()
|
|
|
|
@ -50,6 +52,7 @@ class ForYouViewModelTest {
|
|
|
|
|
@Before
|
|
|
|
|
fun setup() {
|
|
|
|
|
viewModel = ForYouViewModel(
|
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
|
authorsRepository = authorsRepository,
|
|
|
|
|
topicsRepository = topicsRepository,
|
|
|
|
|
newsRepository = newsRepository,
|
|
|
|
@ -125,7 +128,7 @@ class ForYouViewModelTest {
|
|
|
|
|
),
|
|
|
|
|
awaitItem()
|
|
|
|
|
)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -139,7 +142,7 @@ class ForYouViewModelTest {
|
|
|
|
|
),
|
|
|
|
|
awaitItem()
|
|
|
|
|
)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -149,9 +152,9 @@ class ForYouViewModelTest {
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
assertEquals(
|
|
|
|
@ -244,8 +247,8 @@ class ForYouViewModelTest {
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
@ -340,9 +343,9 @@ class ForYouViewModelTest {
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(setOf("0", "1"))
|
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf("0", "1"))
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
ForYouUiState(
|
|
|
|
@ -380,9 +383,9 @@ class ForYouViewModelTest {
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(setOf("0", "1"))
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(setOf("0", "1"))
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
ForYouUiState(
|
|
|
|
@ -418,9 +421,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
@ -686,9 +689,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
@ -954,9 +957,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateTopicSelection("1", isChecked = true)
|
|
|
|
|
viewModel.updateTopicSelection("1", isChecked = false)
|
|
|
|
@ -1051,9 +1054,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateAuthorSelection("1", isChecked = true)
|
|
|
|
|
viewModel.updateAuthorSelection("1", isChecked = false)
|
|
|
|
@ -1148,9 +1151,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateTopicSelection("1", isChecked = true)
|
|
|
|
|
|
|
|
|
@ -1179,8 +1182,8 @@ class ForYouViewModelTest {
|
|
|
|
|
),
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
)
|
|
|
|
|
assertEquals(setOf("1"), topicsRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(emptySet<Int>(), authorsRepository.getCurrentFollowedAuthors())
|
|
|
|
|
assertEquals(setOf("1"), userDataRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(emptySet<Int>(), userDataRepository.getCurrentFollowedAuthors())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1189,9 +1192,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateAuthorSelection("0", isChecked = true)
|
|
|
|
|
|
|
|
|
@ -1216,8 +1219,8 @@ class ForYouViewModelTest {
|
|
|
|
|
),
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
)
|
|
|
|
|
assertEquals(emptySet<Int>(), topicsRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(setOf("0"), authorsRepository.getCurrentFollowedAuthors())
|
|
|
|
|
assertEquals(emptySet<Int>(), userDataRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(setOf("0"), userDataRepository.getCurrentFollowedAuthors())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1226,9 +1229,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateAuthorSelection("1", isChecked = true)
|
|
|
|
|
viewModel.updateTopicSelection("1", isChecked = true)
|
|
|
|
@ -1258,8 +1261,8 @@ class ForYouViewModelTest {
|
|
|
|
|
),
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
)
|
|
|
|
|
assertEquals(setOf("1"), topicsRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(setOf("1"), authorsRepository.getCurrentFollowedAuthors())
|
|
|
|
|
assertEquals(setOf("1"), userDataRepository.getCurrentFollowedTopics())
|
|
|
|
|
assertEquals(setOf("1"), userDataRepository.getCurrentFollowedAuthors())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1268,9 +1271,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateTopicSelection("1", isChecked = true)
|
|
|
|
|
viewModel.saveFollowedInterests()
|
|
|
|
@ -1278,7 +1281,7 @@ class ForYouViewModelTest {
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
assertEquals(
|
|
|
|
@ -1371,9 +1374,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedTopicIds(emptySet())
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateAuthorSelection("1", isChecked = true)
|
|
|
|
|
viewModel.saveFollowedInterests()
|
|
|
|
@ -1381,7 +1384,7 @@ class ForYouViewModelTest {
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
expectMostRecentItem()
|
|
|
|
|
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(emptySet())
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
assertEquals(
|
|
|
|
@ -1473,9 +1476,9 @@ class ForYouViewModelTest {
|
|
|
|
|
viewModel.uiState
|
|
|
|
|
.test {
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
topicsRepository.setFollowedTopicIds(setOf("1"))
|
|
|
|
|
userDataRepository.setFollowedTopicIds(setOf("1"))
|
|
|
|
|
authorsRepository.sendAuthors(sampleAuthors)
|
|
|
|
|
authorsRepository.setFollowedAuthorIds(setOf("1"))
|
|
|
|
|
userDataRepository.setFollowedAuthorIds(setOf("1"))
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
|
viewModel.updateNewsResourceSaved("2", true)
|
|
|
|
|
|
|
|
|
|