Skip to content

Commit

Permalink
For mozilla-mobile#27753 - Update search engines immediately after ch…
Browse files Browse the repository at this point in the history
…anging language
  • Loading branch information
DreVla committed Nov 11, 2022
1 parent fbea76d commit e000700
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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)

Expand All @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
controller = DefaultLocaleSettingsController(
activity = requireActivity(),
localeSettingsStore = localeSettingsStore,
browserStore = browserStore,
localeUseCase = localeUseCase,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +26,7 @@ class LocaleSettingsControllerTest {

private val activity = mockk<Activity>(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())

Expand All @@ -35,6 +38,7 @@ class LocaleSettingsControllerTest {
DefaultLocaleSettingsController(
activity,
localeSettingsStore,
browserStore,
localeUseCases,
),
)
Expand All @@ -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()
}
Expand All @@ -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) }
Expand All @@ -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) }
Expand All @@ -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) {
Expand All @@ -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) }
Expand Down

0 comments on commit e000700

Please sign in to comment.