package com.cottondb.specimenimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.sizeimport androidx.compose.runtime.Composableimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.runtime.rememberimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.test.junit4.ComposeContentTestRuleimport androidx.compose.ui.test.onRootimport androidx.compose.ui.unit.dpimport com.cottondb.shell.LocalMaterialsimport com.cottondb.shell.Materialsimport com.github.takahirom.roborazzi.RoborazziOptionsimport com.github.takahirom.roborazzi.captureRoboImageimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.jsonObject/** * A SPECIMEN of an app's face: drawn by Robolectric with the paintings and type the app's APK carries, held against * the picture kept in app/src/test<App>/specimens/<name>.png ([app] is the flavour, `notes`). A change that moves * the face fails here until the new picture is looked at and kept (`-Pspecimens=record`). The shell's own faces * keep theirs in shell/src/test/specimens. Run under [SpecimenConfig]'s annotations: * `@Config(sdk = [35], qualifiers = SPECIMEN_SCREEN, application = Application::class)` (the app's own Application * opens the core, which a JVM test has not) and `@GraphicsMode(NATIVE)`. */funComposeContentTestRule.specimen(app: String, name: String, width: Int = 360, height: Int = 450, ground: Color = Color(0xFF6E6A63), face: @Composable () -> Unit) { setContent {val context = LocalContext.currentCompositionLocalProvider(LocalMaterials provides remember { Materials(context) }) {Box(Modifier.size(width.dp, height.dp).background(ground)) { face() } } } onRoot().captureRoboImage("src/test${app.replaceFirstChar { it.uppercase() }}/specimens/$name.png", roborazziOptions = RoborazziOptions(compareOptions = RoborazziOptions.CompareOptions(changeThreshold = 0.005f)), )}/** The screen specimens are drawn on: one point a pixel, so the kept pictures stay small. */constval SPECIMEN_SCREEN = "w400dp-h700dp-mdpi"/** A card as the core deals it, from its JSON. */fun card(json: String): JsonObject = Json.parseToJsonElement(json).jsonObject