@ -56,12 +56,14 @@ class SearchFragmentStoreTest {
}
@Test
fun `createInitialSearchFragmentState with no tab `( ) {
fun `createInitialSearchFragmentState with no tab in normal browsing mode `( ) {
activity . browsingModeManager . mode = BrowsingMode . Normal
every { components . core . store . state } returns BrowserState ( )
every { settings . shouldShowSearchShortcuts } returns true
every { settings . showUnifiedSearchFeature } returns true
every { settings . shouldShowHistorySuggestions } returns true
every { settings . shouldShowSearchSuggestions } returns true
every { settings . shouldShowSearchSuggestionsInPrivate } returns false
every { settings . showSponsoredSuggestions } returns true
every { settings . showNonSponsoredSuggestions } returns true
@ -73,7 +75,7 @@ class SearchFragmentStoreTest {
searchEngineSource = SearchEngineSource . None ,
defaultEngine = null ,
showSearchShortcutsSetting = true ,
showSearchSuggestions = fals e,
showSearchSuggestions = tru e,
showSearchSuggestionsHint = false ,
showSearchShortcuts = false ,
areShortcutsAvailable = false ,
@ -119,6 +121,58 @@ class SearchFragmentStoreTest {
}
}
@Test
fun `createInitialSearchFragmentState with no tab in private browsing mode` ( ) {
activity . browsingModeManager . mode = BrowsingMode . Private
every { components . core . store . state } returns BrowserState ( )
every { settings . shouldShowSearchShortcuts } returns true
every { settings . showUnifiedSearchFeature } returns true
every { settings . shouldShowHistorySuggestions } returns true
every { settings . shouldShowSearchSuggestions } returns true
every { settings . shouldShowSearchSuggestionsInPrivate } returns false
every { settings . showSponsoredSuggestions } returns true
every { settings . showNonSponsoredSuggestions } returns true
val expected = SearchFragmentState (
query = " " ,
url = " " ,
searchTerms = " " ,
searchEngineSource = SearchEngineSource . None ,
defaultEngine = null ,
showSearchShortcutsSetting = true ,
showSearchSuggestions = false ,
showSearchSuggestionsHint = false ,
showSearchShortcuts = false ,
areShortcutsAvailable = false ,
showClipboardSuggestions = false ,
showSearchTermHistory = true ,
showHistorySuggestionsForCurrentEngine = false ,
showAllHistorySuggestions = true ,
showBookmarksSuggestionsForCurrentEngine = false ,
showAllBookmarkSuggestions = false ,
showSyncedTabsSuggestionsForCurrentEngine = false ,
showAllSyncedTabsSuggestions = false ,
showSessionSuggestionsForCurrentEngine = false ,
showAllSessionSuggestions = true ,
showSponsoredSuggestions = false ,
showNonSponsoredSuggestions = false ,
tabId = null ,
pastedText = " pastedText " ,
searchAccessPoint = MetricsUtils . Source . ACTION ,
)
assertEquals (
expected ,
createInitialSearchFragmentState (
activity ,
components ,
tabId = null ,
pastedText = " pastedText " ,
searchAccessPoint = MetricsUtils . Source . ACTION ,
) ,
)
}
@Test
fun `createInitialSearchFragmentState with tab` ( ) {
activity . browsingModeManager . mode = BrowsingMode . Private
@ -504,7 +558,7 @@ class SearchFragmentStoreTest {
}
@Test
fun ` WHEN the search engine is the default one THEN search suggestions providers are updated`( ) = runTest {
fun ` GIVEN private browsing mode WHEN the search engine is the default one THEN search suggestions providers are updated`( ) = runTest {
val initialState = emptyDefaultState ( showHistorySuggestionsForCurrentEngine = false )
val store = SearchFragmentStore ( initialState )
every { settings . shouldShowSearchShortcuts } returns false
@ -539,12 +593,51 @@ class SearchFragmentStoreTest {
assertFalse ( store . state . showAllBookmarkSuggestions )
assertFalse ( store . state . showAllSyncedTabsSuggestions )
assertTrue ( store . state . showAllSessionSuggestions )
assert Tru e( store . state . showSponsoredSuggestions )
assert Tru e( store . state . showNonSponsoredSuggestions )
assert Fals e( store . state . showSponsoredSuggestions )
assert Fals e( store . state . showNonSponsoredSuggestions )
verify { shouldShowSearchSuggestions ( BrowsingMode . Private , settings ) }
}
}
@Test
fun `GIVEN normal browsing mode WHEN the search engine is the default one THEN search suggestions providers are updated` ( ) = runTest {
val initialState = emptyDefaultState ( showHistorySuggestionsForCurrentEngine = false )
val store = SearchFragmentStore ( initialState )
every { settings . shouldShowSearchShortcuts } returns false
every { settings . shouldShowSearchSuggestions } returns true
every { settings . shouldShowClipboardSuggestions } returns true
every { settings . shouldShowHistorySuggestions } returns true
every { settings . shouldShowBookmarkSuggestions } returns false
every { settings . shouldShowSyncedTabsSuggestions } returns false
every { settings . shouldShowSearchSuggestions } returns true
every { settings . shouldShowSearchSuggestionsInPrivate } returns true
every { settings . showSponsoredSuggestions } returns true
every { settings . showNonSponsoredSuggestions } returns true
store . dispatch (
SearchFragmentAction . SearchDefaultEngineSelected (
engine = searchEngine ,
browsingMode = BrowsingMode . Normal ,
settings = settings ,
) ,
) . join ( )
assertNotSame ( initialState , store . state )
assertEquals ( SearchEngineSource . Default ( searchEngine ) , store . state . searchEngineSource )
assertTrue ( store . state . showSearchSuggestions )
assertFalse ( store . state . showSearchShortcuts )
assertTrue ( store . state . showClipboardSuggestions )
assertFalse ( store . state . showSearchTermHistory )
assertFalse ( store . state . showHistorySuggestionsForCurrentEngine )
assertTrue ( store . state . showAllHistorySuggestions )
assertFalse ( store . state . showAllBookmarkSuggestions )
assertFalse ( store . state . showAllSyncedTabsSuggestions )
assertTrue ( store . state . showAllSessionSuggestions )
assertTrue ( store . state . showSponsoredSuggestions )
assertTrue ( store . state . showNonSponsoredSuggestions )
}
@Test
fun `GIVEN unified search is enabled WHEN the search engine is updated to a general engine shortcut THEN search suggestions providers are updated` ( ) = runTest {
val initialState = emptyDefaultState ( showHistorySuggestionsForCurrentEngine = false )
@ -1078,7 +1171,7 @@ class SearchFragmentStoreTest {
}
@Test
fun `GIVEN normal browsing mode and search suggestions enabled WHEN checking if search sugge d tions should be shown THEN return true`( ) {
fun `GIVEN normal browsing mode and search suggestions enabled WHEN checking if search sugge s tions should be shown THEN return true`( ) {
var settings : Settings = mockk {
every { shouldShowSearchSuggestions } returns false
every { shouldShowSearchSuggestionsInPrivate } returns false
@ -1093,7 +1186,7 @@ class SearchFragmentStoreTest {
}
@Test
fun `GIVEN private browsing mode and search suggestions enabled WHEN checking if search sugge d tions should be shown THEN return true`( ) {
fun `GIVEN private browsing mode and search suggestions enabled WHEN checking if search sugge s tions should be shown THEN return true`( ) {
var settings : Settings = mockk {
every { shouldShowSearchSuggestions } returns false
every { shouldShowSearchSuggestionsInPrivate } returns false