mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/25814 - Hide "Show search engines" toggle from search settings when unified search is enabled
This commit is contained in:
parent
fab1daaba5
commit
e8ea437ec0
@ -144,6 +144,7 @@ class SearchDialogController(
|
||||
fragmentStore.dispatch(SearchFragmentAction.UpdateQuery(text))
|
||||
fragmentStore.dispatch(
|
||||
SearchFragmentAction.ShowSearchShortcutEnginePicker(
|
||||
!settings.showUnifiedSearchFeature &&
|
||||
(textMatchesCurrentUrl || textMatchesCurrentSearch || text.isEmpty()) &&
|
||||
settings.shouldShowSearchShortcuts,
|
||||
),
|
||||
|
@ -296,7 +296,12 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
||||
flow.map { state -> state.search }
|
||||
.ifChanged()
|
||||
.collect { search ->
|
||||
store.dispatch(SearchFragmentAction.UpdateSearchState(search))
|
||||
store.dispatch(
|
||||
SearchFragmentAction.UpdateSearchState(
|
||||
search,
|
||||
showUnifiedSearchFeature,
|
||||
),
|
||||
)
|
||||
|
||||
updateSearchSelectorMenu(search.searchEngines)
|
||||
}
|
||||
|
@ -212,8 +212,9 @@ sealed class SearchFragmentAction : Action {
|
||||
|
||||
/**
|
||||
* Updates the local `SearchFragmentState` from the global `SearchState` in `BrowserStore`.
|
||||
* If the unified search is enabled, then search shortcuts should not be shown.
|
||||
*/
|
||||
data class UpdateSearchState(val search: SearchState) : SearchFragmentAction()
|
||||
data class UpdateSearchState(val search: SearchState, val isUnifiedSearchEnabled: Boolean) : SearchFragmentAction()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,7 +305,8 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
|
||||
state.copy(
|
||||
defaultEngine = action.search.selectedOrDefaultSearchEngine,
|
||||
areShortcutsAvailable = action.search.searchEngines.size > 1,
|
||||
showSearchShortcuts = state.url.isEmpty() &&
|
||||
showSearchShortcuts = !action.isUnifiedSearchEnabled &&
|
||||
state.url.isEmpty() &&
|
||||
state.showSearchShortcutsSetting &&
|
||||
action.search.searchEngines.size > 1,
|
||||
searchEngineSource = when (state.searchEngineSource) {
|
||||
|
@ -50,6 +50,7 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
|
||||
val showSearchShortcuts =
|
||||
requirePreference<SwitchPreference>(R.string.pref_key_show_search_engine_shortcuts).apply {
|
||||
isChecked = context.settings().shouldShowSearchShortcuts
|
||||
isVisible = !context.settings().showUnifiedSearchFeature
|
||||
}
|
||||
|
||||
val showHistorySuggestions =
|
||||
|
@ -271,6 +271,29 @@ class SearchDialogControllerTest {
|
||||
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN show search shortcuts setting is enabled AND unified search is enabled WHEN query is empty THEN do not show search shortcuts`() {
|
||||
val text = ""
|
||||
every { settings.shouldShowSearchShortcuts } returns true
|
||||
every { settings.showUnifiedSearchFeature } returns true
|
||||
|
||||
createController().handleTextChanged(text)
|
||||
|
||||
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN show search shortcuts setting is enabled AND unified search is enabled WHEN query is url THEN do not show search shortcuts`() {
|
||||
val text = "mozilla.org"
|
||||
every { store.state.url } returns "mozilla.org"
|
||||
every { settings.shouldShowSearchShortcuts } returns true
|
||||
every { settings.showUnifiedSearchFeature } returns true
|
||||
|
||||
createController().handleTextChanged(text)
|
||||
|
||||
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `do not show search shortcuts when setting enabled AND query non-empty`() {
|
||||
val text = "mozilla"
|
||||
|
@ -268,7 +268,7 @@ class SearchFragmentStoreTest {
|
||||
|
||||
store.dispatch(
|
||||
SearchFragmentAction.UpdateSearchState(
|
||||
SearchState(
|
||||
search = SearchState(
|
||||
region = RegionState("US", "US"),
|
||||
regionSearchEngines = listOf(
|
||||
SearchEngine("engine-a", "Engine A", mockk(), type = SearchEngine.Type.BUNDLED),
|
||||
@ -293,6 +293,7 @@ class SearchFragmentStoreTest {
|
||||
userSelectedSearchEngineId = null,
|
||||
userSelectedSearchEngineName = null,
|
||||
),
|
||||
isUnifiedSearchEnabled = false,
|
||||
),
|
||||
)
|
||||
|
||||
@ -327,7 +328,7 @@ class SearchFragmentStoreTest {
|
||||
|
||||
store.dispatch(
|
||||
SearchFragmentAction.UpdateSearchState(
|
||||
SearchState(
|
||||
search = SearchState(
|
||||
region = RegionState("US", "US"),
|
||||
regionSearchEngines = listOf(
|
||||
SearchEngine("engine-a", "Engine A", mockk(), type = SearchEngine.Type.BUNDLED),
|
||||
@ -352,6 +353,7 @@ class SearchFragmentStoreTest {
|
||||
userSelectedSearchEngineId = null,
|
||||
userSelectedSearchEngineName = null,
|
||||
),
|
||||
isUnifiedSearchEnabled = false,
|
||||
),
|
||||
)
|
||||
|
||||
@ -368,6 +370,43 @@ class SearchFragmentStoreTest {
|
||||
assertEquals("Engine B", store.state.searchEngineSource.searchEngine!!.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN unified search is enabled WHEN updating the SearchFragmentState from SearchState THEN disable search shortcuts`() {
|
||||
val store = SearchFragmentStore(
|
||||
emptyDefaultState(
|
||||
searchEngineSource = SearchEngineSource.None,
|
||||
areShortcutsAvailable = false,
|
||||
defaultEngine = null,
|
||||
showSearchShortcutsSetting = false,
|
||||
),
|
||||
)
|
||||
|
||||
assertFalse(store.state.showSearchShortcuts)
|
||||
|
||||
store.dispatch(
|
||||
SearchFragmentAction.UpdateSearchState(
|
||||
search = SearchState(
|
||||
region = RegionState("US", "US"),
|
||||
regionSearchEngines = listOf(
|
||||
SearchEngine("engine-a", "Engine A", mockk(), type = SearchEngine.Type.BUNDLED),
|
||||
SearchEngine("engine-b", "Engine B", mockk(), type = SearchEngine.Type.BUNDLED),
|
||||
),
|
||||
customSearchEngines = listOf(),
|
||||
additionalSearchEngines = listOf(),
|
||||
additionalAvailableSearchEngines = listOf(),
|
||||
hiddenSearchEngines = listOf(),
|
||||
regionDefaultSearchEngineId = "engine-b",
|
||||
userSelectedSearchEngineId = null,
|
||||
userSelectedSearchEngineName = null,
|
||||
),
|
||||
isUnifiedSearchEnabled = true,
|
||||
),
|
||||
)
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertFalse(store.state.showSearchShortcuts)
|
||||
}
|
||||
|
||||
private fun emptyDefaultState(
|
||||
searchEngineSource: SearchEngineSource = mockk(),
|
||||
defaultEngine: SearchEngine? = mockk(),
|
||||
|
Loading…
Reference in New Issue
Block a user