Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce paparazzi for ui unit testing #133

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,110 @@
/*
* Copyright 2020-2023 Photos.network developers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package photos.network.ui.settings.composable

import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.InstantAnimationsRule
import app.cash.paparazzi.Paparazzi
import com.android.ide.common.rendering.api.SessionParams
import org.junit.Rule
import org.junit.Test
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.
Loading