[fenix] Bug 1814506 - Add unit tests to cover multi selection of tabs

Three new unit tests have been added to cover cases when
multiple tabs are selected or unselected.
pull/600/head
DreVla 2 years ago committed by mergify[bot]
parent 0c3d638323
commit 18db357649

@ -54,6 +54,7 @@ import org.mozilla.fenix.ext.maxActiveTime
import org.mozilla.fenix.ext.potentialInactiveTabs
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.home.HomeFragment
import org.mozilla.fenix.selection.SelectionHolder
import org.mozilla.fenix.utils.Settings
import java.util.concurrent.TimeUnit
@ -543,6 +544,91 @@ class DefaultTabsTrayControllerTest {
}
}
@Test
fun `GIVEN no tabs selected and the user is not in multi select mode WHEN the user long taps a tab THEN that tab will become selected`() {
trayStore = TabsTrayStore()
val selectionHolder: SelectionHolder<TabSessionState> = mockk {
every { selectedItems } returns emptySet()
}
val controller = spyk(createController())
val tab1 = TabSessionState(
id = "1",
content = ContentState(
url = "www.mozilla.com",
),
)
val tab2 = TabSessionState(
id = "2",
content = ContentState(
url = "www.google.com",
),
)
trayStore.dispatch(TabsTrayAction.ExitSelectMode)
trayStore.waitUntilIdle()
controller.handleMultiSelectClicked(tab1, selectionHolder, "Tabs tray")
verify(exactly = 1) { controller.handleTabSelected(tab1, "Tabs tray") }
controller.handleMultiSelectClicked(tab2, selectionHolder, "Tabs tray")
verify(exactly = 1) { controller.handleTabSelected(tab2, "Tabs tray") }
}
@Test
fun `GIVEN the user is in multi select mode and a tab is selected WHEN the user taps the selected tab THEN the tab will become unselected`() {
trayStore = TabsTrayStore()
val tab1 = TabSessionState(
id = "1",
content = ContentState(
url = "www.mozilla.com",
),
)
val tab2 = TabSessionState(
id = "2",
content = ContentState(
url = "www.google.com",
),
)
val selectionHolder: SelectionHolder<TabSessionState> = mockk {
every { selectedItems } returns setOf(tab1, tab2)
}
val controller = spyk(createController())
trayStore.dispatch(TabsTrayAction.EnterSelectMode)
trayStore.waitUntilIdle()
controller.handleMultiSelectClicked(tab1, selectionHolder, "Tabs tray")
verify(exactly = 1) { controller.handleTabUnselected(tab1) }
controller.handleMultiSelectClicked(tab2, selectionHolder, "Tabs tray")
verify(exactly = 1) { controller.handleTabUnselected(tab2) }
}
@Test
fun `GIVEN at least a tab is selected and the user is in multi select mode WHEN the user taps a tab THEN that tab will become selected`() {
trayStore = spyk(TabsTrayStore())
trayStore.dispatch(TabsTrayAction.EnterSelectMode)
trayStore.waitUntilIdle()
val controller = spyk(createController())
val tab1 = TabSessionState(
id = "1",
content = ContentState(
url = "www.mozilla.com",
),
)
val selectionHolder: SelectionHolder<TabSessionState> = mockk {
every { selectedItems } returns setOf(tab1)
}
val tab2 = TabSessionState(
id = "2",
content = ContentState(
url = "www.google.com",
),
)
controller.handleMultiSelectClicked(tab2, selectionHolder, "Tabs tray")
verify(exactly = 1) { trayStore.dispatch(TabsTrayAction.AddSelectTab(tab2)) }
}
@Test
fun `GIVEN the user selects only the current tab WHEN the user forces tab to be inactive THEN tab does not become inactive`() {
val currentTab = TabSessionState(content = mockk(), id = "currentTab", createdAt = 11)

Loading…
Cancel
Save