Skip to content

Commit

Permalink
Closes mozilla-mobile#26971: fix naming in SessionControlController t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
mike a committed Sep 15, 2022
1 parent 7f87c62 commit 286d76d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ class DefaultSessionControlController(
return state.availableWallpapers.filter { wallpaper ->
wallpaper.thumbnailFileState == Wallpaper.ImageFileState.Downloaded
}.size.let { downloadedCount ->
downloadedCount >= WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT
// We only display the dialog if enough thumbnails have been downloaded for it.
downloadedCount >= WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT
}.also { isThumbnailsDownloaded ->
if (isThumbnailsDownloaded) {
navController.nav(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -127,6 +127,6 @@ class WallpaperOnboardingDialogFragment : BottomSheetDialogFragment() {
}

companion object {
const val THUMBNAILS_COUNT = 6
const val THUMBNAILS_SELECTION_COUNT = 6
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -882,54 +882,54 @@ class DefaultSessionControlControllerTest {
}

@Test
fun `GIVEN exactly the required amount of downloaded thumbnails WHEN has no errors THEN handleShowWallpapersOnboardingDialog calls the dialog`() {
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(
WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT,
WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT,
false,
),
)
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
}

@Test
fun `GIVEN more than required amount of downloaded thumbnails WHEN has no errors THEN handleShowWallpapersOnboardingDialog calls the dialog`() {
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(
WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT,
WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT,
false,
),
)
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
}

@Test
fun `GIVEN more than required amount of downloaded thumbnails WHEN also has some errors THEN the dialog is called`() {
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(
WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT + 2,
WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT + 2,
true,
),
)
assert(createController().handleShowWallpapersOnboardingDialog(wallpaperState))
}

@Test
fun `GIVEN less than required amount of downloaded thumbnails THEN the dialog is not called`() {
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(
WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT - 1,
WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT - 1,
false,
),
)
assert(!createController().handleShowWallpapersOnboardingDialog(wallpaperState))
}

@Test
fun `GIVEN exactly the required amount of downloaded thumbnails WHEN has errors THEN the dialog is not called`() {
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(
WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT,
WallpaperOnboardingDialogFragment.THUMBNAILS_SELECTION_COUNT,
true,
),
)
Expand Down

0 comments on commit 286d76d

Please sign in to comment.