Skip to content

Commit

Permalink
Use main source
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Jul 30, 2024
1 parent b914aad commit 495da1b
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CompareScreenshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ permissions: {}

jobs:
compare-screenshot-test:
runs-on: ubuntu-latest
runs-on: macos-latest
timeout-minutes: 20

permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
72 changes: 26 additions & 46 deletions sample-generate-preview-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
}
Expand All @@ -64,7 +43,6 @@ android {
)
}
}

testOptions {
unitTests {
isIncludeAndroidResources = true
Expand All @@ -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)
}
4 changes: 4 additions & 0 deletions sample-generate-preview-tests/src/main/AndroidManifest.xml
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,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!"
)
}
}
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 495da1b

Please sign in to comment.