Modern Apps git

← Modern-Apps.git

office: updated automated screenshot generation

Commit
81e615ed5763cf6e075c7e75c590d251c261cef5
Author
Vayun Mathur <[email protected]>
When
2026-07-07 05:32 UTC (5 months ago)
Parents
ef98d77

Diff

metadata_data/assets/Dickinson_Sample_Slides.pptx
diff --git a/metadata_data/assets/Dickinson_Sample_Slides.pptx b/metadata_data/assets/Dickinson_Sample_Slides.pptxnew file mode 100644index 0000000000..ef4ba3bff8Binary files /dev/null and b/metadata_data/assets/Dickinson_Sample_Slides.pptx differ
metadata_data/assets/file-sample_1MB.docx
diff --git a/metadata_data/assets/file-sample_1MB.docx b/metadata_data/assets/file-sample_1MB.docxnew file mode 100644index 0000000000..b36cfed532Binary files /dev/null and b/metadata_data/assets/file-sample_1MB.docx differ
metadata_data/assets/file_example_XLSX_5000.xlsx
diff --git a/metadata_data/assets/file_example_XLSX_5000.xlsx b/metadata_data/assets/file_example_XLSX_5000.xlsxnew file mode 100644index 0000000000..e79d0802feBinary files /dev/null and b/metadata_data/assets/file_example_XLSX_5000.xlsx differ
metadata_data/photos/office/1.png
diff --git a/metadata_data/photos/office/1.png b/metadata_data/photos/office/1.pngindex d06ca6bd76..f6975b9441 100644Binary files a/metadata_data/photos/office/1.png and b/metadata_data/photos/office/1.png differ
metadata_data/photos/office/2.png
diff --git a/metadata_data/photos/office/2.png b/metadata_data/photos/office/2.pngdeleted file mode 100644index 6e8ecd9484..0000000000Binary files a/metadata_data/photos/office/2.png and /dev/null differ
office/build.gradle.kts
diff --git a/office/build.gradle.kts b/office/build.gradle.ktsindex e43639e2bf..1db99fe236 100644--- a/office/build.gradle.kts+++ b/office/build.gradle.kts@@ -7,6 +7,9 @@ android {     defaultConfig {         applicationId = "com.vayunmathur.office"     }+    // Ship the real sample documents (metadata_data/assets) inside the instrumented+    // test APK so the screenshot generator can open them via ACTION_VIEW on device.+    sourceSets.getByName("androidTest").assets.srcDir(rootProject.file("metadata_data/assets")) }  dependencies {
office/src/androidTest/java/com/vayunmathur/office/MetadataScreenshots.kt
diff --git a/office/src/androidTest/java/com/vayunmathur/office/MetadataScreenshots.kt b/office/src/androidTest/java/com/vayunmathur/office/MetadataScreenshots.ktindex d83ce9c2cf..91463b9b4a 100644--- a/office/src/androidTest/java/com/vayunmathur/office/MetadataScreenshots.kt+++ b/office/src/androidTest/java/com/vayunmathur/office/MetadataScreenshots.kt@@ -1,12 +1,18 @@ package com.vayunmathur.office +import android.content.ContentValues+import android.content.Intent import android.graphics.Bitmap+import android.net.Uri+import android.os.Environment+import android.provider.MediaStore import androidx.compose.ui.graphics.asAndroidBitmap+import androidx.compose.ui.semantics.ProgressBarRangeInfo import androidx.compose.ui.test.captureToImage-import androidx.compose.ui.test.junit4.createAndroidComposeRule-import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.hasProgressBarRangeInfo+import androidx.compose.ui.test.junit4.createEmptyComposeRule import androidx.compose.ui.test.onRoot-import androidx.compose.ui.test.performClick+import androidx.test.core.app.ActivityScenario import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import org.junit.Rule@@ -15,24 +21,80 @@ import org.junit.runner.RunWith import java.io.File  /**- * Screenshot generator driven by `:office:metadata`. Leads with the document editor- * (created via "New Doc"), followed by the offline home with the document-type options.+ * Screenshot generator driven by `:office:metadata`. Opens the three real sample documents that+ * ship in `metadata_data/assets` (bundled into this test APK's assets) exactly the way a user+ * would: each file is staged onto the device and handed to [MainActivity] through an+ * `ACTION_VIEW` intent, so the store shots show the app rendering genuine documents.+ *+ * Order (best first): doc = 1, spreadsheet = 2, presentation = 3.+ *+ * The shared [com.vayunmathur.metadata.PlaystoreIconRenderer] test (from build-logic) runs in the+ * same instrumentation pass and is untouched.  */ @RunWith(AndroidJUnit4::class) class MetadataScreenshots { +    // We launch each activity ourselves via ActivityScenario, so the compose rule only needs to+    // attach to whatever composition is currently on screen.     @get:Rule-    val composeRule = createAndroidComposeRule<MainActivity>()+    val composeRule = createEmptyComposeRule() -    private val ctx = InstrumentationRegistry.getInstrumentation().targetContext+    private val instrumentation = InstrumentationRegistry.getInstrumentation()++    // The instrumentation (test-apk) context owns the bundled androidTest assets.+    private val testCtx = instrumentation.context++    // The app-under-test context: instrumentation loads us into its process, so MediaStore entries+    // we insert here are owned by the app and readable back without any cross-app uri grant.+    private val appCtx = instrumentation.targetContext      private val outDir: File by lazy {-        File(ctx.getExternalFilesDir(null), "metadata_screenshots").apply {+        File(appCtx.getExternalFilesDir(null), "metadata_screenshots").apply {             deleteRecursively()             mkdirs()         }     } +    private data class Shot(val index: Int, val asset: String, val mime: String)++    private val shots = listOf(+        Shot(1, "file-sample_1MB.docx", MIME_DOCX),+        Shot(2, "file_example_XLSX_5000.xlsx", MIME_XLSX),+        Shot(3, "Dickinson_Sample_Slides.pptx", MIME_PPTX),+    )++    @Test+    fun generateStoreScreenshots() {+        for (shot in shots) {+            val uri = stageAsset(shot.asset, shot.mime)+            val intent = Intent(Intent.ACTION_VIEW).apply {+                setClassName(appCtx.packageName, "com.vayunmathur.office.MainActivity")+                setDataAndType(uri, shot.mime)+                addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)+            }+            ActivityScenario.launch<MainActivity>(intent).use {+                waitForDocument()+                snap(shot.index)+            }+        }+    }++    /** Waits for the editor to finish loading (the loading spinner to disappear), then settles. */+    private fun waitForDocument() {+        // Let the first composition (which shows the loading spinner) come up before we poll.+        Thread.sleep(800)+        runCatching {+            composeRule.waitUntil(timeoutMillis = 40_000) {+                composeRule+                    .onAllNodes(hasProgressBarRangeInfo(ProgressBarRangeInfo.Indeterminate))+                    .fetchSemanticsNodes().isEmpty()+            }+        }+        // Give the rendered "paper" a moment to lay out its first full frame.+        Thread.sleep(1500)+        composeRule.waitForIdle()+    }+     private fun snap(index: Int) {         composeRule.waitForIdle()         val image = composeRule.onRoot().captureToImage()@@ -41,15 +103,26 @@ class MetadataScreenshots {         }     } -    @Test-    fun generateStoreScreenshots() {-        // Offline home is up at launch — second shot (New Doc / Sheet / Slides).-        Thread.sleep(1000)-        snap(2)--        // Create a new text document and let the editor's WebView render it.-        composeRule.onNodeWithText("New Doc").performClick()-        Thread.sleep(3000)-        snap(1)+    /** Copies a bundled sample document into MediaStore Downloads and returns its content Uri. */+    private fun stageAsset(name: String, mime: String): Uri {+        val resolver = appCtx.contentResolver+        val values = ContentValues().apply {+            put(MediaStore.Downloads.DISPLAY_NAME, name)+            put(MediaStore.Downloads.MIME_TYPE, mime)+            put(MediaStore.Downloads.RELATIVE_PATH, "${Environment.DIRECTORY_DOWNLOADS}/office_metadata")+        }+        val collection = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)+        val uri = resolver.insert(collection, values)+            ?: error("Could not create MediaStore entry for $name")+        resolver.openOutputStream(uri)?.use { out ->+            testCtx.assets.open(name).use { input -> input.copyTo(out) }+        } ?: error("Could not open output stream for $name")+        return uri+    }++    private companion object {+        const val MIME_DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"+        const val MIME_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"+        const val MIME_PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation"     } }
office/src/main/ic_launcher-playstore.png
diff --git a/office/src/main/ic_launcher-playstore.png b/office/src/main/ic_launcher-playstore.pngnew file mode 100644index 0000000000..2e98875bd2Binary files /dev/null and b/office/src/main/ic_launcher-playstore.png differ