Unverified Commit c6de8632 authored by Mugurell's avatar Mugurell Committed by GitHub
Browse files

For #16461 - Ensure the proper items order after exiting Multiselect (#16482)

parent a06b30a7
...@@ -21,6 +21,7 @@ import mozilla.components.browser.storage.sync.SyncedDeviceTabs ...@@ -21,6 +21,7 @@ import mozilla.components.browser.storage.sync.SyncedDeviceTabs
import mozilla.components.feature.syncedtabs.view.SyncedTabsView import mozilla.components.feature.syncedtabs.view.SyncedTabsView
import mozilla.components.lib.state.ext.flowScoped import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.sync.ListenerDelegate import org.mozilla.fenix.sync.ListenerDelegate
import org.mozilla.fenix.sync.SyncedTabsAdapter import org.mozilla.fenix.sync.SyncedTabsAdapter
import org.mozilla.fenix.sync.ext.toAdapterList import org.mozilla.fenix.sync.ext.toAdapterList
...@@ -50,7 +51,11 @@ class SyncedTabsController( ...@@ -50,7 +51,11 @@ class SyncedTabsController(
.collect { mode -> .collect { mode ->
when (mode) { when (mode) {
is TabTrayDialogFragmentState.Mode.Normal -> { is TabTrayDialogFragmentState.Mode.Normal -> {
concatAdapter.addAdapter(0, adapter) if (view.context.settings().gridTabView) {
concatAdapter.addAdapter(adapter)
} else {
concatAdapter.addAdapter(0, adapter)
}
} }
is TabTrayDialogFragmentState.Mode.MultiSelect -> { is TabTrayDialogFragmentState.Mode.MultiSelect -> {
concatAdapter.removeAdapter(adapter) concatAdapter.removeAdapter(adapter)
......
...@@ -25,6 +25,7 @@ import org.junit.Rule ...@@ -25,6 +25,7 @@ import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.sync.SyncedTabsViewHolder import org.mozilla.fenix.sync.SyncedTabsViewHolder
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentAction.EnterMultiSelectMode import org.mozilla.fenix.tabtray.TabTrayDialogFragmentAction.EnterMultiSelectMode
...@@ -54,6 +55,7 @@ class SyncedTabsControllerTest { ...@@ -54,6 +55,7 @@ class SyncedTabsControllerTest {
every { lifecycleOwner.lifecycle } returns lifecycle every { lifecycleOwner.lifecycle } returns lifecycle
concatAdapter = mockk() concatAdapter = mockk()
every { concatAdapter.addAdapter(any()) } returns true
every { concatAdapter.addAdapter(any(), any()) } returns true every { concatAdapter.addAdapter(any(), any()) } returns true
every { concatAdapter.removeAdapter(any()) } returns true every { concatAdapter.removeAdapter(any()) } returns true
...@@ -128,12 +130,22 @@ class SyncedTabsControllerTest { ...@@ -128,12 +130,22 @@ class SyncedTabsControllerTest {
@Test @Test
fun `concatAdapter updated on mode changes`() = testDispatcher.runBlockingTest { fun `concatAdapter updated on mode changes`() = testDispatcher.runBlockingTest {
store.dispatch(EnterMultiSelectMode).joinBlocking() // When returning from Multiselect while in grid view the adapter should be added at the end
every { view.context.settings().gridTabView } returns true
store.dispatch(EnterMultiSelectMode).joinBlocking()
verify { concatAdapter.removeAdapter(any()) } verify { concatAdapter.removeAdapter(any()) }
store.dispatch(ExitMultiSelectMode).joinBlocking() store.dispatch(ExitMultiSelectMode).joinBlocking()
verify { concatAdapter.addAdapter(any()) }
// When returning from Multiselect while in list view the adapter should be added at the front
every { view.context.settings().gridTabView } returns false
store.dispatch(EnterMultiSelectMode).joinBlocking()
verify { concatAdapter.removeAdapter(any()) }
store.dispatch(ExitMultiSelectMode).joinBlocking()
verify { concatAdapter.addAdapter(0, any()) } verify { concatAdapter.addAdapter(0, any()) }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment