|
|
@ -20,12 +20,14 @@ import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCa
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetUserNewsResourcesUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetUserNewsResourcesUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.model.mapToUserNewsResources
|
|
|
|
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.Topic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
|
|
|
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.repository.TestUserDataRepository
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.repository.emptyUserData
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncStatusMonitor
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncStatusMonitor
|
|
|
@ -265,7 +267,8 @@ class ForYouViewModelTest {
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
|
|
|
|
|
|
|
|
val followedTopicIds = setOf("0", "1")
|
|
|
|
val followedTopicIds = setOf("0", "1")
|
|
|
|
userDataRepository.setFollowedTopicIds(followedTopicIds)
|
|
|
|
val userData = emptyUserData.copy(followedTopics = followedTopicIds)
|
|
|
|
|
|
|
|
userDataRepository.setUserData(userData)
|
|
|
|
viewModel.dismissOnboarding()
|
|
|
|
viewModel.dismissOnboarding()
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
@ -282,25 +285,7 @@ class ForYouViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
feed =
|
|
|
|
feed = sampleNewsResources.mapToUserNewsResources(userData)
|
|
|
|
sampleNewsResources.map {
|
|
|
|
|
|
|
|
UserNewsResource(
|
|
|
|
|
|
|
|
id = it.id,
|
|
|
|
|
|
|
|
title = it.title,
|
|
|
|
|
|
|
|
content = it.content,
|
|
|
|
|
|
|
|
url = it.url,
|
|
|
|
|
|
|
|
headerImageUrl = it.headerImageUrl,
|
|
|
|
|
|
|
|
publishDate = it.publishDate,
|
|
|
|
|
|
|
|
type = it.type,
|
|
|
|
|
|
|
|
followableTopics = it.topics.map { topic ->
|
|
|
|
|
|
|
|
FollowableTopic(
|
|
|
|
|
|
|
|
topic = topic,
|
|
|
|
|
|
|
|
isFollowed = followedTopicIds.contains(topic.id)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isSaved = false
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.feedState.value
|
|
|
|
viewModel.feedState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -345,41 +330,14 @@ class ForYouViewModelTest {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.onboardingUiState.value
|
|
|
|
viewModel.onboardingUiState.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val userData = emptyUserData.copy(followedTopics = setOf(followedTopicId))
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
feed = listOf(
|
|
|
|
feed = listOf(
|
|
|
|
UserNewsResource(
|
|
|
|
UserNewsResource(sampleNewsResources[1], userData),
|
|
|
|
id = sampleNewsResources[1].id,
|
|
|
|
UserNewsResource(sampleNewsResources[2], userData),
|
|
|
|
title = sampleNewsResources[1].title,
|
|
|
|
|
|
|
|
content = sampleNewsResources[1].content,
|
|
|
|
|
|
|
|
url = sampleNewsResources[1].url,
|
|
|
|
|
|
|
|
headerImageUrl = sampleNewsResources[1].headerImageUrl,
|
|
|
|
|
|
|
|
publishDate = sampleNewsResources[1].publishDate,
|
|
|
|
|
|
|
|
type = sampleNewsResources[1].type,
|
|
|
|
|
|
|
|
followableTopics = sampleNewsResources[1].topics.map { topic ->
|
|
|
|
|
|
|
|
FollowableTopic(
|
|
|
|
|
|
|
|
topic = topic,
|
|
|
|
|
|
|
|
isFollowed = topic.id == followedTopicId
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isSaved = false
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
UserNewsResource(
|
|
|
|
|
|
|
|
id = sampleNewsResources[2].id,
|
|
|
|
|
|
|
|
title = sampleNewsResources[2].title,
|
|
|
|
|
|
|
|
content = sampleNewsResources[2].content,
|
|
|
|
|
|
|
|
url = sampleNewsResources[2].url,
|
|
|
|
|
|
|
|
headerImageUrl = sampleNewsResources[2].headerImageUrl,
|
|
|
|
|
|
|
|
publishDate = sampleNewsResources[2].publishDate,
|
|
|
|
|
|
|
|
type = sampleNewsResources[2].type,
|
|
|
|
|
|
|
|
followableTopics = sampleNewsResources[2].topics.map { topic ->
|
|
|
|
|
|
|
|
FollowableTopic(
|
|
|
|
|
|
|
|
topic = topic,
|
|
|
|
|
|
|
|
isFollowed = topic.id == followedTopicId
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isSaved = false
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.feedState.value
|
|
|
|
viewModel.feedState.value
|
|
|
@ -460,12 +418,24 @@ class ForYouViewModelTest {
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
val followedTopicIds = setOf("1")
|
|
|
|
val followedTopicIds = setOf("1")
|
|
|
|
|
|
|
|
val userData = emptyUserData.copy(
|
|
|
|
|
|
|
|
followedTopics = followedTopicIds,
|
|
|
|
|
|
|
|
shouldHideOnboarding = true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
topicsRepository.sendTopics(sampleTopics)
|
|
|
|
userDataRepository.setFollowedTopicIds(followedTopicIds)
|
|
|
|
userDataRepository.setUserData(userData)
|
|
|
|
userDataRepository.setShouldHideOnboarding(true)
|
|
|
|
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
newsRepository.sendNewsResources(sampleNewsResources)
|
|
|
|
viewModel.updateNewsResourceSaved("2", true)
|
|
|
|
|
|
|
|
|
|
|
|
val bookmarkedNewsResourceId = "2"
|
|
|
|
|
|
|
|
viewModel.updateNewsResourceSaved(
|
|
|
|
|
|
|
|
newsResourceId = bookmarkedNewsResourceId,
|
|
|
|
|
|
|
|
isChecked = true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val userDataExpected = userData.copy(
|
|
|
|
|
|
|
|
bookmarkedNewsResources = setOf(bookmarkedNewsResourceId)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
OnboardingUiState.NotShown,
|
|
|
|
OnboardingUiState.NotShown,
|
|
|
@ -474,38 +444,8 @@ class ForYouViewModelTest {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
feed = listOf(
|
|
|
|
feed = listOf(
|
|
|
|
UserNewsResource(
|
|
|
|
UserNewsResource(newsResource = sampleNewsResources[1], userDataExpected),
|
|
|
|
id = sampleNewsResources[1].id,
|
|
|
|
UserNewsResource(newsResource = sampleNewsResources[2], userDataExpected)
|
|
|
|
title = sampleNewsResources[1].title,
|
|
|
|
|
|
|
|
content = sampleNewsResources[1].content,
|
|
|
|
|
|
|
|
url = sampleNewsResources[1].url,
|
|
|
|
|
|
|
|
headerImageUrl = sampleNewsResources[1].headerImageUrl,
|
|
|
|
|
|
|
|
publishDate = sampleNewsResources[1].publishDate,
|
|
|
|
|
|
|
|
type = sampleNewsResources[1].type,
|
|
|
|
|
|
|
|
followableTopics = sampleNewsResources[1].topics.map { topic ->
|
|
|
|
|
|
|
|
FollowableTopic(
|
|
|
|
|
|
|
|
topic = topic,
|
|
|
|
|
|
|
|
isFollowed = followedTopicIds.contains(topic.id)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isSaved = true
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
UserNewsResource(
|
|
|
|
|
|
|
|
id = sampleNewsResources[2].id,
|
|
|
|
|
|
|
|
title = sampleNewsResources[2].title,
|
|
|
|
|
|
|
|
content = sampleNewsResources[2].content,
|
|
|
|
|
|
|
|
url = sampleNewsResources[2].url,
|
|
|
|
|
|
|
|
headerImageUrl = sampleNewsResources[2].headerImageUrl,
|
|
|
|
|
|
|
|
publishDate = sampleNewsResources[2].publishDate,
|
|
|
|
|
|
|
|
type = sampleNewsResources[2].type,
|
|
|
|
|
|
|
|
followableTopics = sampleNewsResources[2].topics.map { topic ->
|
|
|
|
|
|
|
|
FollowableTopic(
|
|
|
|
|
|
|
|
topic = topic,
|
|
|
|
|
|
|
|
isFollowed = followedTopicIds.contains(topic.id)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isSaved = false
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.feedState.value
|
|
|
|
viewModel.feedState.value
|
|
|
|