From f20c7ed527b898876f8c7b147787766ffe72bd30 Mon Sep 17 00:00:00 2001 From: Mihai Adrian Carare <48995920+mcarare@users.noreply.github.com> Date: Thu, 17 Jun 2021 13:57:50 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/19813: Invalidate tab tray adapter structure on screen rotation. (https://github.com/mozilla-mobile/fenix/pull/20044) --- .../fenix/tabstray/TabsTrayFragment.kt | 12 +++- .../fenix/tabstray/TabsTrayFragmentTest.kt | 56 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt index 01fc7d644d..c7233d11a1 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt @@ -271,6 +271,10 @@ class TabsTrayFragment : AppCompatDialogFragment() { super.onConfigurationChanged(newConfig) trayBehaviorManager.updateDependingOnOrientation(newConfig.orientation) + + if (requireContext().settings().gridTabView) { + tabsTray.adapter?.notifyDataSetChanged() + } } @VisibleForTesting @@ -287,9 +291,11 @@ class TabsTrayFragment : AppCompatDialogFragment() { getString(R.string.snackbar_deleted_undo), { requireComponents.useCases.tabsUseCases.undo.invoke() - tabLayoutMediator.withFeature { it.selectTabAtPosition( - if (isPrivate) Page.PrivateTabs.ordinal else Page.NormalTabs.ordinal - ) } + tabLayoutMediator.withFeature { + it.selectTabAtPosition( + if (isPrivate) Page.PrivateTabs.ordinal else Page.NormalTabs.ordinal + ) + } }, operation = { }, elevation = ELEVATION, diff --git a/app/src/test/java/org/mozilla/fenix/tabstray/TabsTrayFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/tabstray/TabsTrayFragmentTest.kt index df2cacfcc4..d7a088ac95 100644 --- a/app/src/test/java/org/mozilla/fenix/tabstray/TabsTrayFragmentTest.kt +++ b/app/src/test/java/org/mozilla/fenix/tabstray/TabsTrayFragmentTest.kt @@ -49,6 +49,7 @@ import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.home.HomeScreenViewModel import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor @@ -354,6 +355,7 @@ class TabsTrayFragmentTest { val trayBehaviorManager: TabSheetBehaviorManager = mockk(relaxed = true) fragment.trayBehaviorManager = trayBehaviorManager val newConfiguration = Configuration() + every { context.settings().gridTabView } returns false fragment.onConfigurationChanged(newConfiguration) @@ -370,4 +372,58 @@ class TabsTrayFragmentTest { Assert.assertFalse(behavior.skipCollapsed) assert(behavior.halfExpandedRatio <= 0.001f) } + + @Test + fun `GIVEN a grid TabView WHEN onConfigurationChanged is called THEN the adapter structure is updated`() { + val tray: ViewPager2 = mockk(relaxed = true) + val store: TabsTrayStore = mockk() + val trayInteractor: TabsTrayInteractor = mockk() + val browserInteractor: BrowserTrayInteractor = mockk() + val navigationInteractor: NavigationInteractor = mockk() + val browserStore: BrowserStore = mockk() + + every { fragment.tabsTray } returns tray + every { context.components.core.store } returns browserStore + every { context.settings().gridTabView } returns true + + fragment.setupPager( + context, store, trayInteractor, browserInteractor, navigationInteractor + ) + + val trayBehaviorManager: TabSheetBehaviorManager = mockk(relaxed = true) + fragment.trayBehaviorManager = trayBehaviorManager + + val newConfiguration = Configuration() + + fragment.onConfigurationChanged(newConfiguration) + + verify { tray.adapter?.notifyDataSetChanged() } + } + + @Test + fun `GIVEN a list TabView WHEN onConfigurationChanged is called THEN the adapter structure is NOT updated`() { + val tray: ViewPager2 = mockk(relaxed = true) + val store: TabsTrayStore = mockk() + val trayInteractor: TabsTrayInteractor = mockk() + val browserInteractor: BrowserTrayInteractor = mockk() + val navigationInteractor: NavigationInteractor = mockk() + val browserStore: BrowserStore = mockk() + + every { fragment.tabsTray } returns tray + every { context.components.core.store } returns browserStore + every { context.settings().gridTabView } returns false + + fragment.setupPager( + context, store, trayInteractor, browserInteractor, navigationInteractor + ) + + val trayBehaviorManager: TabSheetBehaviorManager = mockk(relaxed = true) + fragment.trayBehaviorManager = trayBehaviorManager + + val newConfiguration = Configuration() + + fragment.onConfigurationChanged(newConfiguration) + + verify(exactly = 0) { tray.adapter?.notifyDataSetChanged() } + } }