diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt index 3a4e6aa5f..0a9b759a9 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt @@ -12,7 +12,6 @@ import mozilla.components.browser.session.Session import mozilla.components.support.ktx.kotlin.isUrl import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity -import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.ACTION import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.NONE @@ -21,7 +20,6 @@ import org.mozilla.fenix.components.metrics.MetricsUtils import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.metrics -import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.settings /** @@ -82,15 +80,19 @@ class DefaultSearchController( override fun handleTextChanged(text: String) { store.dispatch(SearchFragmentAction.UpdateQuery(text)) - store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker( - text.isEmpty() && context.settings().shouldShowSearchShortcuts - )) - store.dispatch(SearchFragmentAction.ShowSearchSuggestionsHint( - text.isNotEmpty() && - (context as HomeActivity).browsingModeManager.mode.isPrivate && - !context.settings().shouldShowSearchSuggestionsInPrivate && - !context.settings().showSearchSuggestionsInPrivateOnboardingFinished - )) + store.dispatch( + SearchFragmentAction.ShowSearchShortcutEnginePicker( + text.isEmpty() && context.settings().shouldShowSearchShortcuts + ) + ) + store.dispatch( + SearchFragmentAction.ShowSearchSuggestionsHint( + text.isNotEmpty() && + (context as HomeActivity).browsingModeManager.mode.isPrivate && + !context.settings().shouldShowSearchSuggestionsInPrivate && + !context.settings().showSearchSuggestionsInPrivateOnboardingFinished + ) + ) } override fun handleUrlTapped(url: String) { @@ -129,7 +131,8 @@ class DefaultSearchController( override fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine) { store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine)) - val isCustom = CustomSearchEngineStore.isCustomSearchEngine(context, searchEngine.identifier) + val isCustom = + CustomSearchEngineStore.isCustomSearchEngine(context, searchEngine.identifier) context.metrics.track(Event.SearchShortcutSelected(searchEngine, isCustom)) } @@ -144,8 +147,9 @@ class DefaultSearchController( } override fun handleExistingSessionSelected(session: Session) { - val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null) - navController.nav(R.id.searchFragment, directions) context.components.core.sessionManager.select(session) + (context as HomeActivity).openToBrowser( + from = BrowserDirection.FromSearch + ) } } diff --git a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt index 8bc116f72..d641259a9 100644 --- a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt @@ -26,7 +26,6 @@ import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.metrics -import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.searchEngineManager import org.mozilla.fenix.ext.settings import org.mozilla.fenix.utils.Settings @@ -72,12 +71,14 @@ class DefaultSearchControllerTest { controller.handleUrlCommitted(url) - verify { context.openToBrowserAndLoad( - searchTermOrURL = url, - newTab = session == null, - from = BrowserDirection.FromSearch, - engine = searchEngine - ) } + verify { + context.openToBrowserAndLoad( + searchTermOrURL = url, + newTab = session == null, + from = BrowserDirection.FromSearch, + engine = searchEngine + ) + } verify { metrics.track(Event.EnteredUrl(false)) } } @@ -162,11 +163,13 @@ class DefaultSearchControllerTest { controller.handleUrlTapped(url) - verify { context.openToBrowserAndLoad( - searchTermOrURL = url, - newTab = session == null, - from = BrowserDirection.FromSearch - ) } + verify { + context.openToBrowserAndLoad( + searchTermOrURL = url, + newTab = session == null, + from = BrowserDirection.FromSearch + ) + } verify { metrics.track(Event.EnteredUrl(false)) } } @@ -176,13 +179,15 @@ class DefaultSearchControllerTest { controller.handleSearchTermsTapped(searchTerms) - verify { context.openToBrowserAndLoad( - searchTermOrURL = searchTerms, - newTab = session == null, - from = BrowserDirection.FromSearch, - engine = searchEngine, - forceSearch = true - ) } + verify { + context.openToBrowserAndLoad( + searchTermOrURL = searchTerms, + newTab = session == null, + from = BrowserDirection.FromSearch, + engine = searchEngine, + forceSearch = true + ) + } } @Test @@ -197,7 +202,8 @@ class DefaultSearchControllerTest { @Test fun handleClickSearchEngineSettings() { - val directions: NavDirections = SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment() + val directions: NavDirections = + SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment() controller.handleClickSearchEngineSettings() @@ -225,11 +231,10 @@ class DefaultSearchControllerTest { @Test fun handleExistingSessionSelected() { val session: Session = mockk(relaxed = true) - val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null) controller.handleExistingSessionSelected(session) - verify { navController.nav(R.id.searchFragment, directions) } verify { sessionManager.select(session) } + verify { context.openToBrowser(from = BrowserDirection.FromSearch) } } } diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt index a2b98bde1..2507c91c5 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchInteractorTest.kt @@ -6,7 +6,6 @@ package org.mozilla.fenix.search import android.content.Context import androidx.navigation.NavController -import androidx.navigation.NavDestination import androidx.navigation.NavDirections import androidx.test.ext.junit.runners.AndroidJUnit4 import io.mockk.Runs @@ -24,7 +23,6 @@ import org.junit.runner.RunWith import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.FenixApplication import org.mozilla.fenix.HomeActivity -import org.mozilla.fenix.R import org.mozilla.fenix.TestApplication import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES @@ -272,13 +270,12 @@ class SearchInteractorTest { @Test fun onExistingSessionSelected() { val navController: NavController = mockk(relaxed = true) - every { navController.currentDestination } returns NavDestination("").apply { - id = R.id.searchFragment - } - val context: Context = mockk(relaxed = true) + val context: HomeActivity = mockk(relaxed = true) val applicationContext: FenixApplication = mockk(relaxed = true) every { context.applicationContext } returns applicationContext val store: SearchFragmentStore = mockk() + every { context.openToBrowser(any(), any()) } just Runs + every { store.state } returns mockk(relaxed = true) val searchController: SearchController = DefaultSearchController( @@ -292,12 +289,7 @@ class SearchInteractorTest { interactor.onExistingSessionSelected(session) verify { - navController.navigate( - SearchFragmentDirections.actionSearchFragmentToBrowserFragment( - activeSessionId = null - ), - null - ) + context.openToBrowser(BrowserDirection.FromSearch) } } }