Modern Apps git

← Modern-Apps.git

metadata: enable notes screenshots automation

Commit
9180ce50122f37ac88baecc85086717d9195be1a
Author
Vayun Mathur <[email protected]>
When
2026-07-07 00:55 UTC (5 months ago)
Parents
77002bf

Diff

metadata_data/photos/notes/1.png
diff --git a/metadata_data/photos/notes/1.png b/metadata_data/photos/notes/1.pngnew file mode 100644index 0000000000..3c25285f27Binary files /dev/null and b/metadata_data/photos/notes/1.png differ
notes/build.gradle.kts
diff --git a/notes/build.gradle.kts b/notes/build.gradle.ktsindex 83dbf38116..7bb15e6b6a 100644--- a/notes/build.gradle.kts+++ b/notes/build.gradle.kts@@ -1,5 +1,6 @@ plugins {     id("common-conventions-app")+    id("common-conventions-metadata")     alias(libs.plugins.ksp) } 
notes/src/androidTest/java/com/vayunmathur/notes/MetadataScreenshots.kt
diff --git a/notes/src/androidTest/java/com/vayunmathur/notes/MetadataScreenshots.kt b/notes/src/androidTest/java/com/vayunmathur/notes/MetadataScreenshots.ktnew file mode 100644index 0000000000..599859d172--- /dev/null+++ b/notes/src/androidTest/java/com/vayunmathur/notes/MetadataScreenshots.kt@@ -0,0 +1,73 @@+package com.vayunmathur.notes++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.onAllNodesWithText+import androidx.compose.ui.test.onRoot+import androidx.lifecycle.ViewModelProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import com.vayunmathur.notes.data.Note+import com.vayunmathur.notes.util.NotesViewModel+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith+import java.io.File++/**+ * Screenshot generator driven by `:notes:metadata`. Seeds a few sample notes (via the+ * ViewModel, exactly like clock's alarms) so the list isn't empty.+ */+@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)+        }+    }++    private val samples = listOf(+        "Weekend plans" to "Saturday: farmers market + hike at Twin Peaks. Sunday: brunch with Sam, then finish the book.",+        "Groceries" to "Oat milk, eggs, sourdough, spinach, cherry tomatoes, olive oil, dark chocolate.",+        "Project ideas" to "1. Auto-generate app screenshots 2. Offline maps tiles 3. A tiny synth in Compose.",+        "Meeting notes" to "Ship the metadata pipeline. Add dark-mode shots. Review the release checklist.",+        "Books to read" to "Project Hail Mary • The Pragmatic Programmer • Piranesi • Thinking in Systems.",+    )++    @Test+    fun generateStoreScreenshots() {+        // The database is built asynchronously on launch; wait for the list to be ready.+        Thread.sleep(1500)+        val vm = composeRule.runOnUiThread<NotesViewModel> {+            ViewModelProvider(composeRule.activity)[NotesViewModel::class.java]+        }+        composeRule.runOnUiThread {+            vm.upsertAll(+                samples.mapIndexed { i, (title, content) ->+                    Note(title = title, content = content, position = i.toDouble())+                }+            )+        }+        composeRule.waitUntil(timeoutMillis = 10_000) {+            composeRule.onAllNodesWithText(samples[0].first).fetchSemanticsNodes().isNotEmpty()+        }+        snap(1) // populated notes list+    }+}