You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt

377 lines
12 KiB
Kotlin

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.search
import androidx.appcompat.app.AlertDialog
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.spyk
import io.mockk.unmockkObject
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases
import org.junit.After
import org.junit.Before
[fenix] 16900 make navgraph inflation asynchronous (https://github.com/mozilla-mobile/fenix/pull/18889) * For https://github.com/mozilla-mobile/fenix/issues/16900: implement async navgraph inflation For https://github.com/mozilla-mobile/fenix/issues/16900: removed nav graph from xml For https://github.com/mozilla-mobile/fenix/issues/16900: inflate navGraph programatically For https://github.com/mozilla-mobile/fenix/issues/16900: Made NavGraph inflation asynchronous For https://github.com/mozilla-mobile/fenix/issues/16900: Changed to block with runBlocking For https://github.com/mozilla-mobile/fenix/issues/16900: Refactored blocking call into a function For 16900: NavGraph inflation is now async We now attach the nav graph (or check if its attached) on every nav call ( an extension function for NavController). This is done by checking the value of the job stored in PerfNavController.map which keeps track of the job with the NavController as a Key. If the job hasn't been completed, it will block the main thread until the job is done. The job itself is responsible for attaching the navgraph to the navcontroller (and the inflation of the latter too) For 16900: rebased upstream master For 16900: Rebase on master For https://github.com/mozilla-mobile/fenix/issues/16900: Fixed Async Navgraph navigation per review comments. 1)The Asynchronous method is now found in NavGraphProvider.kt. It creates a job on the IO dispatcher 2)The Job is tracked through a WeakHashMap from Controller --> NavGraph 3)The Coroutine scope doesn't use MainScope() anymore 4)The Coroutine is cancelled if the Activity is destroyed 5)The tests mockk the blockForNavGraphInflation method through the FenixReoboelectricTestApplication instead of calling the mock every setup() For https://github.com/mozilla-mobile/fenix/issues/16900: inflateNavGraphAsync now takes navController For https://github.com/mozilla-mobile/fenix/issues/16900: Pass lifecycleScope to NavGraphProvider For https://github.com/mozilla-mobile/fenix/issues/16900: removed unused mock For https://github.com/mozilla-mobile/fenix/issues/16900: Added linter rules for navigate calls We need linting rules to make sure no one calls the NavController.navigate() methods For https://github.com/mozilla-mobile/fenix/issues/16900: Added TestRule to help abstract the mocks in the code For 16900: Fix linting problems For https://github.com/mozilla-mobile/fenix/issues/16900: Cleaned duplicated code in tests For https://github.com/mozilla-mobile/fenix/issues/16900: cleaned up NavGraphTestRule for finished test For https://github.com/mozilla-mobile/fenix/issues/16900: had to revert an accidentally edited file For https://github.com/mozilla-mobile/fenix/issues/16900: rebased master * For https://github.com/mozilla-mobile/fenix/issues/16900: Review nits for async navgraph This is composed of squash commits, the original messages can be found below: -> DisableNavGraphProviderAssertionRule + kdoc. Use test rule in RobolectricApplication. Fix failing CrashReporterControllerTest Fix blame by -> navigate in tests. This commit was generated by the following commands only: ``` find app/src/test -type f -exec sed -i '' "/import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph/d" {} \; find app/src/test -type f -exec sed -i "" "s/navigateBlockingForAsyncNavGraph/navigate/g" {} \; git checkout app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker ``` Fix various blame This is expected to be squashed into the first commit so, if so, it'd fix the blame. Move test rule to helpers pkg. add missing license header Add import change I missed fix unused imports Replace robolectricTestrunner with test rule. Improve navGraphProvider docs Remove unnecessary rule as defined by robolectric. add clarifying comment to robolectric remove unnecessary space * For https://github.com/mozilla-mobile/fenix/issues/16900: nit fixes for MozillaNavigateCheck and lint fixes 3 squash commits: *Changed violation message and fixed the lint rule for MozillaNavigateCheck *Added suppression to NavController.kt *Fixed detekt violations * For 16900: Fixed failing tests Co-authored-by: Michael Comella <michael.l.comella@gmail.com>
3 years ago
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
[fenix] 16900 make navgraph inflation asynchronous (https://github.com/mozilla-mobile/fenix/pull/18889) * For https://github.com/mozilla-mobile/fenix/issues/16900: implement async navgraph inflation For https://github.com/mozilla-mobile/fenix/issues/16900: removed nav graph from xml For https://github.com/mozilla-mobile/fenix/issues/16900: inflate navGraph programatically For https://github.com/mozilla-mobile/fenix/issues/16900: Made NavGraph inflation asynchronous For https://github.com/mozilla-mobile/fenix/issues/16900: Changed to block with runBlocking For https://github.com/mozilla-mobile/fenix/issues/16900: Refactored blocking call into a function For 16900: NavGraph inflation is now async We now attach the nav graph (or check if its attached) on every nav call ( an extension function for NavController). This is done by checking the value of the job stored in PerfNavController.map which keeps track of the job with the NavController as a Key. If the job hasn't been completed, it will block the main thread until the job is done. The job itself is responsible for attaching the navgraph to the navcontroller (and the inflation of the latter too) For 16900: rebased upstream master For 16900: Rebase on master For https://github.com/mozilla-mobile/fenix/issues/16900: Fixed Async Navgraph navigation per review comments. 1)The Asynchronous method is now found in NavGraphProvider.kt. It creates a job on the IO dispatcher 2)The Job is tracked through a WeakHashMap from Controller --> NavGraph 3)The Coroutine scope doesn't use MainScope() anymore 4)The Coroutine is cancelled if the Activity is destroyed 5)The tests mockk the blockForNavGraphInflation method through the FenixReoboelectricTestApplication instead of calling the mock every setup() For https://github.com/mozilla-mobile/fenix/issues/16900: inflateNavGraphAsync now takes navController For https://github.com/mozilla-mobile/fenix/issues/16900: Pass lifecycleScope to NavGraphProvider For https://github.com/mozilla-mobile/fenix/issues/16900: removed unused mock For https://github.com/mozilla-mobile/fenix/issues/16900: Added linter rules for navigate calls We need linting rules to make sure no one calls the NavController.navigate() methods For https://github.com/mozilla-mobile/fenix/issues/16900: Added TestRule to help abstract the mocks in the code For 16900: Fix linting problems For https://github.com/mozilla-mobile/fenix/issues/16900: Cleaned duplicated code in tests For https://github.com/mozilla-mobile/fenix/issues/16900: cleaned up NavGraphTestRule for finished test For https://github.com/mozilla-mobile/fenix/issues/16900: had to revert an accidentally edited file For https://github.com/mozilla-mobile/fenix/issues/16900: rebased master * For https://github.com/mozilla-mobile/fenix/issues/16900: Review nits for async navgraph This is composed of squash commits, the original messages can be found below: -> DisableNavGraphProviderAssertionRule + kdoc. Use test rule in RobolectricApplication. Fix failing CrashReporterControllerTest Fix blame by -> navigate in tests. This commit was generated by the following commands only: ``` find app/src/test -type f -exec sed -i '' "/import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph/d" {} \; find app/src/test -type f -exec sed -i "" "s/navigateBlockingForAsyncNavGraph/navigate/g" {} \; git checkout app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker ``` Fix various blame This is expected to be squashed into the first commit so, if so, it'd fix the blame. Move test rule to helpers pkg. add missing license header Add import change I missed fix unused imports Replace robolectricTestrunner with test rule. Improve navGraphProvider docs Remove unnecessary rule as defined by robolectric. add clarifying comment to robolectric remove unnecessary space * For https://github.com/mozilla-mobile/fenix/issues/16900: nit fixes for MozillaNavigateCheck and lint fixes 3 squash commits: *Changed violation message and fixed the lint rule for MozillaNavigateCheck *Added suppression to NavController.kt *Fixed detekt violations * For 16900: Fixed failing tests Co-authored-by: Michael Comella <michael.l.comella@gmail.com>
3 years ago
import org.mozilla.fenix.helpers.DisableNavGraphProviderAssertionRule
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.components.metrics.MetricsUtils
[fenix] 16900 make navgraph inflation asynchronous (https://github.com/mozilla-mobile/fenix/pull/18889) * For https://github.com/mozilla-mobile/fenix/issues/16900: implement async navgraph inflation For https://github.com/mozilla-mobile/fenix/issues/16900: removed nav graph from xml For https://github.com/mozilla-mobile/fenix/issues/16900: inflate navGraph programatically For https://github.com/mozilla-mobile/fenix/issues/16900: Made NavGraph inflation asynchronous For https://github.com/mozilla-mobile/fenix/issues/16900: Changed to block with runBlocking For https://github.com/mozilla-mobile/fenix/issues/16900: Refactored blocking call into a function For 16900: NavGraph inflation is now async We now attach the nav graph (or check if its attached) on every nav call ( an extension function for NavController). This is done by checking the value of the job stored in PerfNavController.map which keeps track of the job with the NavController as a Key. If the job hasn't been completed, it will block the main thread until the job is done. The job itself is responsible for attaching the navgraph to the navcontroller (and the inflation of the latter too) For 16900: rebased upstream master For 16900: Rebase on master For https://github.com/mozilla-mobile/fenix/issues/16900: Fixed Async Navgraph navigation per review comments. 1)The Asynchronous method is now found in NavGraphProvider.kt. It creates a job on the IO dispatcher 2)The Job is tracked through a WeakHashMap from Controller --> NavGraph 3)The Coroutine scope doesn't use MainScope() anymore 4)The Coroutine is cancelled if the Activity is destroyed 5)The tests mockk the blockForNavGraphInflation method through the FenixReoboelectricTestApplication instead of calling the mock every setup() For https://github.com/mozilla-mobile/fenix/issues/16900: inflateNavGraphAsync now takes navController For https://github.com/mozilla-mobile/fenix/issues/16900: Pass lifecycleScope to NavGraphProvider For https://github.com/mozilla-mobile/fenix/issues/16900: removed unused mock For https://github.com/mozilla-mobile/fenix/issues/16900: Added linter rules for navigate calls We need linting rules to make sure no one calls the NavController.navigate() methods For https://github.com/mozilla-mobile/fenix/issues/16900: Added TestRule to help abstract the mocks in the code For 16900: Fix linting problems For https://github.com/mozilla-mobile/fenix/issues/16900: Cleaned duplicated code in tests For https://github.com/mozilla-mobile/fenix/issues/16900: cleaned up NavGraphTestRule for finished test For https://github.com/mozilla-mobile/fenix/issues/16900: had to revert an accidentally edited file For https://github.com/mozilla-mobile/fenix/issues/16900: rebased master * For https://github.com/mozilla-mobile/fenix/issues/16900: Review nits for async navgraph This is composed of squash commits, the original messages can be found below: -> DisableNavGraphProviderAssertionRule + kdoc. Use test rule in RobolectricApplication. Fix failing CrashReporterControllerTest Fix blame by -> navigate in tests. This commit was generated by the following commands only: ``` find app/src/test -type f -exec sed -i '' "/import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph/d" {} \; find app/src/test -type f -exec sed -i "" "s/navigateBlockingForAsyncNavGraph/navigate/g" {} \; git checkout app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker ``` Fix various blame This is expected to be squashed into the first commit so, if so, it'd fix the blame. Move test rule to helpers pkg. add missing license header Add import change I missed fix unused imports Replace robolectricTestrunner with test rule. Improve navGraphProvider docs Remove unnecessary rule as defined by robolectric. add clarifying comment to robolectric remove unnecessary space * For https://github.com/mozilla-mobile/fenix/issues/16900: nit fixes for MozillaNavigateCheck and lint fixes 3 squash commits: *Changed violation message and fixed the lint rule for MozillaNavigateCheck *Added suppression to NavController.kt *Fixed detekt violations * For 16900: Fixed failing tests Co-authored-by: Michael Comella <michael.l.comella@gmail.com>
3 years ago
import org.mozilla.fenix.search.SearchDialogFragmentDirections.Companion.actionGlobalAddonsManagementFragment
import org.mozilla.fenix.search.SearchDialogFragmentDirections.Companion.actionGlobalSearchEngineFragment
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.utils.Settings
@ExperimentalCoroutinesApi
class SearchDialogControllerTest {
@MockK(relaxed = true) private lateinit var activity: HomeActivity
@MockK(relaxed = true) private lateinit var store: SearchDialogFragmentStore
@MockK(relaxed = true) private lateinit var navController: NavController
@MockK private lateinit var searchEngine: SearchEngine
@MockK(relaxed = true) private lateinit var metrics: MetricController
@MockK(relaxed = true) private lateinit var settings: Settings
@MockK private lateinit var sessionManager: SessionManager
@MockK(relaxed = true) private lateinit var clearToolbarFocus: () -> Unit
@MockK(relaxed = true) private lateinit var focusToolbar: () -> Unit
@MockK(relaxed = true) private lateinit var clearToolbar: () -> Unit
@MockK(relaxed = true) private lateinit var dismissDialog: () -> Unit
private lateinit var controller: SearchDialogController
[fenix] 16900 make navgraph inflation asynchronous (https://github.com/mozilla-mobile/fenix/pull/18889) * For https://github.com/mozilla-mobile/fenix/issues/16900: implement async navgraph inflation For https://github.com/mozilla-mobile/fenix/issues/16900: removed nav graph from xml For https://github.com/mozilla-mobile/fenix/issues/16900: inflate navGraph programatically For https://github.com/mozilla-mobile/fenix/issues/16900: Made NavGraph inflation asynchronous For https://github.com/mozilla-mobile/fenix/issues/16900: Changed to block with runBlocking For https://github.com/mozilla-mobile/fenix/issues/16900: Refactored blocking call into a function For 16900: NavGraph inflation is now async We now attach the nav graph (or check if its attached) on every nav call ( an extension function for NavController). This is done by checking the value of the job stored in PerfNavController.map which keeps track of the job with the NavController as a Key. If the job hasn't been completed, it will block the main thread until the job is done. The job itself is responsible for attaching the navgraph to the navcontroller (and the inflation of the latter too) For 16900: rebased upstream master For 16900: Rebase on master For https://github.com/mozilla-mobile/fenix/issues/16900: Fixed Async Navgraph navigation per review comments. 1)The Asynchronous method is now found in NavGraphProvider.kt. It creates a job on the IO dispatcher 2)The Job is tracked through a WeakHashMap from Controller --> NavGraph 3)The Coroutine scope doesn't use MainScope() anymore 4)The Coroutine is cancelled if the Activity is destroyed 5)The tests mockk the blockForNavGraphInflation method through the FenixReoboelectricTestApplication instead of calling the mock every setup() For https://github.com/mozilla-mobile/fenix/issues/16900: inflateNavGraphAsync now takes navController For https://github.com/mozilla-mobile/fenix/issues/16900: Pass lifecycleScope to NavGraphProvider For https://github.com/mozilla-mobile/fenix/issues/16900: removed unused mock For https://github.com/mozilla-mobile/fenix/issues/16900: Added linter rules for navigate calls We need linting rules to make sure no one calls the NavController.navigate() methods For https://github.com/mozilla-mobile/fenix/issues/16900: Added TestRule to help abstract the mocks in the code For 16900: Fix linting problems For https://github.com/mozilla-mobile/fenix/issues/16900: Cleaned duplicated code in tests For https://github.com/mozilla-mobile/fenix/issues/16900: cleaned up NavGraphTestRule for finished test For https://github.com/mozilla-mobile/fenix/issues/16900: had to revert an accidentally edited file For https://github.com/mozilla-mobile/fenix/issues/16900: rebased master * For https://github.com/mozilla-mobile/fenix/issues/16900: Review nits for async navgraph This is composed of squash commits, the original messages can be found below: -> DisableNavGraphProviderAssertionRule + kdoc. Use test rule in RobolectricApplication. Fix failing CrashReporterControllerTest Fix blame by -> navigate in tests. This commit was generated by the following commands only: ``` find app/src/test -type f -exec sed -i '' "/import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph/d" {} \; find app/src/test -type f -exec sed -i "" "s/navigateBlockingForAsyncNavGraph/navigate/g" {} \; git checkout app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker ``` Fix various blame This is expected to be squashed into the first commit so, if so, it'd fix the blame. Move test rule to helpers pkg. add missing license header Add import change I missed fix unused imports Replace robolectricTestrunner with test rule. Improve navGraphProvider docs Remove unnecessary rule as defined by robolectric. add clarifying comment to robolectric remove unnecessary space * For https://github.com/mozilla-mobile/fenix/issues/16900: nit fixes for MozillaNavigateCheck and lint fixes 3 squash commits: *Changed violation message and fixed the lint rule for MozillaNavigateCheck *Added suppression to NavController.kt *Fixed detekt violations * For 16900: Fixed failing tests Co-authored-by: Michael Comella <michael.l.comella@gmail.com>
3 years ago
@get:Rule
val disableNavGraphProviderAssertionRule = DisableNavGraphProviderAssertionRule()
@Before
fun setUp() {
MockKAnnotations.init(this)
mockkObject(MetricsUtils)
val browserStore = BrowserStore()
every { store.state.tabId } returns "test-tab-id"
every { store.state.searchEngineSource.searchEngine } returns searchEngine
every { sessionManager.select(any()) } just Runs
every { navController.currentDestination } returns mockk {
every { id } returns R.id.searchDialogFragment
}
every { MetricsUtils.createSearchEvent(searchEngine, browserStore, any()) } returns null
val tabsUseCases = TabsUseCases(browserStore, sessionManager)
controller = SearchDialogController(
activity = activity,
store = browserStore,
tabsUseCases = tabsUseCases,
fragmentStore = store,
navController = navController,
settings = settings,
metrics = metrics,
dismissDialog = dismissDialog,
clearToolbarFocus = clearToolbarFocus,
focusToolbar = focusToolbar,
clearToolbar = clearToolbar
)
}
@After
fun teardown() {
unmockkObject(MetricsUtils)
}
@Test
fun handleUrlCommitted() {
val url = "https://www.google.com/"
controller.handleUrlCommitted(url)
verify {
activity.openToBrowserAndLoad(
searchTermOrURL = url,
newTab = false,
from = BrowserDirection.FromSearchDialog,
engine = searchEngine
)
}
verify { metrics.track(Event.EnteredUrl(false)) }
}
@Test
fun handleBlankUrlCommitted() {
val url = ""
controller.handleUrlCommitted(url)
verify {
dismissDialog()
}
}
@Test
fun handleSearchCommitted() {
val searchTerm = "Firefox"
controller.handleUrlCommitted(searchTerm)
verify {
activity.openToBrowserAndLoad(
searchTermOrURL = searchTerm,
newTab = false,
from = BrowserDirection.FromSearchDialog,
engine = searchEngine
)
}
}
@Test
fun handleCrashesUrlCommitted() {
val url = "about:crashes"
every { activity.packageName } returns "org.mozilla.fenix"
controller.handleUrlCommitted(url)
verify {
activity.startActivity(any())
}
}
@Test
fun handleAddonsUrlCommitted() {
val url = "about:addons"
val directions = actionGlobalAddonsManagementFragment()
controller.handleUrlCommitted(url)
verify { navController.navigate(directions) }
}
@Test
fun handleMozillaUrlCommitted() {
val url = "moz://a"
controller.handleUrlCommitted(url)
verify {
activity.openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.MANIFESTO),
newTab = false,
from = BrowserDirection.FromSearchDialog,
engine = searchEngine
)
}
verify { metrics.track(Event.EnteredUrl(false)) }
}
@Test
fun handleEditingCancelled() = runBlockingTest {
controller.handleEditingCancelled()
verify {
clearToolbarFocus()
}
}
@Test
fun handleTextChangedNonEmpty() {
val text = "fenix"
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.UpdateQuery(text)) }
}
@Test
fun handleTextChangedEmpty() {
val text = ""
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.UpdateQuery(text)) }
}
@Test
fun `show search shortcuts when setting enabled AND query empty`() {
val text = ""
every { settings.shouldShowSearchShortcuts } returns true
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) }
}
@Test
fun `show search shortcuts when setting enabled AND query equals url`() {
val text = "mozilla.org"
every { store.state.url } returns "mozilla.org"
every { settings.shouldShowSearchShortcuts } returns true
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) }
}
@Test
fun `do not show search shortcuts when setting enabled AND query non-empty`() {
val text = "mozilla"
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
}
@Test
fun `do not show search shortcuts when setting disabled AND query empty AND url not matching query`() {
every { settings.shouldShowSearchShortcuts } returns false
val text = ""
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
}
@Test
fun `do not show search shortcuts when setting disabled AND query non-empty`() {
every { settings.shouldShowSearchShortcuts } returns false
val text = "mozilla"
controller.handleTextChanged(text)
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
}
@Test
fun handleUrlTapped() {
val url = "https://www.google.com/"
controller.handleUrlTapped(url)
verify {
activity.openToBrowserAndLoad(
searchTermOrURL = url,
newTab = false,
from = BrowserDirection.FromSearchDialog
)
}
verify { metrics.track(Event.EnteredUrl(false)) }
}
@Test
fun handleSearchTermsTapped() {
val searchTerms = "fenix"
controller.handleSearchTermsTapped(searchTerms)
verify {
activity.openToBrowserAndLoad(
searchTermOrURL = searchTerms,
newTab = false,
from = BrowserDirection.FromSearchDialog,
engine = searchEngine,
forceSearch = true
)
}
}
@Test
fun handleSearchShortcutEngineSelected() {
val searchEngine: SearchEngine = mockk(relaxed = true)
controller.handleSearchShortcutEngineSelected(searchEngine)
verify { focusToolbar() }
verify { store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine)) }
verify { metrics.track(Event.SearchShortcutSelected(searchEngine, false)) }
}
@Test
fun handleClickSearchEngineSettings() {
val directions: NavDirections = actionGlobalSearchEngineFragment()
controller.handleClickSearchEngineSettings()
verify { navController.navigate(directions) }
}
@Test
fun handleSearchShortcutsButtonClicked_alreadyOpen() {
every { store.state.showSearchShortcuts } returns true
controller.handleSearchShortcutsButtonClicked()
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(false)) }
}
@Test
fun handleSearchShortcutsButtonClicked_notYetOpen() {
every { store.state.showSearchShortcuts } returns false
controller.handleSearchShortcutsButtonClicked()
verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) }
}
@Test
fun handleExistingSessionSelected() {
val session = mockk<Session>()
every { sessionManager.findSessionById("selected") } returns session
controller.handleExistingSessionSelected("selected")
verify { sessionManager.select(session) }
verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
}
@Test
fun handleExistingSessionSelected_tabId_nullSession() {
every { sessionManager.findSessionById("tab-id") } returns null
controller.handleExistingSessionSelected("tab-id")
verify(inverse = true) { sessionManager.select(any()) }
verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
}
@Test
fun handleExistingSessionSelected_tabId() {
val session = mockk<Session>()
every { sessionManager.findSessionById("tab-id") } returns session
controller.handleExistingSessionSelected("tab-id")
verify { sessionManager.select(any()) }
verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
}
@Test
fun `show camera permissions needed dialog`() {
val dialogBuilder: AlertDialog.Builder = mockk(relaxed = true)
val spyController = spyk(controller)
every { spyController.buildDialog() } returns dialogBuilder
spyController.handleCameraPermissionsNeeded()
verify { dialogBuilder.show() }
}
}