Skip to content

Commit

Permalink
introduce paparazzi for ui unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Jul 26, 2023
1 parent d9a35d4 commit 68d69a4
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ tripletPlugin = "3.8.1" # 3.8.3
# https://github.com/pinterest/ktlint
ktlint = "0.48.2" # 0.49.1

# https://github.com/cashapp/paparazzi/
paparazzi = "1.3.1"




Expand Down Expand Up @@ -230,3 +233,4 @@ kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
grgit = { id = "org.ajoberstar.grgit", version.ref = "grgit" }
triplet = { id = "com.github.triplet.play", version.ref = "tripletPlugin" }
paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }
1 change: 1 addition & 0 deletions ui/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.kover)
alias(libs.plugins.spotless)
alias(libs.plugins.paparazzi)
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package photos.network.ui.settings.composable

import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.InstantAnimationsRule
import app.cash.paparazzi.Paparazzi
import org.junit.Rule
import org.junit.Test
import com.android.ide.common.rendering.api.SessionParams
import photos.network.api.ServerStatus
import photos.network.ui.common.theme.AppTheme

class SettingsHeader {
@get:Rule
val instantAnimationsRule = InstantAnimationsRule()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.PIXEL_5,
showSystemUi = false,
supportsRtl = true,
renderingMode = SessionParams.RenderingMode.SHRINK
)

@Test
fun unauthorized_dark() {
paparazzi.snapshot {
AppTheme(useDarkTheme = true) {
SettingsHeader(serverStatus = ServerStatus.UNAUTHORIZED)
}
}
}

@Test
fun unauthorized_light() {
paparazzi.snapshot {
AppTheme(useDarkTheme = false) {
SettingsHeader(serverStatus = ServerStatus.UNAUTHORIZED)
}
}
}

@Test
fun unavailable_dark() {
paparazzi.snapshot {
AppTheme(useDarkTheme = true) {
SettingsHeader(serverStatus = ServerStatus.UNAVAILABLE)
}
}
}

@Test
fun unavailable_light() {
paparazzi.snapshot {
AppTheme(useDarkTheme = false) {
SettingsHeader(serverStatus = ServerStatus.UNAVAILABLE)
}
}
}

@Test
fun progress_dark() {
paparazzi.snapshot {
AppTheme(useDarkTheme = true) {
SettingsHeader(serverStatus = ServerStatus.PROGRESS)
}
}
}

@Test
fun progress_light() {
paparazzi.snapshot {
AppTheme(useDarkTheme = false) {
SettingsHeader(serverStatus = ServerStatus.PROGRESS)
}
}
}

@Test
fun available_dark() {
paparazzi.snapshot {
AppTheme(useDarkTheme = true) {
SettingsHeader(serverStatus = ServerStatus.AVAILABLE)
}
}
}

@Test
fun available_light() {
paparazzi.snapshot {
AppTheme(useDarkTheme = false) {
SettingsHeader(serverStatus = ServerStatus.AVAILABLE)
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68d69a4

Please sign in to comment.