Modern Apps git

← Modern-Apps.git

astronomy: strengthen launch e2e test

Commit
624ceca2030505aca371ce9626499ce0bbda52bb
Author
Vayun Mathur <[email protected]>
When
2026-11-19 04:21 UTC (17 days ago)
Parents
aab391e
Strengthen the single LaunchNoCrashTest for astronomy instead of adding a
separate journey test, so the app keeps exactly one emulator e2e test.

The test now clears the target package data (pm clear) before the
grant/launch pass, so it starts from clean state on the emulator, then
performs one small deterministic core interaction after the existing
launch assertions: sky map -> Search -> type Mars -> Planet result row -> detail (Rise / Transit / Set) -> Back -> sky map; fully offline via bundled catalogs. All selectors are verified literals from
the module's Compose code and strings (see the test body); no network,
accounts, Bluetooth, SIM, camera, microphone input or other hardware
dependency is introduced beyond the existing headless grant pass.

No production code, lint, detekt or test configuration was changed.

Verified compile-only (emulator runs centrally, not here):
JAVA_HOME=/home/vayun/maos/prebuilts/jdk/jdk21/linux-x86 ./gradlew
:astronomy:assembleDev :astronomy:assembleDevAndroidTest -- BUILD SUCCESSFUL.

Diff

astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt
diff --git a/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt b/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.ktindex 0fcb1d3959..2bacf945ce 100644--- a/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt+++ b/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt@@ -25,6 +25,11 @@ import org.junit.runner.RunWith  * map itself is a canvas with icon-button chrome, so the test keys on the  * Search action's content description.  *+ * Strengthened launch-e2e: clears the target package data before the+ * grant/launch pass so the journey starts from clean state, then performs+ * one small deterministic core interaction (see the test body) and returns+ * to the launch surface. Still a single @Test for this app.+ *  * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on  * hidden InputManager APIs that no longer exist on current releases, so every  * compose-rule test dies before its first line. Content-description polling@@ -40,6 +45,10 @@ class LaunchNoCrashTest {         val targetContext = instrumentation.targetContext         val packageName = targetContext.packageName +        // Clean state first (fresh-install journey); grants follow the clear+        // because a clear can drop runtime-grant state on some releases.+        clearAppData(instrumentation.uiAutomation, packageName)+         grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)          val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)@@ -57,10 +66,46 @@ class LaunchNoCrashTest {             "sky map never appeared; the app may have crashed on launch",             device.wait(Until.findObject(By.desc(SEARCH_ACTION)), CONTENT_TIMEOUT_MS),         )+        // Core interaction: Search -> "Mars" -> detail -> back. Fully+        // offline (bundled catalogs), so the planet row is deterministic.+        // The row is keyed by its "Planet" subtitle because the typed+        // query itself also reads "Mars" inside the search field.+        device.findObject(By.desc(SEARCH_ACTION))!!.click()+        assertNotNull(+            "search field never appeared",+            device.wait(Until.findObject(By.text(SEARCH_LABEL)), CONTENT_TIMEOUT_MS),+        )+        val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), CONTENT_TIMEOUT_MS)+        assertNotNull("search edit field never appeared", fields)+        val field = fields!!.first()+        field.click()+        field.setText(QUERY)+        val result = device.wait(Until.findObject(By.text(RESULT_SUBTITLE)), CONTENT_TIMEOUT_MS)+        assertNotNull("Mars result never appeared (bundled catalog search failed)", result)+        result!!.click()+        assertNotNull(+            "Mars detail never appeared",+            device.wait(Until.findObject(By.text(DETAIL_SECTION)), CONTENT_TIMEOUT_MS),+        )+        device.pressBack()+        assertNotNull(+            "sky map never reappeared after Back",+            device.wait(Until.findObject(By.desc(SEARCH_ACTION)), CONTENT_TIMEOUT_MS),+        )         // Still alive in front: the process did not crash after painting content.         assertEquals(packageName, device.currentPackageName)     } +    private fun clearAppData(uiAutomation: UiAutomation, packageName: String) {+        try {+            uiAutomation.executeShellCommand("pm clear $packageName").close()+        } catch (ignored: SecurityException) {+            // Clear refused: the journey assertions below still report state.+        } catch (ignored: IOException) {+            // Shell pipe failed: the content assertions below report it.+        }+    }+     private fun grantAllRequestedPermissions(         uiAutomation: UiAutomation,         packageManager: PackageManager,@@ -97,6 +142,10 @@ class LaunchNoCrashTest {         private const val GATE_TIMEOUT_MS = 5_000L         private const val SEARCH_ACTION = "Search"         private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"+        private const val SEARCH_LABEL = "Search stars, planets, Messier"+        private const val QUERY = "Mars"+        private const val RESULT_SUBTITLE = "Planet"+        private const val DETAIL_SECTION = "Rise / Transit / Set"          /**          * Special access behind some apps' gates: exact alarms + full-screen intent