-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add preview test #97
Add preview test #97
Changes from 14 commits
f483c93
48802bb
df249fe
5fd9475
94224d0
d133d4c
23ac965
01b8392
1809b9c
93208e4
9373776
f3248d6
19bef16
bc17d49
50e642b
38f01f1
69ae467
dff7c71
a31ddd4
cdea948
b487928
0d8f6ef
f6debee
8dce810
eece508
513aaa2
a675e42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
screenshot-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: Copy CI gradle.properties | ||
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Would you keep using v1 action? or just forget changing to v3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to know the your thought if you have. 🙇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right, it should be v3.x.x.:pray: |
||
with: | ||
java-version: 11 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Download Screenshots | ||
id: download-artifact | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
workflow: UpdateScreenshots.yml | ||
name: screenshots | ||
path: preview-screenshots/src/test/snapshots/images | ||
|
||
- name: Run screenshot tests | ||
id: verifyPaparazziDebug | ||
continue-on-error: true | ||
run: ./gradlew preview-screenshots:verifyPaparazziDebug | ||
|
||
- name: Error Screenshot tests | ||
continue-on-error: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not be necessary, because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to delete this one:sweat_smile: |
||
if: ${{ hashFiles('preview-screenshots/out/failures/*.png') != '' }} | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: scrennshot-test-results | ||
path: preview-screenshots/out/failures | ||
|
||
- name: Comment PR | ||
continue-on-error: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not be necessary, too. |
||
if: ${{ hashFiles('preview-screenshots/out/failures/*.png') != '' }} | ||
uses: thollander/actions-comment-pull-request@v1 | ||
with: | ||
message: | | ||
There are differences in Compose previews. Please check your build and download the diff artifact. | ||
https://github.com/DroidKaigi/conference-app-2022/actions/workflows/ScreenShotTest.yml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be kinder to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your comment. |
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [closed] | ||
|
||
jobs: | ||
update-screenshot: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
with: | ||
java-version: '11' | ||
- name: Run Update Screenshots | ||
run: ./gradlew recordPaparazziDebug | ||
|
||
- name: Upload Screenshots | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: screenshots | ||
path: preview-screenshots/src/test/snapshots/images | ||
retention-days: 15 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed | ||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
id("droidkaigi.primitive.android") | ||
id("droidkaigi.primitive.android.kotlin") | ||
id("droidkaigi.primitive.android.compose") | ||
id("droidkaigi.primitive.android.hilt") | ||
id("droidkaigi.primitive.molecule") | ||
id("droidkaigi.primitive.spotless") | ||
alias(libs.plugins.ksp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create "droidkaigi.primitive.android.compose.showkase"? |
||
} | ||
|
||
android.namespace = "io.github.droidkaigi.confsched2022.template.core.ui" | ||
|
||
dependencies { | ||
implementation(libs.accompanistPager) | ||
implementation(libs.showkase.runtime) | ||
ksp(libs.showkase.processor) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,8 @@ import io.github.droidkaigi.confsched2022.designsystem.theme.KaigiScaffold | |||||
import io.github.droidkaigi.confsched2022.designsystem.theme.KaigiTheme | ||||||
import io.github.droidkaigi.confsched2022.designsystem.theme.KaigiTopAppBar | ||||||
import io.github.droidkaigi.confsched2022.feature.contributors.ContributorsUiModel.ContributorsState.Loaded | ||||||
import io.github.droidkaigi.confsched2022.model.Contributor | ||||||
import io.github.droidkaigi.confsched2022.model.fakes | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [spotless] reported by reviewdog 🐶
Suggested change
|
||||||
|
||||||
@Composable | ||||||
fun ContributorsScreenRoot( | ||||||
|
@@ -95,6 +97,13 @@ fun Contributors( | |||||
@Composable | ||||||
fun ContributorsPreview() { | ||||||
KaigiTheme { | ||||||
ContributorsScreenRoot() | ||||||
Contributors( | ||||||
uiModel = ContributorsUiModel( | ||||||
Loaded( | ||||||
contributors = Contributor.fakes() | ||||||
) | ||||||
), | ||||||
onNavigationIconClick = {} | ||||||
) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed | ||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
id("droidkaigi.primitive.android") | ||
id("droidkaigi.primitive.android.kotlin") | ||
id("droidkaigi.primitive.android.compose") | ||
id("droidkaigi.primitive.molecule") | ||
id("droidkaigi.primitive.spotless") | ||
alias(libs.plugins.ksp) | ||
alias(libs.plugins.paparazzi) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create "droidkaigi.primitive.android.paparazzi"? |
||
} | ||
|
||
android.namespace = "io.github.droidkaigi.confsched2022.template.preview.screenshots" | ||
|
||
androidComponents { | ||
// Disable release builds for this test-only library, no need to run screenshot tests more than | ||
// once | ||
beforeVariants(selector().withBuildType("release")) { builder -> | ||
builder.enable = false | ||
} | ||
beforeVariants(selector().withBuildType("prod")) { builder -> | ||
builder.enable = false | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(project(":core-ui")) | ||
implementation(project(":feature-contributors")) | ||
implementation(project(":feature-sessions")) | ||
|
||
implementation(libs.composeUi) | ||
implementation(libs.showkase.runtime) | ||
ksp(libs.showkase.processor) | ||
|
||
testImplementation(projects.coreTesting) | ||
testImplementation(libs.testParameterInjector) | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn("verifyPaparazziDemoDebug") | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
// Increase memory for Paparazzi tests | ||
maxHeapSize = "2g" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.github.droidkaigi.confsched2022 | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.platform.LocalInspectionMode | ||
import androidx.compose.ui.unit.Density | ||
import app.cash.paparazzi.DeviceConfig | ||
import app.cash.paparazzi.Paparazzi | ||
import app.cash.paparazzi.androidHome | ||
import app.cash.paparazzi.detectEnvironment | ||
import com.airbnb.android.showkase.models.Showkase | ||
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent | ||
import com.google.testing.junit.testparameterinjector.TestParameter | ||
import com.google.testing.junit.testparameterinjector.TestParameter.TestParameterValuesProvider | ||
import com.google.testing.junit.testparameterinjector.TestParameterInjector | ||
import org.junit.Rule | ||
import org.junit.Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for confirmation 👀 , is Paparazzi possible to working with JUnit5? 🤔 if possible, other engineer can use modern toolchain...! ✨ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't check this one. |
||
import org.junit.runner.RunWith | ||
|
||
class ComponentPreview( | ||
private val showkaseBrowserComponent: ShowkaseBrowserComponent | ||
) { | ||
val content: @Composable () -> Unit = showkaseBrowserComponent.component | ||
override fun toString(): String = showkaseBrowserComponent.componentKey | ||
} | ||
|
||
@RunWith(TestParameterInjector::class) | ||
class PreviewScreenshotTests { | ||
|
||
object PreviewProvider : TestParameterValuesProvider { | ||
override fun provideValues(): List<ComponentPreview> = | ||
Showkase.getMetadata().componentList.map(::ComponentPreview) | ||
} | ||
|
||
enum class BaseDeviceConfig( | ||
val deviceConfig: DeviceConfig, | ||
) { | ||
NEXUS_5(DeviceConfig.NEXUS_5), | ||
PIXEL_5(DeviceConfig.PIXEL_5), | ||
PIXEL_C(DeviceConfig.PIXEL_C), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry. I never know the Pixel C is tablet device...! bit old device than my engineer life...! |
||
} | ||
|
||
@get:Rule | ||
val paparazzi = Paparazzi( | ||
environment = detectEnvironment().copy( | ||
platformDir = "${androidHome()}/platforms/android-31", | ||
compileSdkVersion = 31 | ||
), | ||
maxPercentDifference = 0.0, | ||
) | ||
|
||
@Test | ||
fun preview_tests( | ||
@TestParameter(valuesProvider = PreviewProvider::class) componentPreview: ComponentPreview, | ||
@TestParameter baseDeviceConfig: BaseDeviceConfig, | ||
@TestParameter(value = ["1.0", "1.5"]) fontScale: Float | ||
) { | ||
paparazzi.unsafeUpdateConfig( | ||
baseDeviceConfig.deviceConfig.copy( | ||
softButtons = false, | ||
) | ||
) | ||
paparazzi.snapshot { | ||
CompositionLocalProvider( | ||
LocalInspectionMode provides true, | ||
LocalDensity provides Density( | ||
density = LocalDensity.current.density, | ||
fontScale = fontScale | ||
) | ||
) { | ||
Box { | ||
componentPreview.content() | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github.droidkaigi.confsched2022 | ||
|
||
import com.airbnb.android.showkase.annotation.ShowkaseRoot | ||
import com.airbnb.android.showkase.annotation.ShowkaseRootModule | ||
|
||
@ShowkaseRoot | ||
class ScreenshotShowkaseModule : ShowkaseRootModule |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ pluginManagement { | |
gradlePluginPortal() | ||
google() | ||
mavenCentral() | ||
// maven("https://oss.sonatype.org/content/repositories/snapshots/") | ||
maven("https://oss.sonatype.org/content/repositories/snapshots/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make it a plugin, we'll be able to remove this? 👀 |
||
} | ||
} | ||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") | ||
|
@@ -14,6 +14,7 @@ dependencyResolutionManagement { | |
repositories { | ||
google() | ||
mavenCentral() | ||
maven("https://oss.sonatype.org/content/repositories/snapshots/") | ||
// for datastore-okio | ||
// maven(url = "https://androidx.dev/snapshots/builds/8938977/artifacts/repository") { | ||
// content { | ||
|
@@ -36,7 +37,8 @@ include( | |
":core-designsystem", | ||
":core-data", | ||
":core-testing", | ||
":core-model" | ||
":core-model", | ||
":preview-screenshots" | ||
) | ||
|
||
// for iOS framework name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not be necessary, because it should work only at the time of pull request as it is only for pull requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right.