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-<run>. The first shot is the transcript's existing blocks, to prove the loop before the redesign. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+115
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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"))
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/<phone>-<name>-<theme>.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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" }
|
||||
|
||||
Reference in new issue
Block a user