From 495da1bdb9f367932b7187ef100509401efa1303 Mon Sep 17 00:00:00 2001 From: takahirom Date: Tue, 30 Jul 2024 10:41:20 +0900 Subject: [PATCH] Use main source --- .github/workflows/CompareScreenshot.yml | 2 +- .../takahirom/roborazzi/RoborazziOptions.kt | 2 +- .../build.gradle.kts | 72 +++++-------- .../src/main/AndroidManifest.xml | 4 + .../takahirom/preview/tests/Previews.kt | 102 ++++++++++++++++++ settings.gradle | 1 - 6 files changed, 134 insertions(+), 49 deletions(-) create mode 100644 sample-generate-preview-tests/src/main/AndroidManifest.xml create mode 100644 sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt diff --git a/.github/workflows/CompareScreenshot.yml b/.github/workflows/CompareScreenshot.yml index 57a485ab0..4ed56fd13 100644 --- a/.github/workflows/CompareScreenshot.yml +++ b/.github/workflows/CompareScreenshot.yml @@ -7,7 +7,7 @@ permissions: {} jobs: compare-screenshot-test: - runs-on: ubuntu-latest + runs-on: macos-latest timeout-minutes: 20 permissions: diff --git a/include-build/roborazzi-core/src/commonJvmMain/kotlin/com/github/takahirom/roborazzi/RoborazziOptions.kt b/include-build/roborazzi-core/src/commonJvmMain/kotlin/com/github/takahirom/roborazzi/RoborazziOptions.kt index 8ddd3eaeb..273a7f3f6 100644 --- a/include-build/roborazzi-core/src/commonJvmMain/kotlin/com/github/takahirom/roborazzi/RoborazziOptions.kt +++ b/include-build/roborazzi-core/src/commonJvmMain/kotlin/com/github/takahirom/roborazzi/RoborazziOptions.kt @@ -129,7 +129,7 @@ data class RoborazziOptions( ) companion object { - val DefaultImageComparator = SimpleImageComparator(maxDistance = 0.007F, hShift = 1) + val DefaultImageComparator = SimpleImageComparator(maxDistance = 0.007F) val DefaultResultValidator = ThresholdValidator(0F) } } diff --git a/sample-generate-preview-tests/build.gradle.kts b/sample-generate-preview-tests/build.gradle.kts index 00a5c17dc..5d56f7012 100644 --- a/sample-generate-preview-tests/build.gradle.kts +++ b/sample-generate-preview-tests/build.gradle.kts @@ -1,56 +1,35 @@ plugins { - kotlin("multiplatform") - id("com.android.library") - id("org.jetbrains.compose") + id("com.android.application") +// id("com.android.library") + id("org.jetbrains.kotlin.android") id("io.github.takahirom.roborazzi") } -kotlin { - iosSimulatorArm64() - androidTarget() - - sourceSets { - val androidMain by getting { - dependencies { - implementation(project(":sample-generate-preview-tests-lib")) - implementation(compose.material3) - implementation(compose.ui) - implementation(compose.uiTooling) - implementation(compose.runtime) - } - } - - val androidUnitTest by getting { - dependencies { - implementation("io.github.takahirom.roborazzi:roborazzi-compose-preview-scanner-support:0.1.0") - implementation(libs.junit) - implementation(libs.robolectric) - implementation(libs.composable.preview.scanner) - } - } - - val androidInstrumentedTest by getting { - dependencies { - implementation(libs.androidx.test.ext.junit) - implementation(libs.androidx.test.espresso.core) - } - } +roborazzi { + generateComposePreviewRobolectricTests { + enable = true + packages = listOf("com.github.takahirom.preview.tests") } } +repositories { + mavenCentral() + google() + maven { url = uri("https://jitpack.io") } +} + android { namespace = "com.github.takahirom.preview.tests" compileSdk = 34 defaultConfig { minSdk = 24 + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } - buildFeatures { compose = true } - composeOptions { kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() } @@ -64,7 +43,6 @@ android { ) } } - testOptions { unitTests { isIncludeAndroidResources = true @@ -75,15 +53,17 @@ android { } } -roborazzi { - generateComposePreviewRobolectricTests { - enable = true - packages = listOf("com.github.takahirom.preview.tests") - } -} +dependencies { + implementation(libs.androidx.compose.material3) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.tooling) + implementation(libs.androidx.compose.runtime) -repositories { - mavenCentral() - google() - maven { url = uri("https://jitpack.io") } + // replaced by dependency substitution + testImplementation("io.github.takahirom.roborazzi:roborazzi-compose-preview-scanner-support:0.1.0") + testImplementation(libs.junit) + testImplementation(libs.robolectric) + testImplementation(libs.composable.preview.scanner) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.androidx.test.espresso.core) } \ No newline at end of file diff --git a/sample-generate-preview-tests/src/main/AndroidManifest.xml b/sample-generate-preview-tests/src/main/AndroidManifest.xml new file mode 100644 index 000000000..a5918e68a --- /dev/null +++ b/sample-generate-preview-tests/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt b/sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt new file mode 100644 index 000000000..233c868cf --- /dev/null +++ b/sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt @@ -0,0 +1,102 @@ +package com.github.takahirom.preview.tests + +import android.content.res.Configuration +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material3.Card +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Devices +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.Wallpapers +import androidx.compose.ui.unit.dp + +@Preview +@Composable +fun PreviewNormal() { + MaterialTheme { + Card( + Modifier + .width(180.dp) + ) { + Text( + modifier = Modifier.padding(8.dp), + text = "Generate Preview Test Sample" + ) + } + } +} + +@Preview( + uiMode = Configuration.UI_MODE_NIGHT_YES +) +@Composable +fun PreviewDarkMode() { + val isSystemInDarkTheme = isSystemInDarkTheme() + MaterialTheme( + colorScheme = if (isSystemInDarkTheme) { + darkColorScheme() + } else { + lightColorScheme() + } + ) { + Card( + Modifier + .width(180.dp) + ) { + Text( + modifier = Modifier.padding(8.dp), + text = "Generate Preview Test Sample" + ) + } + } +} + +@Preview( + name = "Preview Name", + // These properties are not supported by Roborazzi yet. + group = "Preview Group", + apiLevel = 30, + widthDp = 320, + heightDp = 640, + locale = "ja-rJP", + fontScale = 1.5f, +) +@Composable +fun PreviewWithProperties1() { + Card( + Modifier + .width(100.dp) + ) { + Text( + modifier = Modifier.padding(8.dp), + text = "Hello, World!" + ) + } +} + +@Preview( + showSystemUi = true, + showBackground = true, + backgroundColor = 0xFF0000FF, + uiMode = Configuration.UI_MODE_NIGHT_YES, + device = Devices.NEXUS_5, + wallpaper = Wallpapers.GREEN_DOMINATED_EXAMPLE, +) +@Composable +fun PreviewWithProperties2() { + Card( + Modifier + .width(100.dp) + ) { + Text( + modifier = Modifier.padding(8.dp), + text = "Hello, World!" + ) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 82483ee94..20e68d9aa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -28,7 +28,6 @@ include ':sample-android-without-compose' include ':sample-compose-desktop-multiplatform' include ':sample-compose-desktop-jvm' include ':sample-generate-preview-tests' -include ':sample-generate-preview-tests-lib' includeBuild("include-build") { dependencySubstitution {