From 1460a7627df9ff9671306b10346d5b16cce268c1 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Thu, 2 Jul 2026 17:15:14 -0500 Subject: [PATCH] test(onboarding): grant POST_NOTIFICATIONS in onboarding E2E to fix API 33+ flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moving the notification-permission request into OnboardingWelcomeScreen (#151) means the system POST_NOTIFICATIONS dialog now pops when that screen composes. On API 33+ (where it became a runtime permission) the dialog backgrounded the activity mid-flow, so OnboardingFlowTest failed with "No compose hierarchies found" on API 33/34/35/36/37 while API 29–32 stayed green. Pre-grant the permission via a GrantPermissionRule so the dialog never appears during the flow, guarded for API 33+ (the permission does not exist below TIRAMISU, so grant nothing there to avoid erroring on older devices). Adds the androidx.test:rules dependency that provides the rule. Co-Authored-By: Claude Opus 4.8 --- app/build.gradle.kts | 1 + .../ui/onboarding/OnboardingFlowTest.kt | 16 ++++++++++++++++ gradle/libs.versions.toml | 2 ++ 3 files changed, 19 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4f62af4..5c0e84e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -227,6 +227,7 @@ dependencies { androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.androidx.espresso.intents) + androidTestImplementation(libs.androidx.test.rules) androidTestImplementation(platform(libs.androidx.compose.bom)) androidTestImplementation(libs.androidx.compose.ui.test.junit4) androidTestImplementation(libs.androidx.room.testing) diff --git a/app/src/androidTest/kotlin/org/libremail/ui/onboarding/OnboardingFlowTest.kt b/app/src/androidTest/kotlin/org/libremail/ui/onboarding/OnboardingFlowTest.kt index 5308266..0b32584 100644 --- a/app/src/androidTest/kotlin/org/libremail/ui/onboarding/OnboardingFlowTest.kt +++ b/app/src/androidTest/kotlin/org/libremail/ui/onboarding/OnboardingFlowTest.kt @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later package org.libremail.ui.onboarding +import android.Manifest +import android.os.Build import androidx.activity.ComponentActivity import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext @@ -18,6 +20,7 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.navigation.navArgument import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.GrantPermissionRule import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -54,6 +57,19 @@ class OnboardingFlowTest { @get:Rule val composeTestRule = createAndroidComposeRule() + // OnboardingWelcomeScreen requests POST_NOTIFICATIONS when it first composes (#151). On API 33+ + // that runtime dialog would pop over the test, backgrounding the activity and leaving the compose + // rule with "No compose hierarchies found". Pre-grant it so the flow runs uninterrupted; the + // permission only exists on API 33+, so below TIRAMISU grant nothing (granting a nonexistent + // permission errors on older devices). + @get:Rule + val notificationPermission: GrantPermissionRule = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + GrantPermissionRule.grant(Manifest.permission.POST_NOTIFICATIONS) + } else { + GrantPermissionRule.grant() + } + private fun string(resId: Int, vararg args: Any) = composeTestRule.activity.getString(resId, *args) // Generous cap for the slow, animation-disabled CI matrix emulators; waitUntil returns as soon diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ac5b242..20e92fc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,6 +26,7 @@ angusMail = "2.0.5" junit = "4.13.2" androidxJunit = "1.2.1" espresso = "3.7.0" +androidxTestRules = "1.7.0" turbine = "1.2.1" mockk = "1.14.11" greenmail = "2.1.9" @@ -110,6 +111,7 @@ greenmail = { group = "com.icegreen", name = "greenmail", version.ref = "greenma androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso" } androidx-espresso-intents = { group = "androidx.test.espresso", name = "espresso-intents", version.ref = "espresso" } +androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTestRules" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" }