|
|
@ -17,6 +17,8 @@
|
|
|
|
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.analytics.AnalyticsEvent
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent.Param
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
|
|
|
@ -30,6 +32,7 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRe
|
|
|
|
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.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.TestAnalyticsHelper
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncManager
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncManager
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.LINKED_NEWS_RESOURCE_ID
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.LINKED_NEWS_RESOURCE_ID
|
|
|
@ -44,6 +47,7 @@ import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
import kotlin.test.assertNull
|
|
|
|
import kotlin.test.assertNull
|
|
|
|
|
|
|
|
import kotlin.test.assertTrue
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* To learn more about how this test handles Flows created with stateIn, see
|
|
|
|
* To learn more about how this test handles Flows created with stateIn, see
|
|
|
@ -54,6 +58,7 @@ class ForYouViewModelTest {
|
|
|
|
val mainDispatcherRule = MainDispatcherRule()
|
|
|
|
val mainDispatcherRule = MainDispatcherRule()
|
|
|
|
|
|
|
|
|
|
|
|
private val syncManager = TestSyncManager()
|
|
|
|
private val syncManager = TestSyncManager()
|
|
|
|
|
|
|
|
private val analyticsHelper = TestAnalyticsHelper()
|
|
|
|
private val userDataRepository = TestUserDataRepository()
|
|
|
|
private val userDataRepository = TestUserDataRepository()
|
|
|
|
private val topicsRepository = TestTopicsRepository()
|
|
|
|
private val topicsRepository = TestTopicsRepository()
|
|
|
|
private val newsRepository = TestNewsRepository()
|
|
|
|
private val newsRepository = TestNewsRepository()
|
|
|
@ -74,6 +79,7 @@ class ForYouViewModelTest {
|
|
|
|
viewModel = ForYouViewModel(
|
|
|
|
viewModel = ForYouViewModel(
|
|
|
|
syncManager = syncManager,
|
|
|
|
syncManager = syncManager,
|
|
|
|
savedStateHandle = savedStateHandle,
|
|
|
|
savedStateHandle = savedStateHandle,
|
|
|
|
|
|
|
|
analyticsHelper = analyticsHelper,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
getFollowableTopics = getFollowableTopicsUseCase,
|
|
|
|
getFollowableTopics = getFollowableTopicsUseCase,
|
|
|
@ -253,7 +259,6 @@ class ForYouViewModelTest {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
NewsFeedUiState.Success(
|
|
|
|
feed = emptyList(),
|
|
|
|
feed = emptyList(),
|
|
|
|
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
viewModel.feedState.value,
|
|
|
|
viewModel.feedState.value,
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -484,6 +489,20 @@ class ForYouViewModelTest {
|
|
|
|
viewModel.deepLinkedNewsResource.value,
|
|
|
|
viewModel.deepLinkedNewsResource.value,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(
|
|
|
|
|
|
|
|
analyticsHelper.hasLogged(
|
|
|
|
|
|
|
|
AnalyticsEvent(
|
|
|
|
|
|
|
|
type = "news_deep_link_opened",
|
|
|
|
|
|
|
|
extras = listOf(
|
|
|
|
|
|
|
|
Param(
|
|
|
|
|
|
|
|
key = LINKED_NEWS_RESOURCE_ID,
|
|
|
|
|
|
|
|
value = sampleNewsResources.first().id,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
collectJob.cancel()
|
|
|
|
collectJob.cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|