metadata: enable weather screenshots automation
- Commit
4d57308f62c899d1d7c7a044cf4a2c72df9fc40a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-07 02:43 UTC (5 months ago)
- Parents
15856f2
Diff
metadata_data/photos/weather/1.png
diff --git a/metadata_data/photos/weather/1.png b/metadata_data/photos/weather/1.pngnew file mode 100644index 0000000000..8452f9aa7dBinary files /dev/null and b/metadata_data/photos/weather/1.png differ
weather/build.gradle.kts
diff --git a/weather/build.gradle.kts b/weather/build.gradle.ktsindex 866746a735..b9a2f6f032 100644--- a/weather/build.gradle.kts+++ b/weather/build.gradle.kts@@ -2,6 +2,7 @@ import java.util.Properties plugins { id("common-conventions-app")+ id("common-conventions-metadata") alias(libs.plugins.ksp) }
weather/src/androidTest/java/com/vayunmathur/weather/MetadataScreenshots.kt
diff --git a/weather/src/androidTest/java/com/vayunmathur/weather/MetadataScreenshots.kt b/weather/src/androidTest/java/com/vayunmathur/weather/MetadataScreenshots.ktnew file mode 100644index 0000000000..28cc012abc--- /dev/null+++ b/weather/src/androidTest/java/com/vayunmathur/weather/MetadataScreenshots.kt@@ -0,0 +1,65 @@+package com.vayunmathur.weather++import androidx.compose.ui.graphics.asAndroidBitmap+import androidx.compose.ui.test.captureToImage+import androidx.compose.ui.test.junit4.createEmptyComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onRoot+import androidx.test.core.app.ActivityScenario+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import com.vayunmathur.library.util.buildDatabase+import com.vayunmathur.weather.data.SavedLocation+import com.vayunmathur.weather.data.WeatherDatabase+import kotlinx.coroutines.runBlocking+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith+import java.io.File++/**+ * Screenshot generator driven by `:weather:metadata`. Seeds a saved city so the app+ * fetches its live forecast on launch, then captures the home page.+ */+@RunWith(AndroidJUnit4::class)+class MetadataScreenshots {++ @get:Rule+ val composeRule = createEmptyComposeRule()++ 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) {+ val image = composeRule.onRoot().captureToImage()+ File(outDir, "$index.png").outputStream().use { out ->+ image.asAndroidBitmap().compress(android.graphics.Bitmap.CompressFormat.PNG, 100, out)+ }+ }++ @Test+ fun generateStoreScreenshots() {+ val dao = ctx.buildDatabase<WeatherDatabase>(dbName = "weather-db").weatherDao()+ runBlocking {+ dao.insertLocation(SavedLocation(name = "San Francisco", country = "United States", latitude = 37.7749, longitude = -122.4194, displayOrder = 0))+ dao.insertLocation(SavedLocation(name = "Tokyo", country = "Japan", latitude = 35.6762, longitude = 139.6503, displayOrder = 1))+ }++ ActivityScenario.launch(MainActivity::class.java).use {+ // Wait until the live Open-Meteo forecast has loaded and rendered (network+ // latency varies), rather than a fixed sleep.+ composeRule.waitUntil(timeoutMillis = 45_000) {+ composeRule.onAllNodesWithText("Feels like", substring = true)+ .fetchSemanticsNodes().isNotEmpty()+ }+ Thread.sleep(1000)+ snap(1)+ }+ }+}