|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.topic
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.SavedStateHandle
|
|
|
|
|
import androidx.navigation.testing.invoke
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
@ -25,6 +26,7 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepo
|
|
|
|
|
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.MainDispatcherRule
|
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicRoute
|
|
|
|
|
import kotlinx.coroutines.flow.collect
|
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
|
import kotlinx.coroutines.flow.first
|
|
|
|
@ -35,13 +37,22 @@ import kotlinx.datetime.Instant
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.robolectric.RobolectricTestRunner
|
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
|
import kotlin.test.assertIs
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To learn more about how this test handles Flows created with stateIn, see
|
|
|
|
|
* https://developer.android.com/kotlin/flow/test#statein
|
|
|
|
|
*
|
|
|
|
|
* These tests use Robolectric because the subject under test (the ViewModel) uses
|
|
|
|
|
* `SavedStateHandle.toRoute` which has a dependency on `android.os.Bundle`.
|
|
|
|
|
*
|
|
|
|
|
* TODO: Remove Robolectric if/when AndroidX Navigation API is updated to remove Android dependency.
|
|
|
|
|
* * See b/340966212.
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(RobolectricTestRunner::class)
|
|
|
|
|
class TopicViewModelTest {
|
|
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
@ -59,8 +70,9 @@ class TopicViewModelTest {
|
|
|
|
|
@Before
|
|
|
|
|
fun setup() {
|
|
|
|
|
viewModel = TopicViewModel(
|
|
|
|
|
// TODO: Figure out how to supply the correct dependency TopicDestination(id = testInputTopics[0].topic.id)
|
|
|
|
|
savedStateHandle = SavedStateHandle(mapOf("id" to testInputTopics[0].topic.id)),
|
|
|
|
|
savedStateHandle = SavedStateHandle(
|
|
|
|
|
route = TopicRoute(id = testInputTopics[0].topic.id),
|
|
|
|
|
),
|
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
|
topicsRepository = topicsRepository,
|
|
|
|
|
userNewsResourceRepository = userNewsResourceRepository,
|
|
|
|
|