|
|
@ -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
|
|
|
@ -60,7 +59,6 @@ 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
|
|
|
|
|
|
|
|
|
|
|
@ -68,8 +66,8 @@ class SearchViewModelTest {
|
|
|
|
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,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
|
userDataRepository = userDataRepository,
|
|
|
@ -87,7 +85,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("")
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +97,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)
|
|
|
@ -112,7 +112,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
|
|
|
@ -123,7 +124,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("")
|
|
|
|
|
|
|
|
|
|
|
|