From d8c5f85ad75c6ca085def75a39e488cc72ea36b6 Mon Sep 17 00:00:00 2001 From: Neil Marietta Date: Tue, 23 May 2023 19:54:05 +0200 Subject: [PATCH] test: Added Basic Paparazzi Snapshot Tests. --- .gitattributes | 1 + .gitlab-ci.yml | 2 +- .../SnapshotAddAccountThemeTest.kt | 40 +++++++++++++++ .../presentation/SnapshotProtonThemeTest.kt | 40 +++++++++++++++ ...otAddAccountThemeTest_addAccountLayout.png | 3 ++ ...SnapshotProtonThemeTest_authHelpLayout.png | 3 ++ gradle/libs.versions.toml | 3 ++ plugins/core/build.gradle.kts | 1 + .../me/proton/core/gradle/plugin/PluginIds.kt | 1 + .../plugin/android/AndroidUiLibraryPlugin.kt | 6 +++ .../presentation/SnapshotProtonThemeTest.kt | 50 +++++++++++++++++++ ...otonThemeTest_protonProgressButtonIdle.png | 3 ++ ...nThemeTest_protonProgressButtonLoading.png | 3 ++ 13 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotAddAccountThemeTest.kt create mode 100644 auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotProtonThemeTest.kt create mode 100644 auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotAddAccountThemeTest_addAccountLayout.png create mode 100644 auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotProtonThemeTest_authHelpLayout.png create mode 100644 presentation/src/test/kotlin/me/proton/core/presentation/SnapshotProtonThemeTest.kt create mode 100644 presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonIdle.png create mode 100644 presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonLoading.png diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..0542767ef --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +**/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index becdd3b0d..4cb23d932 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -164,7 +164,7 @@ unit-tests-and-coverage-report: - assemble stage: test script: - - ./gradlew -Pci --console=plain koverVerify coberturaXmlReport globalLineCoverage :coverage:koverHtmlReport -x :coverage:jacocoToCobertura + - ./gradlew -Pci --console=plain koverVerify coberturaXmlReport globalLineCoverage :coverage:koverHtmlReport -x :coverage:jacocoToCobertura verifyPaparazziDebug coverage: /TotalLineCoverage.*?(\d{1,3}\.\d{0,2})%/ interruptible: true artifacts: diff --git a/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotAddAccountThemeTest.kt b/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotAddAccountThemeTest.kt new file mode 100644 index 000000000..130093874 --- /dev/null +++ b/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotAddAccountThemeTest.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Proton Technologies AG + * This file is part of Proton Technologies AG and ProtonCore. + * + * ProtonCore is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ProtonCore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ProtonCore. If not, see . + */ + +package me.proton.core.auth.presentation + +import android.widget.ScrollView +import app.cash.paparazzi.DeviceConfig +import app.cash.paparazzi.Paparazzi +import org.junit.Rule +import org.junit.Test + +class SnapshotAddAccountThemeTest { + + @get:Rule + val paparazzi = Paparazzi( + deviceConfig = DeviceConfig.PIXEL_5, + theme = "ProtonTheme.AddAccount" + ) + + @Test + fun addAccountLayout() { + val view = paparazzi.inflate(R.layout.activity_add_account) + paparazzi.snapshot(view) + } +} diff --git a/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotProtonThemeTest.kt b/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotProtonThemeTest.kt new file mode 100644 index 000000000..c709a1d75 --- /dev/null +++ b/auth/presentation/src/test/kotlin/me/proton/core/auth/presentation/SnapshotProtonThemeTest.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Proton Technologies AG + * This file is part of Proton Technologies AG and ProtonCore. + * + * ProtonCore is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ProtonCore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ProtonCore. If not, see . + */ + +package me.proton.core.auth.presentation + +import androidx.coordinatorlayout.widget.CoordinatorLayout +import app.cash.paparazzi.DeviceConfig +import app.cash.paparazzi.Paparazzi +import org.junit.Rule +import org.junit.Test + +class SnapshotProtonThemeTest { + + @get:Rule + val paparazzi = Paparazzi( + deviceConfig = DeviceConfig.PIXEL_5, + theme = "ProtonTheme" + ) + + @Test + fun authHelpLayout() { + val view = paparazzi.inflate(R.layout.activity_auth_help) + paparazzi.snapshot(view) + } +} diff --git a/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotAddAccountThemeTest_addAccountLayout.png b/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotAddAccountThemeTest_addAccountLayout.png new file mode 100644 index 000000000..554be83f6 --- /dev/null +++ b/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotAddAccountThemeTest_addAccountLayout.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a22e54880d6aea9dd399999b425764bd277b6b9cdeb6b592d9a587c617429a41 +size 127172 diff --git a/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotProtonThemeTest_authHelpLayout.png b/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotProtonThemeTest_authHelpLayout.png new file mode 100644 index 000000000..7a959c49c --- /dev/null +++ b/auth/presentation/src/test/snapshots/images/me.proton.core.auth.presentation_SnapshotProtonThemeTest_authHelpLayout.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da00e77afada9022ceb7692f962298ca87321ae8ac553d5bf845dc3b91dbfbfd +size 33341 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e3cb47760..d472abbae 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,7 @@ kotlinBinaryCompatibilityValidator = "0.12.1" kotlinx-kover = "0.7.0" jacoco-to-cobertura = "1.1.0" vanniktechPublish = "0.18.0" +paparazzi = "1.2.0" [plugins] benManes-versions-gradle = { id = "com.github.ben-manes.versions", version.ref = "benManesVersions" } @@ -26,6 +27,7 @@ kotlin-gradle = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlinx-kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kotlinx-kover" } jacoco-to-cobertura = { id = "net.razvan.jacoco-to-cobertura", version.ref = "jacoco-to-cobertura" } +paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" } [libraries] android-gradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" } @@ -46,3 +48,4 @@ kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializat kotlinx-kover = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kotlinx-kover" } jacoco-to-cobertura = { module = "net.razvan:JacocoToCoberturaPlugin", version.ref = "jacoco-to-cobertura" } vanniktech-mavenPublish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "vanniktechPublish" } +paparazzi-gradle-plugin = { module = "app.cash.paparazzi:paparazzi-gradle-plugin", version.ref = "paparazzi" } diff --git a/plugins/core/build.gradle.kts b/plugins/core/build.gradle.kts index 3320bcacd..5cfe57e93 100644 --- a/plugins/core/build.gradle.kts +++ b/plugins/core/build.gradle.kts @@ -85,4 +85,5 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin") compileOnly(libs.android.gradle) api(libs.easyGradle.androidDsl) + api(libs.paparazzi.gradle.plugin) } diff --git a/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/PluginIds.kt b/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/PluginIds.kt index 0c000d3ff..f4dd93396 100644 --- a/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/PluginIds.kt +++ b/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/PluginIds.kt @@ -27,4 +27,5 @@ internal object PluginIds { const val kapt = "org.jetbrains.kotlin.kapt" const val kotlinAndroid = "org.jetbrains.kotlin.android" const val kotlinJvm = "org.jetbrains.kotlin.jvm" + const val paparazzi = "app.cash.paparazzi" } diff --git a/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/android/AndroidUiLibraryPlugin.kt b/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/android/AndroidUiLibraryPlugin.kt index 0d0951c1e..aae2e3e9e 100644 --- a/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/android/AndroidUiLibraryPlugin.kt +++ b/plugins/core/src/main/kotlin/me/proton/core/gradle/plugin/android/AndroidUiLibraryPlugin.kt @@ -34,4 +34,10 @@ public class AndroidUiLibraryPlugin : BaseAndroidPlugin. + */ + +package me.proton.core.presentation + +import app.cash.paparazzi.DeviceConfig +import app.cash.paparazzi.Paparazzi +import me.proton.core.presentation.ui.view.ProtonProgressButton +import org.junit.Rule +import org.junit.Test + +class SnapshotProtonThemeTest { + + @get:Rule + val paparazzi = Paparazzi( + deviceConfig = DeviceConfig.PIXEL_5, + theme = "ProtonTheme" + ) + + @Test + fun protonProgressButtonIdle() { + val view = ProtonProgressButton(paparazzi.context) + view.text = "Button" + view.setIdle() + paparazzi.snapshot(view) + } + + @Test + fun protonProgressButtonLoading() { + val view = ProtonProgressButton(paparazzi.context) + view.text = "Button" + view.setLoading() + paparazzi.snapshot(view) + } +} diff --git a/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonIdle.png b/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonIdle.png new file mode 100644 index 000000000..8f5d8b5ca --- /dev/null +++ b/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonIdle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a59df2b7412237dad2066c55c816b2e1732dfe23ec82ea25a9150232850851a +size 9377 diff --git a/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonLoading.png b/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonLoading.png new file mode 100644 index 000000000..b235fa508 --- /dev/null +++ b/presentation/src/test/snapshots/images/me.proton.core.presentation_SnapshotProtonThemeTest_protonProgressButtonLoading.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc3eb5fd27cb81a25321270a1ce30570ae9e35fb9dace9529a9ab8f15d3471a6 +size 9851