Modern Apps git

← Modern-Apps.git

metadata: enable chess screenshots automation

Commit
0b028357d32f73d683eb94e7bba9ddc5360fda81
Author
Vayun Mathur <[email protected]>
When
2026-07-07 00:55 UTC (5 months ago)
Parents
1fe8351

Diff

games/chess/build.gradle.kts
diff --git a/games/chess/build.gradle.kts b/games/chess/build.gradle.ktsindex 500a4fd0f0..f6948cad64 100644--- a/games/chess/build.gradle.kts+++ b/games/chess/build.gradle.kts@@ -1,5 +1,6 @@ plugins {     id("common-conventions-app")+    id("common-conventions-metadata") }  android {
games/chess/src/androidTest/java/com/vayunmathur/games/chess/MetadataScreenshots.kt
diff --git a/games/chess/src/androidTest/java/com/vayunmathur/games/chess/MetadataScreenshots.kt b/games/chess/src/androidTest/java/com/vayunmathur/games/chess/MetadataScreenshots.ktnew file mode 100644index 0000000000..0d60880896--- /dev/null+++ b/games/chess/src/androidTest/java/com/vayunmathur/games/chess/MetadataScreenshots.kt@@ -0,0 +1,55 @@+package com.vayunmathur.games.chess++import android.graphics.Bitmap+import androidx.compose.ui.graphics.asAndroidBitmap+import androidx.compose.ui.test.captureToImage+import androidx.compose.ui.test.junit4.createAndroidComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.onRoot+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith+import java.io.File++/**+ * Screenshot generator driven by `:games:chess:metadata`. Store screenshots lead with+ * gameplay (the board), followed by the mode-selection dialog.+ */+@RunWith(AndroidJUnit4::class)+class MetadataScreenshots {++    @get:Rule+    val composeRule = createAndroidComposeRule<MainActivity>()++    private val ctx = InstrumentationRegistry.getInstrumentation().targetContext++    private val outDir: File by lazy {+        File(ctx.getExternalFilesDir(null), "metadata_screenshots").apply {+            deleteRecursively()+            mkdirs()+        }+    }++    private fun snap(index: Int) {+        composeRule.waitForIdle()+        val image = composeRule.onRoot().captureToImage()+        File(outDir, "$index.png").outputStream().use { out ->+            image.asAndroidBitmap().compress(Bitmap.CompressFormat.PNG, 100, out)+        }+    }++    @Test+    fun generateStoreScreenshots() {+        // App launches with the New Game dialog up (offers 2-player / vs-AI) — keep it+        // as the second shot advertising the modes.+        snap(2)++        // Start a local 2-player game to show the populated board first.+        composeRule.onNodeWithText(ctx.getString(R.string.two_player_local)).performClick()+        composeRule.waitForIdle()+        snap(1)+    }+}
metadata_data/photos/games-chess/1.png
diff --git a/metadata_data/photos/games-chess/1.png b/metadata_data/photos/games-chess/1.pngnew file mode 100644index 0000000000..074d4b3a96Binary files /dev/null and b/metadata_data/photos/games-chess/1.png differ
metadata_data/photos/games-chess/2.png
diff --git a/metadata_data/photos/games-chess/2.png b/metadata_data/photos/games-chess/2.pngnew file mode 100644index 0000000000..a9b2c68b6fBinary files /dev/null and b/metadata_data/photos/games-chess/2.png differ