2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] DefaultRecentlyClosedControllerTest: Do not mock functions

This commit is contained in:
Sebastian Kaspari 2021-07-28 17:39:19 +02:00 committed by mergify[bot]
parent 3fde165e1c
commit 0400ede268

View File

@ -44,25 +44,12 @@ class DefaultRecentlyClosedControllerTest {
private val resources: Resources = mockk(relaxed = true)
private val snackbar: FenixSnackbar = mockk(relaxed = true)
private val clipboardManager: ClipboardManager = mockk(relaxed = true)
private val openToBrowser: (RecoverableTab, BrowsingMode?) -> Unit = mockk(relaxed = true)
private val activity: HomeActivity = mockk(relaxed = true)
private val browserStore: BrowserStore = mockk(relaxed = true)
private val recentlyClosedStore: RecentlyClosedFragmentStore = mockk(relaxed = true)
private val tabsUseCases: TabsUseCases = mockk(relaxed = true)
val mockedTab: RecoverableTab = mockk(relaxed = true)
private val controller = DefaultRecentlyClosedController(
navController,
browserStore,
recentlyClosedStore,
tabsUseCases,
resources,
snackbar,
clipboardManager,
activity,
openToBrowser
)
@Before
fun setUp() {
every { tabsUseCases.restore.invoke(any(), true) } just Runs
@ -77,43 +64,69 @@ class DefaultRecentlyClosedControllerTest {
fun handleOpen() {
val item: RecoverableTab = mockk(relaxed = true)
var actualtab: RecoverableTab? = null
var actualBrowsingMode: BrowsingMode? = null
val controller = createController(
openToBrowser = { tab, browsingMode ->
actualtab = tab
actualBrowsingMode = browsingMode
}
)
controller.handleOpen(item, BrowsingMode.Private)
verify {
openToBrowser(item, BrowsingMode.Private)
}
assertEquals(item, actualtab)
assertEquals(actualBrowsingMode, BrowsingMode.Private)
actualtab = null
actualBrowsingMode = null
controller.handleOpen(item, BrowsingMode.Normal)
verify {
openToBrowser(item, BrowsingMode.Normal)
}
assertEquals(item, actualtab)
assertEquals(actualBrowsingMode, BrowsingMode.Normal)
}
@Test
fun `open multiple tabs`() {
val tabs = createFakeTabList(2)
val actualTabs = mutableListOf<RecoverableTab>()
val actualBrowsingModes = mutableListOf<BrowsingMode?>()
val controller = createController(
openToBrowser = { tab, mode ->
actualTabs.add(tab)
actualBrowsingModes.add(mode)
}
)
controller.handleOpen(tabs.toSet(), BrowsingMode.Normal)
verify {
openToBrowser(tabs[0], BrowsingMode.Normal)
openToBrowser(tabs[1], BrowsingMode.Normal)
}
assertEquals(2, actualTabs.size)
assertEquals(tabs[0], actualTabs[0])
assertEquals(tabs[1], actualTabs[1])
assertEquals(BrowsingMode.Normal, actualBrowsingModes[0])
assertEquals(BrowsingMode.Normal, actualBrowsingModes[1])
actualTabs.clear()
actualBrowsingModes.clear()
controller.handleOpen(tabs.toSet(), BrowsingMode.Private)
verify {
openToBrowser(tabs[0], BrowsingMode.Private)
openToBrowser(tabs[1], BrowsingMode.Private)
}
assertEquals(2, actualTabs.size)
assertEquals(tabs[0], actualTabs[0])
assertEquals(tabs[1], actualTabs[1])
assertEquals(BrowsingMode.Private, actualBrowsingModes[0])
assertEquals(BrowsingMode.Private, actualBrowsingModes[1])
}
@Test
fun `handle select tab`() {
val selectedTab = createFakeTab()
controller.handleSelect(selectedTab)
createController().handleSelect(selectedTab)
verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Select(selectedTab)) }
}
@ -122,7 +135,7 @@ class DefaultRecentlyClosedControllerTest {
fun `handle deselect tab`() {
val deselectedTab = createFakeTab()
controller.handleDeselect(deselectedTab)
createController().handleDeselect(deselectedTab)
verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Deselect(deselectedTab)) }
}
@ -131,7 +144,7 @@ class DefaultRecentlyClosedControllerTest {
fun handleDelete() {
val item: RecoverableTab = mockk(relaxed = true)
controller.handleDelete(item)
createController().handleDelete(item)
verify {
browserStore.dispatch(RecentlyClosedAction.RemoveClosedTabAction(item))
@ -142,7 +155,7 @@ class DefaultRecentlyClosedControllerTest {
fun `delete multiple tabs`() {
val tabs = createFakeTabList(2)
controller.handleDelete(tabs.toSet())
createController().handleDelete(tabs.toSet())
verify {
browserStore.dispatch(RecentlyClosedAction.RemoveClosedTabAction(tabs[0]))
@ -152,7 +165,7 @@ class DefaultRecentlyClosedControllerTest {
@Test
fun handleNavigateToHistory() {
controller.handleNavigateToHistory()
createController().handleNavigateToHistory()
verify {
navController.navigate(
@ -170,7 +183,7 @@ class DefaultRecentlyClosedControllerTest {
val clipdata = slot<ClipData>()
controller.handleCopyUrl(item)
createController().handleCopyUrl(item)
verify {
clipboardManager.setPrimaryClip(capture(clipdata))
@ -187,7 +200,7 @@ class DefaultRecentlyClosedControllerTest {
fun handleShare() {
val item = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
controller.handleShare(item)
createController().handleShare(item)
verify {
navController.navigate(
@ -204,7 +217,7 @@ class DefaultRecentlyClosedControllerTest {
fun `share multiple tabs`() {
val tabs = createFakeTabList(2)
controller.handleShare(tabs.toSet())
createController().handleShare(tabs.toSet())
verify {
val data = arrayOf(
@ -219,7 +232,7 @@ class DefaultRecentlyClosedControllerTest {
@Test
fun handleRestore() {
controller.handleRestore(mockedTab)
createController().handleRestore(mockedTab)
dispatcher.advanceUntilIdle()
@ -230,11 +243,27 @@ class DefaultRecentlyClosedControllerTest {
fun `exist multi-select mode when back is pressed`() {
every { recentlyClosedStore.state.selectedTabs } returns createFakeTabList(3).toSet()
controller.handleBackPressed()
createController().handleBackPressed()
verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.DeselectAll) }
}
private fun createController(
openToBrowser: (RecoverableTab, BrowsingMode?) -> Unit = { _, _ -> }
): RecentlyClosedController {
return DefaultRecentlyClosedController(
navController,
browserStore,
recentlyClosedStore,
tabsUseCases,
resources,
snackbar,
clipboardManager,
activity,
openToBrowser
)
}
private fun createFakeTab(id: String = "FakeId", url: String = "www.fake.com"): RecoverableTab =
RecoverableTab(id, url)