|
|
@ -19,7 +19,6 @@ package com.google.samples.apps.nowinandroid.feature.search
|
|
|
|
import androidx.lifecycle.SavedStateHandle
|
|
|
|
import androidx.lifecycle.SavedStateHandle
|
|
|
|
import com.google.samples.apps.nowinandroid.core.analytics.NoOpAnalyticsHelper
|
|
|
|
import com.google.samples.apps.nowinandroid.core.analytics.NoOpAnalyticsHelper
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetRecentSearchQueriesUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetRecentSearchQueriesUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetSearchContentsCountUseCase
|
|
|
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetSearchContentsUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.domain.GetSearchContentsUseCase
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.data.newsResourcesTestData
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.data.newsResourcesTestData
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.data.topicsTestData
|
|
|
|
import com.google.samples.apps.nowinandroid.core.testing.data.topicsTestData
|
|
|
@ -59,15 +58,14 @@ class SearchViewModelTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
private val recentSearchRepository = TestRecentSearchRepository()
|
|
|
|
private val recentSearchRepository = TestRecentSearchRepository()
|
|
|
|
private val getRecentQueryUseCase = GetRecentSearchQueriesUseCase(recentSearchRepository)
|
|
|
|
private val getRecentQueryUseCase = GetRecentSearchQueriesUseCase(recentSearchRepository)
|
|
|
|
private val getSearchContentsCountUseCase = GetSearchContentsCountUseCase(searchContentsRepository)
|
|
|
|
|
|
|
|
private lateinit var viewModel: SearchViewModel
|
|
|
|
private lateinit var viewModel: SearchViewModel
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
@Before
|
|
|
|
fun setup() {
|
|
|
|
fun setup() {
|
|
|
|
viewModel = SearchViewModel(
|
|
|
|
viewModel = SearchViewModel(
|
|
|
|
getSearchContentsUseCase = getSearchContentsUseCase,
|
|
|
|
getSearchContentsUseCase = getSearchContentsUseCase,
|
|
|
|
getSearchContentsCountUseCase = getSearchContentsCountUseCase,
|
|
|
|
|
|
|
|
recentSearchQueriesUseCase = getRecentQueryUseCase,
|
|
|
|
recentSearchQueriesUseCase = getRecentQueryUseCase,
|
|
|
|
|
|
|
|
searchContentsRepository = searchContentsRepository,
|
|
|
|
savedStateHandle = SavedStateHandle(),
|
|
|
|
savedStateHandle = SavedStateHandle(),
|
|
|
|
recentSearchRepository = recentSearchRepository,
|
|
|
|
recentSearchRepository = recentSearchRepository,
|
|
|
|
analyticsHelper = NoOpAnalyticsHelper(),
|
|
|
|
analyticsHelper = NoOpAnalyticsHelper(),
|
|
|
@ -84,7 +82,8 @@ class SearchViewModelTest {
|
|
|
|
fun stateIsEmptyQuery_withEmptySearchQuery() = runTest {
|
|
|
|
fun stateIsEmptyQuery_withEmptySearchQuery() = runTest {
|
|
|
|
searchContentsRepository.addNewsResources(newsResourcesTestData)
|
|
|
|
searchContentsRepository.addNewsResources(newsResourcesTestData)
|
|
|
|
searchContentsRepository.addTopics(topicsTestData)
|
|
|
|
searchContentsRepository.addTopics(topicsTestData)
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
val collectJob =
|
|
|
|
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.onSearchQueryChanged("")
|
|
|
|
viewModel.onSearchQueryChanged("")
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +94,8 @@ class SearchViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun emptyResultIsReturned_withNotMatchingQuery() = runTest {
|
|
|
|
fun emptyResultIsReturned_withNotMatchingQuery() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
val collectJob =
|
|
|
|
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.onSearchQueryChanged("XXX")
|
|
|
|
viewModel.onSearchQueryChanged("XXX")
|
|
|
|
searchContentsRepository.addNewsResources(newsResourcesTestData)
|
|
|
|
searchContentsRepository.addNewsResources(newsResourcesTestData)
|
|
|
@ -109,7 +109,8 @@ class SearchViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun recentSearches_verifyUiStateIsSuccess() = runTest {
|
|
|
|
fun recentSearches_verifyUiStateIsSuccess() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.recentSearchQueriesUiState.collect() }
|
|
|
|
val collectJob =
|
|
|
|
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.recentSearchQueriesUiState.collect() }
|
|
|
|
viewModel.onSearchTriggered("kotlin")
|
|
|
|
viewModel.onSearchTriggered("kotlin")
|
|
|
|
|
|
|
|
|
|
|
|
val result = viewModel.recentSearchQueriesUiState.value
|
|
|
|
val result = viewModel.recentSearchQueriesUiState.value
|
|
|
@ -120,7 +121,8 @@ class SearchViewModelTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun searchNotReady_withNoFtsTableEntity() = runTest {
|
|
|
|
fun searchNotReady_withNoFtsTableEntity() = runTest {
|
|
|
|
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
val collectJob =
|
|
|
|
|
|
|
|
launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() }
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.onSearchQueryChanged("")
|
|
|
|
viewModel.onSearchQueryChanged("")
|
|
|
|
|
|
|
|
|
|
|
|