From 807b0567f99c698a4860b86865829cd19b5680c2 Mon Sep 17 00:00:00 2001 From: DreVla Date: Thu, 10 Nov 2022 12:51:42 +0200 Subject: [PATCH] For #27753 - Update search engines immediately after changing language --- .../java/org/mozilla/fenix/ui/SettingsSearchTest.kt | 6 +----- .../settings/advanced/DefaultLocaleSettingsController.kt | 5 +++++ .../fenix/settings/advanced/LocaleSettingsFragment.kt | 1 + .../settings/advanced/LocaleSettingsControllerTest.kt | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsSearchTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsSearchTest.kt index bedae77e20..3ef2762108 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsSearchTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsSearchTest.kt @@ -420,11 +420,7 @@ class SettingsSearchTest { "Bing", "Amazon.com", "DuckDuckGo", - "eBay", - /* Disabled Arabic Wikipedia verification - until https://github.com/mozilla-mobile/fenix/issues/12236 gets fixed - "ويكيبيديا (ar)" - */ + "ويكيبيديا (ar)", ) } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt b/app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt index 05f75ec22a..fd2f5c9232 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt @@ -6,6 +6,8 @@ package org.mozilla.fenix.settings.advanced import android.app.Activity import android.content.Context +import mozilla.components.browser.state.action.SearchAction +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleUseCases import org.mozilla.fenix.nimbus.FxNimbus @@ -20,6 +22,7 @@ interface LocaleSettingsController { class DefaultLocaleSettingsController( private val activity: Activity, private val localeSettingsStore: LocaleSettingsStore, + private val browserStore: BrowserStore, private val localeUseCase: LocaleUseCases, ) : LocaleSettingsController { @@ -30,6 +33,7 @@ class DefaultLocaleSettingsController( return } localeSettingsStore.dispatch(LocaleSettingsAction.Select(locale)) + browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) LocaleManager.setNewLocale(activity, localeUseCase, locale) LocaleManager.updateBaseConfiguration(activity, locale) @@ -44,6 +48,7 @@ class DefaultLocaleSettingsController( return } localeSettingsStore.dispatch(LocaleSettingsAction.Select(localeSettingsStore.state.localeList[0])) + browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) LocaleManager.resetToSystemDefault(activity, localeUseCase) LocaleManager.updateBaseConfiguration(activity, localeSettingsStore.state.localeList[0]) diff --git a/app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt index fa1efc95f3..91929aab38 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt @@ -58,6 +58,7 @@ class LocaleSettingsFragment : Fragment(), MenuProvider { controller = DefaultLocaleSettingsController( activity = requireActivity(), localeSettingsStore = localeSettingsStore, + browserStore = browserStore, localeUseCase = localeUseCase, ), ) diff --git a/app/src/test/java/org/mozilla/fenix/settings/advanced/LocaleSettingsControllerTest.kt b/app/src/test/java/org/mozilla/fenix/settings/advanced/LocaleSettingsControllerTest.kt index ec0daaa631..6017df096a 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/advanced/LocaleSettingsControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/advanced/LocaleSettingsControllerTest.kt @@ -14,6 +14,8 @@ import io.mockk.mockkStatic import io.mockk.spyk import io.mockk.verify import io.mockk.verifyAll +import mozilla.components.browser.state.action.SearchAction +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleUseCases import org.junit.Before @@ -24,6 +26,7 @@ class LocaleSettingsControllerTest { private val activity = mockk(relaxed = true) private val localeSettingsStore: LocaleSettingsStore = mockk(relaxed = true) + private val browserStore: BrowserStore = mockk(relaxed = true) private val localeUseCases: LocaleUseCases = mockk(relaxed = true) private val mockState = LocaleSettingsState(mockk(), mockk(), mockk()) @@ -35,6 +38,7 @@ class LocaleSettingsControllerTest { DefaultLocaleSettingsController( activity, localeSettingsStore, + browserStore, localeUseCases, ), ) @@ -53,6 +57,7 @@ class LocaleSettingsControllerTest { verifyAll(inverse = true) { localeSettingsStore.dispatch(LocaleSettingsAction.Select(selectedLocale)) + browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) LocaleManager.setNewLocale(activity, locale = selectedLocale) activity.recreate() } @@ -77,6 +82,7 @@ class LocaleSettingsControllerTest { controller.handleLocaleSelected(selectedLocale) verify { localeSettingsStore.dispatch(LocaleSettingsAction.Select(selectedLocale)) } + verify { browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) } verify { LocaleManager.setNewLocale(activity, localeUseCases, selectedLocale) } verify { activity.recreate() } verify { activity.overridePendingTransition(0, 0) } @@ -101,6 +107,7 @@ class LocaleSettingsControllerTest { controller.handleLocaleSelected(selectedLocale) verify { localeSettingsStore.dispatch(LocaleSettingsAction.Select(selectedLocale)) } + verify { browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) } verify { LocaleManager.setNewLocale(activity, localeUseCases, selectedLocale) } verify { activity.recreate() } verify { activity.overridePendingTransition(0, 0) } @@ -120,6 +127,7 @@ class LocaleSettingsControllerTest { verifyAll(inverse = true) { localeSettingsStore.dispatch(LocaleSettingsAction.Select(selectedLocale)) + browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) LocaleManager.resetToSystemDefault(activity, localeUseCases) activity.recreate() with(controller) { @@ -141,6 +149,7 @@ class LocaleSettingsControllerTest { controller.handleDefaultLocaleSelected() verify { localeSettingsStore.dispatch(LocaleSettingsAction.Select(selectedLocale)) } + verify { browserStore.dispatch(SearchAction.RefreshSearchEnginesAction) } verify { LocaleManager.resetToSystemDefault(activity, localeUseCases) } verify { activity.recreate() } verify { activity.overridePendingTransition(0, 0) }