Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty search text is added in recent searches problem fix. #1223

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
97686cb
Add if state to prevent blank query.
Jaehwa-Noh Feb 21, 2024
aa42b48
Create test emptySearchText_NotAddToRecentSearches
Jaehwa-Noh Feb 21, 2024
d1582a0
Apply early return.
Jaehwa-Noh Feb 21, 2024
cd6224c
assertEquals to assertNull.
Jaehwa-Noh Feb 21, 2024
9fb4c6a
Import org.junit.Assert.assertNull
Jaehwa-Noh Feb 21, 2024
ad2c782
Change org.junit.Assert.assertNull to kotlin.test.assertNull.
Jaehwa-Noh Feb 21, 2024
1976c4c
Add 'or' to prevent search when query is blank.
Jaehwa-Noh Feb 22, 2024
b0e1212
Create stateIsEmptyQuery_withThreeWhiteSpacesSearchQuery test.
Jaehwa-Noh Feb 22, 2024
983c6fe
Add UI logic to prevent blank text search in SearchScreen.
Jaehwa-Noh Feb 22, 2024
324b693
Apply trim at query to remove whitespace.
Jaehwa-Noh Feb 23, 2024
f1a55cc
Create test stateIsEmptyQuery_withThreeWhiteSpacesAndOneLetterSearchQ…
Jaehwa-Noh Feb 23, 2024
54c92c2
Merge branch 'android:main' into main
Jaehwa-Noh Feb 24, 2024
8528ab1
Merge branch 'android:main' into main
Jaehwa-Noh Feb 28, 2024
c8a4088
Merge branch 'android:main' into main
Jaehwa-Noh Mar 4, 2024
bc59112
Update feature/search/src/test/kotlin/com/google/samples/apps/nowinan…
Jaehwa-Noh Mar 5, 2024
1fd341d
Change name to searchTextWithThreeSpaces_isEmptyQuery()
Jaehwa-Noh Mar 5, 2024
e4c1765
Change name to searchTextWithThreeWhiteSpacesAndOneCharacter_isEmptyQ…
Jaehwa-Noh Mar 5, 2024
39a137f
Revert "Change name to searchTextWithThreeWhiteSpacesAndOneCharacter_…
Jaehwa-Noh Mar 5, 2024
8664528
Change name to searchTextWithThreeSpacesAndOneLetter_isEmptyQuery
Jaehwa-Noh Mar 5, 2024
4d7b7e0
Merge branch 'android:main' into main
Jaehwa-Noh Mar 6, 2024
ef49f44
Merge branch 'android:main' into main
Jaehwa-Noh Mar 8, 2024
a2e3e53
Merge branch 'android:main' into main
Jaehwa-Noh Mar 11, 2024
8c7441f
Merge branch 'android:main' into main
Jaehwa-Noh Mar 14, 2024
ccbd9b3
Merge branch 'main' into main
Jaehwa-Noh Mar 15, 2024
f820cf2
Add end curly bracket.
Jaehwa-Noh Mar 15, 2024
8db6969
Merge branch 'android:main' into main
Jaehwa-Noh Mar 18, 2024
c80af8f
Merge branch 'android:main' into main
Jaehwa-Noh Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ class SearchViewModel @Inject constructor(
* search query in the search text field, defining this method.
*/
fun onSearchTriggered(query: String) {
viewModelScope.launch {
recentSearchRepository.insertOrReplaceRecentSearch(searchQuery = query)
if (query.isNotBlank()) {
viewModelScope.launch {
recentSearchRepository.insertOrReplaceRecentSearch(searchQuery = query)
}
analyticsHelper.logEventSearchTriggered(query = query)
}
analyticsHelper.logEventSearchTriggered(query = query)
}
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved

fun clearRecentSearches() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.google.samples.apps.nowinandroid.feature.search.SearchResultUiState.E
import com.google.samples.apps.nowinandroid.feature.search.SearchResultUiState.Loading
import com.google.samples.apps.nowinandroid.feature.search.SearchResultUiState.SearchNotReady
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -128,4 +129,15 @@ class SearchViewModelTest {

collectJob.cancel()
}

@Test
fun emptySearchText_NotAddToRecentSearches() = runTest {
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved
viewModel.onSearchTriggered("")

val recentSearchQueriesStream = getRecentQueryUseCase()
val recentSearchQueries = recentSearchQueriesStream.first()
val recentSearchQuery = recentSearchQueries.firstOrNull()

assertEquals(null, recentSearchQuery)
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved
}
}