Closes #26971: fix wallpaper onboarding display condition
This commit is contained in:
parent
7fc96b01b2
commit
cc30e3dc5a
|
@ -56,7 +56,7 @@ import org.mozilla.fenix.gleanplumb.MessageController
|
|||
import org.mozilla.fenix.home.HomeFragment
|
||||
import org.mozilla.fenix.home.HomeFragmentDirections
|
||||
import org.mozilla.fenix.home.Mode
|
||||
import org.mozilla.fenix.onboarding.WallpaperOnboardingDialogFragment
|
||||
import org.mozilla.fenix.onboarding.WallpaperOnboardingDialogFragment.Companion.THUMBNAILS_SELECTION_COUNT
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
import org.mozilla.fenix.settings.SupportUtils.SumoTopic.PRIVATE_BROWSING_MYTHS
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
@ -510,16 +510,19 @@ class DefaultSessionControlController(
|
|||
}
|
||||
|
||||
override fun handleShowWallpapersOnboardingDialog(state: WallpaperState): Boolean {
|
||||
if (state.availableWallpapers.all { it.thumbnailFileState == Wallpaper.ImageFileState.Downloaded } &&
|
||||
state.availableWallpapers.size >= WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT
|
||||
) {
|
||||
navController.nav(
|
||||
R.id.homeFragment,
|
||||
HomeFragmentDirections.actionGlobalWallpaperOnboardingDialog(),
|
||||
)
|
||||
return true
|
||||
return state.availableWallpapers.filter { wallpaper ->
|
||||
wallpaper.thumbnailFileState == Wallpaper.ImageFileState.Downloaded
|
||||
}.size.let { downloadedCount ->
|
||||
// We only display the dialog if enough thumbnails have been downloaded for it.
|
||||
downloadedCount >= THUMBNAILS_SELECTION_COUNT
|
||||
}.also { showOnboarding ->
|
||||
if (showOnboarding) {
|
||||
navController.nav(
|
||||
R.id.homeFragment,
|
||||
HomeFragmentDirections.actionGlobalWallpaperOnboardingDialog(),
|
||||
)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun handleReadPrivacyNoticeClicked() {
|
||||
|
|
|
@ -82,7 +82,7 @@ class WallpaperOnboardingDialogFragment : BottomSheetDialogFragment() {
|
|||
setContent {
|
||||
FirefoxTheme {
|
||||
val wallpapers = appStore.observeAsComposableState { state ->
|
||||
state.wallpaperState.availableWallpapers.take(THUMBNAILS_COUNT)
|
||||
state.wallpaperState.availableWallpapers.take(THUMBNAILS_SELECTION_COUNT)
|
||||
}.value ?: listOf()
|
||||
val currentWallpaper = appStore.observeAsComposableState { state ->
|
||||
state.wallpaperState.currentWallpaper
|
||||
|
@ -127,6 +127,6 @@ class WallpaperOnboardingDialogFragment : BottomSheetDialogFragment() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val THUMBNAILS_COUNT = 6
|
||||
const val THUMBNAILS_SELECTION_COUNT = 6
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,11 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|||
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
|
||||
import org.mozilla.fenix.home.recenttabs.RecentTab
|
||||
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
|
||||
import org.mozilla.fenix.onboarding.WallpaperOnboardingDialogFragment.Companion.THUMBNAILS_SELECTION_COUNT
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
import org.mozilla.fenix.wallpapers.Wallpaper
|
||||
import org.mozilla.fenix.wallpapers.WallpaperState
|
||||
import mozilla.components.feature.tab.collections.Tab as ComponentTab
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class) // For gleanTestRule
|
||||
|
@ -878,6 +881,61 @@ class DefaultSessionControlControllerTest {
|
|||
assertNull(TopSites.remove.testGetValue()!!.single().extra)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN exactly the required amount of downloaded thumbnails with no errors WHEN handling wallpaper dialog THEN dialog is shown`() {
|
||||
val wallpaperState = WallpaperState.default.copy(
|
||||
availableWallpapers = makeFakeRemoteWallpapers(
|
||||
THUMBNAILS_SELECTION_COUNT,
|
||||
false,
|
||||
),
|
||||
)
|
||||
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN more than required amount of downloaded thumbnails with no errors WHEN handling wallpaper dialog THEN dialog is shown`() {
|
||||
val wallpaperState = WallpaperState.default.copy(
|
||||
availableWallpapers = makeFakeRemoteWallpapers(
|
||||
THUMBNAILS_SELECTION_COUNT,
|
||||
false,
|
||||
),
|
||||
)
|
||||
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN more than required amount of downloaded thumbnails with some errors WHEN handling wallpaper dialog THEN dialog is shown`() {
|
||||
val wallpaperState = WallpaperState.default.copy(
|
||||
availableWallpapers = makeFakeRemoteWallpapers(
|
||||
THUMBNAILS_SELECTION_COUNT + 2,
|
||||
true,
|
||||
),
|
||||
)
|
||||
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fewer than the required amount of downloaded thumbnails WHEN handling wallpaper dialog THEN the dialog is not shown`() {
|
||||
val wallpaperState = WallpaperState.default.copy(
|
||||
availableWallpapers = makeFakeRemoteWallpapers(
|
||||
THUMBNAILS_SELECTION_COUNT - 1,
|
||||
false,
|
||||
),
|
||||
)
|
||||
assert(!createController().handleShowWallpapersOnboardingDialog(wallpaperState))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN exactly the required amount of downloaded thumbnails with errors WHEN handling wallpaper dialog THEN the dialog is not shown`() {
|
||||
val wallpaperState = WallpaperState.default.copy(
|
||||
availableWallpapers = makeFakeRemoteWallpapers(
|
||||
THUMBNAILS_SELECTION_COUNT,
|
||||
true,
|
||||
),
|
||||
)
|
||||
assert(!createController().handleShowWallpapersOnboardingDialog(wallpaperState))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleStartBrowsingClicked() {
|
||||
var hideOnboardingInvoked = false
|
||||
|
@ -1255,4 +1313,35 @@ class DefaultSessionControlControllerTest {
|
|||
showTabTray = showTabTray,
|
||||
)
|
||||
}
|
||||
|
||||
private fun makeFakeRemoteWallpapers(size: Int, hasError: Boolean): List<Wallpaper> {
|
||||
val list = mutableListOf<Wallpaper>()
|
||||
for (i in 0 until size) {
|
||||
if (hasError && i == 0) {
|
||||
list.add(makeFakeRemoteWallpaper(Wallpaper.ImageFileState.Error))
|
||||
} else {
|
||||
list.add(makeFakeRemoteWallpaper(Wallpaper.ImageFileState.Downloaded))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun makeFakeRemoteWallpaper(
|
||||
thumbnailFileState: Wallpaper.ImageFileState = Wallpaper.ImageFileState.Unavailable,
|
||||
) = Wallpaper(
|
||||
name = "name",
|
||||
collection = Wallpaper.Collection(
|
||||
name = Wallpaper.firefoxCollectionName,
|
||||
heading = null,
|
||||
description = null,
|
||||
availableLocales = null,
|
||||
startDate = null,
|
||||
endDate = null,
|
||||
learnMoreUrl = null,
|
||||
),
|
||||
textColor = null,
|
||||
cardColor = null,
|
||||
thumbnailFileState = thumbnailFileState,
|
||||
assetsFileState = Wallpaper.ImageFileState.Unavailable,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue