mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
Bug 1834746 - Refactor tests to remove mockkStatic.
This commit is contained in:
parent
ef5b50ab47
commit
6c80e5c476
@ -20,8 +20,6 @@ import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.browser.state.state.SearchState
|
||||
import mozilla.components.browser.state.state.searchEngines
|
||||
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
@ -31,8 +29,7 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.components.Components
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
@ -99,58 +96,53 @@ internal class SearchDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
fun `GIVEN the default search engine is currently selected WHEN checking the need to update the current search engine THEN don't to anything`() {
|
||||
fragment.interactor = mockk()
|
||||
val searchDialogFragment = spyk(fragment)
|
||||
val interactor = spyk(SearchDialogInteractor(mockk()))
|
||||
|
||||
every { searchDialogFragment.interactor } returns interactor
|
||||
|
||||
val defaultSearchEngine: SearchEngine = mockk {
|
||||
every { id } returns "default"
|
||||
}
|
||||
val otherSearchEngine: SearchEngine = mockk {
|
||||
every { id } returns "other"
|
||||
}
|
||||
val components: Components = mockk {
|
||||
every { core.store.state.search } returns mockk(relaxed = true) {
|
||||
every { searchEngines } returns listOf(otherSearchEngine, defaultSearchEngine)
|
||||
}
|
||||
}
|
||||
mockkStatic(
|
||||
"org.mozilla.fenix.ext.FragmentKt",
|
||||
"mozilla.components.browser.state.state.SearchStateKt",
|
||||
) {
|
||||
every { any<Fragment>().requireComponents } returns components
|
||||
every { any<SearchState>().selectedOrDefaultSearchEngine } returns defaultSearchEngine
|
||||
|
||||
fragment.maybeSelectShortcutEngine(defaultSearchEngine.id)
|
||||
every { searchDialogFragment.requireContext() } returns testContext
|
||||
every { testContext.components.core.store.state.search } returns SearchState(
|
||||
regionSearchEngines = listOf(defaultSearchEngine, otherSearchEngine),
|
||||
userSelectedSearchEngineId = "default",
|
||||
)
|
||||
|
||||
verify { fragment.interactor wasNot Called }
|
||||
}
|
||||
searchDialogFragment.maybeSelectShortcutEngine(defaultSearchEngine.id)
|
||||
|
||||
verify { interactor wasNot Called }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN the default search engine is not currently selected WHEN checking the need to update the current search engine THEN update it to the current engine`() {
|
||||
fragment.interactor = mockk {
|
||||
every { onSearchShortcutEngineSelected(any()) } just Runs
|
||||
}
|
||||
val searchDialogFragment = spyk(fragment)
|
||||
val interactor = spyk(SearchDialogInteractor(mockk()))
|
||||
|
||||
every { searchDialogFragment.interactor } returns interactor
|
||||
every { interactor.onSearchShortcutEngineSelected(any()) } just Runs
|
||||
|
||||
val defaultSearchEngine: SearchEngine = mockk {
|
||||
every { id } returns "default"
|
||||
}
|
||||
val otherSearchEngine: SearchEngine = mockk {
|
||||
every { id } returns "other"
|
||||
}
|
||||
val components: Components = mockk {
|
||||
every { core.store.state.search } returns mockk(relaxed = true) {
|
||||
every { searchEngines } returns listOf(otherSearchEngine, defaultSearchEngine)
|
||||
}
|
||||
}
|
||||
mockkStatic(
|
||||
"org.mozilla.fenix.ext.FragmentKt",
|
||||
"mozilla.components.browser.state.state.SearchStateKt",
|
||||
) {
|
||||
every { any<Fragment>().requireComponents } returns components
|
||||
every { any<SearchState>().selectedOrDefaultSearchEngine } returns defaultSearchEngine
|
||||
|
||||
fragment.maybeSelectShortcutEngine(otherSearchEngine.id)
|
||||
every { searchDialogFragment.requireContext() } returns testContext
|
||||
every { testContext.components.core.store.state.search } returns SearchState(
|
||||
regionSearchEngines = listOf(defaultSearchEngine, otherSearchEngine),
|
||||
userSelectedSearchEngineId = "default",
|
||||
)
|
||||
|
||||
verify { fragment.interactor.onSearchShortcutEngineSelected(otherSearchEngine) }
|
||||
}
|
||||
searchDialogFragment.maybeSelectShortcutEngine(otherSearchEngine.id)
|
||||
|
||||
verify { interactor.onSearchShortcutEngineSelected(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user