Skip to content

Commit

Permalink
For mozilla-mobile#27055: check whether applied wallpaper name is blank
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTighe authored and mergify[bot] committed Sep 20, 2022
1 parent 16f490e commit 414c569
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ class HomeFragment : Fragment() {
when {
!shouldEnableWallpaper() ||
(wallpaperName == lastAppliedWallpaperName && !orientationChange) -> return
wallpaperName == Wallpaper.defaultName -> {
Wallpaper.nameIsDefault(wallpaperName) -> {
binding.wallpaperImageView.isVisible = false
lastAppliedWallpaperName = wallpaperName
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/org/mozilla/fenix/wallpapers/Wallpaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ data class Wallpaper(
null
}
}

/**
* Check if a wallpaper name matches the default. Considers empty strings to be default
* since that likely means a wallpaper has never been set.
*
* @param name The name to check.
*/
fun nameIsDefault(name: String): Boolean = name.isEmpty() || name == defaultName
}

/**
Expand Down
28 changes: 28 additions & 0 deletions app/src/test/java/org/mozilla/fenix/wallpapers/WallpaperTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.mozilla.fenix.wallpapers

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class WallpaperTest {
@Test
fun `GIVEN blank wallpaper name WHEN checking whether is default THEN is default`() {
val result = Wallpaper.nameIsDefault("")

assertTrue(result)
}

@Test
fun `GIVEN the default wallpaper is set to be shown WHEN checking whether the current wallpaper should be default THEN return true`() {
val result = Wallpaper.nameIsDefault("default")

assertTrue(result)
}

@Test
fun `GIVEN a custom wallpaper is set to be shown WHEN checking whether the current wallpaper should be default THEN return false`() {
val result = Wallpaper.nameIsDefault("wally world")

assertFalse(result)
}
}

0 comments on commit 414c569

Please sign in to comment.