From ec1d6dfc7d5089b2975f5ce3f71f725bea3bca37 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Tue, 15 Mar 2022 22:55:29 -0400 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/24114 - Check feature settings to show and hide home screen sections --- .../home/sessioncontrol/SessionControlView.kt | 16 ++++--- .../sessioncontrol/SessionControlViewTest.kt | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt index 56a5e20767..55b5216cf6 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt @@ -30,6 +30,7 @@ import org.mozilla.fenix.utils.Settings @Suppress("ComplexMethod", "LongParameterList") @VisibleForTesting internal fun normalModeAdapterItems( + settings: Settings, topSites: List, collections: List, expandedCollections: Set, @@ -50,23 +51,23 @@ internal fun normalModeAdapterItems( items.add(AdapterItem.ExperimentDefaultBrowserCard) } - if (topSites.isNotEmpty()) { + if (settings.showTopSitesFeature && topSites.isNotEmpty()) { items.add(AdapterItem.TopSitePager(topSites)) } - if (recentTabs.isNotEmpty()) { + if (settings.showRecentTabsFeature && recentTabs.isNotEmpty()) { shouldShowCustomizeHome = true items.add(AdapterItem.RecentTabsHeader) items.add(AdapterItem.RecentTabItem) } - if (recentBookmarks.isNotEmpty()) { + if (settings.showRecentBookmarksFeature && recentBookmarks.isNotEmpty()) { shouldShowCustomizeHome = true items.add(AdapterItem.RecentBookmarksHeader) items.add(AdapterItem.RecentBookmarks) } - if (recentVisits.isNotEmpty()) { + if (settings.historyMetadataUIFeature && recentVisits.isNotEmpty()) { shouldShowCustomizeHome = true items.add(AdapterItem.RecentVisitsHeader) items.add(AdapterItem.RecentVisitsItems) @@ -80,7 +81,7 @@ internal fun normalModeAdapterItems( showCollections(collections, expandedCollections, items) } - if (pocketStories.isNotEmpty()) { + if (settings.showPocketRecommendationsFeature && pocketStories.isNotEmpty()) { shouldShowCustomizeHome = true items.add(AdapterItem.PocketStoriesItem) items.add(AdapterItem.PocketCategoriesItem) @@ -148,8 +149,9 @@ private fun onboardingAdapterItems(onboardingState: OnboardingState): List = when (mode) { +private fun AppState.toAdapterList(settings: Settings): List = when (mode) { is Mode.Normal -> normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -219,6 +221,6 @@ class SessionControlView( if (shouldReportMetrics) interactor.reportSessionMetrics(state) - sessionControlAdapter.submitList(state.toAdapterList()) + sessionControlAdapter.submitList(state.toAdapterList(view.context.settings())) } } diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt index 2beb6db478..ff4e6fb5f0 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt @@ -133,6 +133,7 @@ class SessionControlViewTest { @Test fun `GIVEN recent Bookmarks WHEN normalModeAdapterItems is called THEN add a customize home button`() { + val settings: Settings = mockk() val topSites = emptyList() val collections = emptyList() val expandedCollections = emptySet() @@ -141,7 +142,14 @@ class SessionControlViewTest { val historyMetadata = emptyList() val pocketArticles = emptyList() + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -161,6 +169,7 @@ class SessionControlViewTest { @Test fun `GIVEN recent tabs WHEN normalModeAdapterItems is called THEN add a customize home button`() { + val settings: Settings = mockk() val topSites = emptyList() val collections = emptyList() val expandedCollections = emptySet() @@ -169,7 +178,14 @@ class SessionControlViewTest { val historyMetadata = emptyList() val pocketArticles = emptyList() + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -189,6 +205,7 @@ class SessionControlViewTest { @Test fun `GIVEN history metadata WHEN normalModeAdapterItems is called THEN add a customize home button`() { + val settings: Settings = mockk() val topSites = emptyList() val collections = emptyList() val expandedCollections = emptySet() @@ -197,7 +214,14 @@ class SessionControlViewTest { val historyMetadata = listOf(RecentHistoryGroup("title", emptyList())) val pocketArticles = emptyList() + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -217,6 +241,7 @@ class SessionControlViewTest { @Test fun `GIVEN pocket articles WHEN normalModeAdapterItems is called THEN add a customize home button`() { + val settings: Settings = mockk() val topSites = emptyList() val collections = emptyList() val expandedCollections = emptySet() @@ -225,7 +250,14 @@ class SessionControlViewTest { val historyMetadata = emptyList() val pocketArticles = listOf(PocketRecommendedStory("", "", "", "", "", 1, 1)) + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -246,6 +278,7 @@ class SessionControlViewTest { @Test fun `GIVEN none recentBookmarks,recentTabs, historyMetadata or pocketArticles WHEN normalModeAdapterItems is called THEN the customize home button is not added`() { + val settings: Settings = mockk() val topSites = emptyList() val collections = emptyList() val expandedCollections = emptySet() @@ -254,7 +287,14 @@ class SessionControlViewTest { val historyMetadata = emptyList() val pocketArticles = emptyList() + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections, @@ -271,6 +311,7 @@ class SessionControlViewTest { @Test fun `GIVEN all items THEN top placeholder item is always the first item`() { + val settings: Settings = mockk() val collection = mockk { every { id } returns 123L } @@ -282,7 +323,14 @@ class SessionControlViewTest { val historyMetadata = listOf(mockk()) val pocketArticles = listOf(mockk()) + every { settings.showTopSitesFeature } returns true + every { settings.showRecentTabsFeature } returns true + every { settings.showRecentBookmarksFeature } returns true + every { settings.historyMetadataUIFeature } returns true + every { settings.showPocketRecommendationsFeature } returns true + val results = normalModeAdapterItems( + settings, topSites, collections, expandedCollections,