From 6589a1407356d993e9884944ffdeab69d3b2c0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Mon, 9 Nov 2026 12:36:36 +0000 Subject: [PATCH] Screenshots on the JVM: Robolectric + Roborazzi, uploaded by CI Test-only dependencies (nothing in the APK). shoot() renders a composable in the Shire and Moria themes at a phone's size and writes app/build/screenshots/*.png; CI uploads them as llembas-android-screenshots-. The first shot is the transcript's existing blocks, to prove the loop before the redesign. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 9 ++++ app/build.gradle.kts | 14 ++++++ .../java/eu/llembas/android/shots/Fakes.kt | 14 ++++++ .../eu/llembas/android/shots/ScreenShots.kt | 28 ++++++++++++ .../java/eu/llembas/android/shots/Shoot.kt | 43 +++++++++++++++++++ gradle/libs.versions.toml | 7 +++ 6 files changed, 115 insertions(+) create mode 100644 app/src/test/java/eu/llembas/android/shots/Fakes.kt create mode 100644 app/src/test/java/eu/llembas/android/shots/ScreenShots.kt create mode 100644 app/src/test/java/eu/llembas/android/shots/Shoot.kt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d19b4c..c29b4fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,15 @@ jobs: path: test-builds/ if-no-files-found: error + # The screens as the screenshot tests rendered them (app/src/test/.../shots), light and + # dark, at a large and a small phone's size: the design is reviewed from these. + - uses: actions/upload-artifact@v4 + if: always() + with: + name: llembas-android-screenshots-${{ github.run_number }} + path: app/build/screenshots/ + if-no-files-found: warn + - uses: actions/upload-artifact@v4 if: always() with: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c058177..11e3063 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -106,6 +106,15 @@ android { testOptions { unitTests.isReturnDefaultValues = true + // The screenshot tests (`shots/`) render the screens on the JVM with Robolectric, and + // Roborazzi writes each to app/build/screenshots/ -- recorded every run, never compared: + // they are for looking at, and CI uploads them. Nothing of this reaches the APK. + unitTests.isIncludeAndroidResources = true + unitTests.all { test -> + test.systemProperty("roborazzi.test.record", "true") + test.systemProperty("robolectric.pixelCopyRenderMode", "hardware") + test.maxHeapSize = "3g" + } } sourceSets { @@ -144,4 +153,9 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.kotlinx.coroutines.test) testImplementation(libs.okhttp.mockwebserver) + testImplementation(platform(libs.compose.bom)) + testImplementation(libs.compose.ui.test.junit4) + testImplementation(libs.robolectric) + testImplementation(libs.roborazzi) + testImplementation(libs.roborazzi.compose) } diff --git a/app/src/test/java/eu/llembas/android/shots/Fakes.kt b/app/src/test/java/eu/llembas/android/shots/Fakes.kt new file mode 100644 index 0000000..c3d4bfa --- /dev/null +++ b/app/src/test/java/eu/llembas/android/shots/Fakes.kt @@ -0,0 +1,14 @@ +package eu.llembas.android.shots + +import eu.llembas.android.api.LembasJson +import eu.llembas.android.api.Message +import eu.llembas.android.api.ModelList + +/** Made-up data for the screenshots: the server's own contract files where they fit. */ +object Fakes { + private fun text(name: String): String = requireNotNull(javaClass.classLoader!!.getResource("$name.json")).readText() + + val models = LembasJson.decodeFromString(ModelList.serializer(), text("models")).models + val question = LembasJson.decodeFromString(Message.serializer(), text("message_user")) + val answer = LembasJson.decodeFromString(Message.serializer(), text("message_assistant")) +} diff --git a/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt new file mode 100644 index 0000000..23dd46c --- /dev/null +++ b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt @@ -0,0 +1,28 @@ +package eu.llembas.android.shots + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import eu.llembas.android.ui.chat.Steps +import eu.llembas.android.ui.chat.UserBubble +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** The app's screens with made-up data ([Fakes]), as a phone shows them. See [shoot]. */ +@RunWith(RobolectricTestRunner::class) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +@Config(sdk = [35], qualifiers = "xhdpi") +class ScreenShots { + @Test + fun transcript() = shoot("transcript") { + Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) { + UserBubble(Fakes.question) + Steps(Fakes.answer.steps) + } + } +} diff --git a/app/src/test/java/eu/llembas/android/shots/Shoot.kt b/app/src/test/java/eu/llembas/android/shots/Shoot.kt new file mode 100644 index 0000000..cab1aba --- /dev/null +++ b/app/src/test/java/eu/llembas/android/shots/Shoot.kt @@ -0,0 +1,43 @@ +@file:OptIn(ExperimentalRoborazziApi::class) + +package eu.llembas.android.shots + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.github.takahirom.roborazzi.ExperimentalRoborazziApi +import com.github.takahirom.roborazzi.RoborazziComposeOptions +import com.github.takahirom.roborazzi.captureRoboImage +import com.github.takahirom.roborazzi.fontScale +import com.github.takahirom.roborazzi.size +import eu.llembas.android.ui.theme.LembasTheme + +/** The phones the screens are looked at on: a large one, and a small one where things crowd. */ +enum class Phone(val tag: String, val widthDp: Int, val heightDp: Int) { + Large("411x891", 411, 891), + Small("360x640", 360, 640), +} + +/** + * Render [content] in the app's theme, light (Shire) and dark (Moria), at [phone]'s size and + * write each to `app/build/screenshots/--.png`, which CI uploads. These are + * for looking at -- by a person, or by an agent reading the PNGs -- not compared against + * anything: a design change is meant to change them. + */ +fun shoot(name: String, phone: Phone = Phone.Large, fontScale: Float = 1f, content: @Composable () -> Unit) { + for ((theme, choice) in listOf("light" to "shire", "dark" to "moria")) { + val font = if (fontScale != 1f) "-font$fontScale" else "" + captureRoboImage( + filePath = "build/screenshots/${phone.tag}-$name-$theme$font.png", + roborazziComposeOptions = RoborazziComposeOptions { + size(phone.widthDp, phone.heightDp) + if (fontScale != 1f) fontScale(fontScale) + }, + ) { + LembasTheme(choice) { + Surface(Modifier.fillMaxSize()) { content() } + } + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 172dacd..f6bcb93 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,9 @@ coroutines = "1.10.2" markwon = "4.6.2" unifiedpush = "3.3.5" junit = "4.13.2" +# Test-only: JVM screenshots of the screens (Robolectric renders, Roborazzi writes the PNGs). +robolectric = "4.17" +roborazzi = "1.78.0" [libraries] androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" } @@ -42,6 +45,10 @@ markwon-tables = { module = "io.noties.markwon:ext-tables", version.ref = "markw markwon-strikethrough = { module = "io.noties.markwon:ext-strikethrough", version.ref = "markwon" } unifiedpush-connector = { module = "org.unifiedpush.android:connector", version.ref = "unifiedpush" } junit = { module = "junit:junit", version.ref = "junit" } +robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } +roborazzi = { module = "io.github.takahirom.roborazzi:roborazzi", version.ref = "roborazzi" } +roborazzi-compose = { module = "io.github.takahirom.roborazzi:roborazzi-compose", version.ref = "roborazzi" } +compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" }