From 78cdc095ffb02d0c6ddc2bfccbd9b052e46e1d5b Mon Sep 17 00:00:00 2001 From: DreVla Date: Thu, 21 Sep 2023 13:23:48 +0300 Subject: [PATCH] Bug 1811976 - Hide Sync FAB in TabsTray when user not signed in If there is no user signed in, the SYNC FAB should not be displayed in the sync page of the tabs tray. --- .../mozilla/fenix/ui/robots/TabDrawerRobot.kt | 7 ---- .../tabstray/FloatingActionButtonBinding.kt | 32 +++++++++++-------- .../org/mozilla/fenix/tabstray/TabsTrayFab.kt | 20 ++++++++++-- .../fenix/tabstray/TabsTrayFragment.kt | 2 ++ .../FloatingActionButtonBindingTest.kt | 22 +++++++++++++ 5 files changed, 60 insertions(+), 23 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt index f6f93472c..277f58e7e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt @@ -40,7 +40,6 @@ import org.mozilla.fenix.R import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION import org.mozilla.fenix.helpers.Constants.RETRY_COUNT import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists -import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndDescriptionExists import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText @@ -297,12 +296,6 @@ class TabDrawerRobot { itemContainingText(getStringResource(R.string.synced_tabs_sign_in_message)), itemContainingText(getStringResource(R.string.sync_sign_in)), ) - assertItemWithResIdAndDescriptionExists( - itemWithResIdAndDescription( - "$packageName:id/new_tab_button", - getStringResource(R.string.resync_button_content_description), - ), - ) } class Transition { diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/FloatingActionButtonBinding.kt b/app/src/main/java/org/mozilla/fenix/tabstray/FloatingActionButtonBinding.kt index 780703f45..eeb5c06b3 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/FloatingActionButtonBinding.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/FloatingActionButtonBinding.kt @@ -21,6 +21,7 @@ class FloatingActionButtonBinding( store: TabsTrayStore, private val actionButton: ExtendedFloatingActionButton, private val interactor: TabsTrayFabInteractor, + private val isSignedIn: Boolean, ) : AbstractBinding(store) { override suspend fun onState(flow: Flow) { @@ -62,20 +63,25 @@ class FloatingActionButtonBinding( } } Page.SyncedTabs -> { - actionButton.apply { - setText( - when (syncing) { - true -> R.string.sync_syncing_in_progress - false -> R.string.tab_drawer_fab_sync - }, - ) - contentDescription = context.getString(R.string.resync_button_content_description) - extend() - show() - setIconResource(R.drawable.ic_fab_sync) - setOnClickListener { - interactor.onSyncedTabsFabClicked() + if (isSignedIn) { + actionButton.apply { + setText( + when (syncing) { + true -> R.string.sync_syncing_in_progress + false -> R.string.tab_drawer_fab_sync + }, + ) + contentDescription = + context.getString(R.string.resync_button_content_description) + extend() + show() + setIconResource(R.drawable.ic_fab_sync) + setOnClickListener { + interactor.onSyncedTabsFabClicked() + } } + } else { + actionButton.hide() } } } diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFab.kt b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFab.kt index 72af1abae..7774ba002 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFab.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFab.kt @@ -22,6 +22,7 @@ import org.mozilla.fenix.theme.FirefoxTheme * Floating action button for tabs tray. * * @param tabsTrayStore [TabsTrayStore] used to listen for changes to [TabsTrayState]. + * @param isSignedIn Used to know when to show the SYNC FAB when [Page.SyncedTabs] is displayed. * @param onNormalTabsFabClicked Invoked when the fab is clicked in [Page.NormalTabs]. * @param onPrivateTabsFabClicked Invoked when the fab is clicked in [Page.PrivateTabs]. * @param onSyncedTabsFabClicked Invoked when the fab is clicked in [Page.SyncedTabs]. @@ -29,6 +30,7 @@ import org.mozilla.fenix.theme.FirefoxTheme @Composable fun TabsTrayFab( tabsTrayStore: TabsTrayStore, + isSignedIn: Boolean, onNormalTabsFabClicked: () -> Unit, onPrivateTabsFabClicked: () -> Unit, onSyncedTabsFabClicked: () -> Unit, @@ -75,7 +77,7 @@ fun TabsTrayFab( } } - if (isInNormalMode) { + if (isInNormalMode && !(currentPage == Page.SyncedTabs && !isSignedIn)) { FloatingActionButton( icon = icon, modifier = Modifier @@ -99,7 +101,13 @@ private fun TabsTraySyncFabPreview() { ) FirefoxTheme { - TabsTrayFab(store, {}, {}, {}) + TabsTrayFab( + tabsTrayStore = store, + isSignedIn = true, + onNormalTabsFabClicked = {}, + onPrivateTabsFabClicked = {}, + onSyncedTabsFabClicked = {}, + ) } } @@ -112,6 +120,12 @@ private fun TabsTrayPrivateFabPreview() { ), ) FirefoxTheme { - TabsTrayFab(store, {}, {}, {}) + TabsTrayFab( + tabsTrayStore = store, + isSignedIn = true, + onNormalTabsFabClicked = {}, + onPrivateTabsFabClicked = {}, + onSyncedTabsFabClicked = {}, + ) } } 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 10445b802..876f6b850 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt @@ -313,6 +313,7 @@ class TabsTrayFragment : AppCompatDialogFragment() { FirefoxTheme(theme = Theme.getTheme(allowPrivateTheme = false)) { TabsTrayFab( tabsTrayStore = tabsTrayStore, + isSignedIn = requireContext().settings().signedInFxaAccount, onNormalTabsFabClicked = tabsTrayInteractor::onNormalTabsFabClicked, onPrivateTabsFabClicked = tabsTrayInteractor::onPrivateTabsFabClicked, onSyncedTabsFabClicked = tabsTrayInteractor::onSyncedTabsFabClicked, @@ -463,6 +464,7 @@ class TabsTrayFragment : AppCompatDialogFragment() { store = tabsTrayStore, actionButton = fabButtonBinding.newTabButton, interactor = tabsTrayInteractor, + isSignedIn = requireContext().settings().signedInFxaAccount, ), owner = this, view = view, diff --git a/app/src/test/java/org/mozilla/fenix/tabstray/FloatingActionButtonBindingTest.kt b/app/src/test/java/org/mozilla/fenix/tabstray/FloatingActionButtonBindingTest.kt index 695bbf8d7..cbdfc01b9 100644 --- a/app/src/test/java/org/mozilla/fenix/tabstray/FloatingActionButtonBindingTest.kt +++ b/app/src/test/java/org/mozilla/fenix/tabstray/FloatingActionButtonBindingTest.kt @@ -48,6 +48,7 @@ class FloatingActionButtonBindingTest { tabsTrayStore, actionButton, interactor, + true, ) fabBinding.start() @@ -65,6 +66,7 @@ class FloatingActionButtonBindingTest { tabsTrayStore, actionButton, interactor, + true, ) fabBinding.start() @@ -82,6 +84,7 @@ class FloatingActionButtonBindingTest { tabsTrayStore, actionButton, interactor, + true, ) fabBinding.start() @@ -92,6 +95,24 @@ class FloatingActionButtonBindingTest { verify(exactly = 0) { actionButton.hide() } } + @Test + fun `GIVEN the selected tab page is sync WHEN the user is not signed in THEN extend and show is called`() { + val tabsTrayStore = TabsTrayStore(TabsTrayState(selectedPage = Page.SyncedTabs)) + val fabBinding = FloatingActionButtonBinding( + tabsTrayStore, + actionButton, + interactor, + false, + ) + + fabBinding.start() + + verify(exactly = 0) { actionButton.extend() } + verify(exactly = 0) { actionButton.show() } + verify(exactly = 0) { actionButton.shrink() } + verify(exactly = 1) { actionButton.hide() } + } + @Test fun `WHEN selected page is updated THEN button is updated`() { val tabsTrayStore = TabsTrayStore(TabsTrayState(selectedPage = Page.NormalTabs)) @@ -99,6 +120,7 @@ class FloatingActionButtonBindingTest { tabsTrayStore, actionButton, interactor, + true, ) fabBinding.start()