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