Fixes #26050: show jump back in when only synced tab available

This commit is contained in:
MatthewTighe 2022-07-18 13:13:16 -07:00 committed by mergify[bot]
parent b454684090
commit f58f1541ce
4 changed files with 73 additions and 18 deletions

View File

@ -15,7 +15,9 @@ import org.mozilla.fenix.home.blocklist.BlocklistHandler
import org.mozilla.fenix.home.pocket.POCKET_STORIES_DEFAULT_CATEGORY_NAME
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
import org.mozilla.fenix.home.pocket.PocketStory
import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTabState
import org.mozilla.fenix.home.recenttabs.RecentTab.SearchGroup
import org.mozilla.fenix.utils.Settings
/**
* Total count of all stories to show irrespective of their type.
@ -180,3 +182,12 @@ fun AppState.filterState(blocklistHandler: BlocklistHandler): AppState =
recentHistory = recentHistory.filteredByBlocklist()
)
}
/**
* Determines whether a recent tab section should be shown, based on user preference
* and the availability of local or Synced tabs.
*/
fun AppState.shouldShowRecentTabs(settings: Settings): Boolean {
val hasTab = recentTabs.isNotEmpty() || recentSyncedTabState is RecentSyncedTabState.Success
return settings.showRecentTabsFeature && hasTab
}

View File

@ -15,11 +15,11 @@ import mozilla.components.service.pocket.PocketStory
import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.shouldShowRecentTabs
import org.mozilla.fenix.gleanplumb.Message
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
import org.mozilla.fenix.home.recenttabs.RecentTab
import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem
import org.mozilla.fenix.onboarding.JumpBackInCFRDialog
import org.mozilla.fenix.utils.Settings
@ -36,7 +36,7 @@ internal fun normalModeAdapterItems(
recentBookmarks: List<RecentBookmark>,
showCollectionsPlaceholder: Boolean,
nimbusMessageCard: Message? = null,
recentTabs: List<RecentTab>,
showRecentTab: Boolean,
recentVisits: List<RecentlyVisitedItem>,
pocketStories: List<PocketStory>
): List<AdapterItem> {
@ -54,7 +54,7 @@ internal fun normalModeAdapterItems(
items.add(AdapterItem.TopSitePager(topSites))
}
if (settings.showRecentTabsFeature && recentTabs.isNotEmpty()) {
if (showRecentTab) {
shouldShowCustomizeHome = true
items.add(AdapterItem.RecentTabsHeader)
items.add(AdapterItem.RecentTabItem)
@ -157,7 +157,7 @@ private fun AppState.toAdapterList(settings: Settings): List<AdapterItem> = when
recentBookmarks,
showCollectionPlaceholder,
messaging.messageToShow,
recentTabs,
shouldShowRecentTabs(settings),
recentHistory,
pocketStories
)

View File

@ -4,11 +4,13 @@
package org.mozilla.fenix.ext
import io.mockk.every
import io.mockk.mockk
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStoryCaps
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStoryShim
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
@ -18,7 +20,9 @@ import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.home.pocket.POCKET_STORIES_DEFAULT_CATEGORY_NAME
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesSelectedCategory
import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTabState
import org.mozilla.fenix.home.recenttabs.RecentTab
import org.mozilla.fenix.utils.Settings
import java.util.concurrent.TimeUnit
import kotlin.random.Random
@ -511,6 +515,53 @@ class AppStateTest {
assertNull(state.recentSearchGroup)
}
@Test
fun `GIVEN recent tabs disabled in settings WHEN checking to show tabs THEN section should not be shown`() {
val settings = mockk<Settings> {
every { showRecentTabsFeature } returns false
}
val state = AppState()
Assert.assertFalse(state.shouldShowRecentTabs(settings))
}
@Test
fun `GIVEN only local tabs WHEN checking to show tabs THEN section should be shown`() {
val settings = mockk<Settings> {
every { showRecentTabsFeature } returns true
}
val state = AppState(recentTabs = listOf(mockk()))
assertTrue(state.shouldShowRecentTabs(settings))
}
@Test
fun `GIVEN only remote tabs WHEN checking to show tabs THEN section should be shown`() {
val settings = mockk<Settings> {
every { showRecentTabsFeature } returns true
}
val state = AppState(recentSyncedTabState = RecentSyncedTabState.Success(mockk()))
assertTrue(state.shouldShowRecentTabs(settings))
}
@Test
fun `GIVEN local and remote tabs WHEN checking to show tabs THEN section should be shown`() {
val settings = mockk<Settings> {
every { showRecentTabsFeature } returns true
}
val state = AppState(
recentTabs = listOf(mockk()),
recentSyncedTabState = RecentSyncedTabState.Success(mockk())
)
assertTrue(state.shouldShowRecentTabs(settings))
}
}
private fun getFakePocketStories(

View File

@ -138,7 +138,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf(RecentBookmark())
val recentTabs = emptyList<RecentTab.Tab>()
val historyMetadata = emptyList<RecentHistoryGroup>()
val pocketStories = emptyList<PocketStory>()
@ -156,7 +155,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
false,
historyMetadata,
pocketStories
)
@ -174,7 +173,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf(RecentBookmark())
val recentTabs = emptyList<RecentTab.Tab>()
val historyMetadata = emptyList<RecentHistoryGroup>()
val pocketStories = emptyList<PocketStory>()
val nimbusMessageCard: Message = mockk()
@ -193,7 +191,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
nimbusMessageCard,
recentTabs,
false,
historyMetadata,
pocketStories
)
@ -208,7 +206,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf<RecentBookmark>()
val recentTabs = listOf<RecentTab.Tab>(mockk())
val historyMetadata = emptyList<RecentHistoryGroup>()
val pocketStories = emptyList<PocketStory>()
@ -226,7 +223,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
true,
historyMetadata,
pocketStories
)
@ -244,7 +241,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf<RecentBookmark>()
val recentTabs = emptyList<RecentTab.Tab>()
val historyMetadata = listOf(RecentHistoryGroup("title", emptyList()))
val pocketStories = emptyList<PocketStory>()
@ -262,7 +258,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
false,
historyMetadata,
pocketStories
)
@ -280,7 +276,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf<RecentBookmark>()
val recentTabs = emptyList<RecentTab.Tab>()
val historyMetadata = emptyList<RecentHistoryGroup>()
val pocketStories = listOf(PocketRecommendedStory("", "", "", "", "", 1, 1))
@ -298,7 +293,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
false,
historyMetadata,
pocketStories
)
@ -317,7 +312,6 @@ class SessionControlViewTest {
val collections = emptyList<TabCollection>()
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf<RecentBookmark>()
val recentTabs = emptyList<RecentTab.Tab>()
val historyMetadata = emptyList<RecentHistoryGroup>()
val pocketStories = emptyList<PocketStory>()
@ -335,7 +329,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
false,
historyMetadata,
pocketStories
)
@ -353,7 +347,6 @@ class SessionControlViewTest {
val collections = listOf(collection)
val expandedCollections = emptySet<Long>()
val recentBookmarks = listOf<RecentBookmark>(mockk())
val recentTabs = listOf<RecentTab.Tab>(mockk())
val historyMetadata = listOf<RecentHistoryGroup>(mockk())
val pocketStories = listOf<PocketStory>(mockk())
@ -371,7 +364,7 @@ class SessionControlViewTest {
recentBookmarks,
false,
null,
recentTabs,
true,
historyMetadata,
pocketStories
)