Bug 1826470 – fixed an edge case when cached values affected unified search feature

fenix/117.0
mike a 11 months ago committed by mergify[bot]
parent 537c34848c
commit 717b999ad3

@ -261,7 +261,8 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
state.copy(
searchEngineSource = SearchEngineSource.Default(action.engine),
showSearchSuggestions = shouldShowSearchSuggestions(action.browsingMode, action.settings),
showSearchShortcuts = action.settings.shouldShowSearchShortcuts,
showSearchShortcuts = action.settings.shouldShowSearchShortcuts &&
!action.settings.showUnifiedSearchFeature,
showClipboardSuggestions = action.settings.shouldShowClipboardSuggestions,
showSearchTermHistory = action.settings.showUnifiedSearchFeature &&
action.settings.shouldShowHistorySuggestions,

@ -177,6 +177,180 @@ class SearchFragmentStoreTest {
assertEquals(query, store.state.query)
}
@Test
fun `GIVEN search shortcuts are disabled and unified search is enabled in settings WHEN the default search engine is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.showUnifiedSearchFeature } returns true
every { settings.shouldShowSearchShortcuts } returns false
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = searchEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts are enabled and unified search is disabled in settings WHEN the default search engine is selected THEN search shortcuts are displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.showUnifiedSearchFeature } returns false
every { settings.shouldShowSearchShortcuts } returns true
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = searchEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertTrue(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts and unified search are both enabled in settings WHEN the default search engine is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.showUnifiedSearchFeature } returns true
every { settings.shouldShowSearchShortcuts } returns true
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = searchEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts and unified search are both disabled in settings WHEN the default search engine is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.showUnifiedSearchFeature } returns true
every { settings.shouldShowSearchShortcuts } returns true
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = searchEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
// non default tests
@Test
fun `GIVEN search shortcuts are disabled and unified search is enabled in settings WHEN the search engine shortcut is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.shouldShowSearchShortcuts } returns false
every { settings.showUnifiedSearchFeature } returns true
val newEngine: SearchEngine = mockk {
every { id } returns "DuckDuckGo"
every { isGeneral } returns true
}
store.dispatch(
SearchFragmentAction.SearchShortcutEngineSelected(
engine = newEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts are enabled and unified search is disabled in settings WHEN the search engine shortcut is selected THEN search shortcuts are displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.shouldShowSearchShortcuts } returns true
every { settings.showUnifiedSearchFeature } returns false
val newEngine: SearchEngine = mockk {
every { id } returns "DuckDuckGo"
every { isGeneral } returns true
}
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = newEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertTrue(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts and unified search are both enabled in settings WHEN the search engine shortcut is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.shouldShowSearchShortcuts } returns true
every { settings.showUnifiedSearchFeature } returns true
val newEngine: SearchEngine = mockk {
every { id } returns "DuckDuckGo"
every { isGeneral } returns true
}
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = newEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
@Test
fun `GIVEN search shortcuts and unified search are both disabled in settings WHEN the search engine shortcut is selected THEN search shortcuts are not displayed`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)
val store = SearchFragmentStore(initialState)
every { settings.shouldShowSearchShortcuts } returns true
every { settings.showUnifiedSearchFeature } returns true
val newEngine: SearchEngine = mockk {
every { id } returns "DuckDuckGo"
every { isGeneral } returns true
}
store.dispatch(
SearchFragmentAction.SearchDefaultEngineSelected(
engine = newEngine,
browsingMode = BrowsingMode.Normal,
settings = settings,
),
).join()
assertNotSame(initialState, store.state)
assertFalse(store.state.showSearchShortcuts)
}
@Test
fun `WHEN the search engine is the default one THEN search suggestions providers are updated`() = runTest {
val initialState = emptyDefaultState(showHistorySuggestionsForCurrentEngine = false)

Loading…
Cancel
Save