From 0a9f77f7c89bd4fed35587ce2a60e39d06ac07d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Tue, 18 Feb 2025 17:13:52 +0000 Subject: [PATCH] Fix instrumented tests for Fdroid --- .../org/ooni/probe/uitesting/OnboardingTest.kt | 14 +++++++++++--- .../org/ooni/probe/uitesting/SettingsTest.kt | 3 +++ .../uitesting/helpers/ApplicationTestHelper.kt | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/OnboardingTest.kt b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/OnboardingTest.kt index 6587988bc..f6cd29151 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/OnboardingTest.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/OnboardingTest.kt @@ -26,6 +26,7 @@ import org.ooni.probe.data.models.SettingsKey import org.ooni.probe.uitesting.helpers.clickOnTag import org.ooni.probe.uitesting.helpers.clickOnText import org.ooni.probe.uitesting.helpers.dependencies +import org.ooni.probe.uitesting.helpers.isCrashReportingEnabled import org.ooni.probe.uitesting.helpers.onNodeWithContentDescription import org.ooni.probe.uitesting.helpers.onNodeWithText import org.ooni.probe.uitesting.helpers.preferences @@ -66,8 +67,10 @@ class OnboardingTest { wait { onNodeWithText(Res.string.Onboarding_AutomatedTesting_Title).isDisplayed() } clickOnTag("No-AutoTest") - wait { onNodeWithText(Res.string.Onboarding_Crash_Title).isDisplayed() } - clickOnTag("Yes-CrashReporting") + if (isCrashReportingEnabled) { + wait { onNodeWithText(Res.string.Onboarding_Crash_Title).isDisplayed() } + clickOnTag("Yes-CrashReporting") + } if (dependencies.platformInfo.needsToRequestNotificationsPermission) { wait { @@ -86,6 +89,11 @@ class OnboardingTest { false, preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_ENABLED).first(), ) - assertEquals(true, preferences.getValueByKey(SettingsKey.SEND_CRASH).first()) + if (isCrashReportingEnabled) { + assertEquals( + true, + preferences.getValueByKey(SettingsKey.SEND_CRASH).first(), + ) + } } } diff --git a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt index 8664f18bc..6a53f87c4 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt @@ -37,6 +37,7 @@ import org.ooni.probe.data.models.ProxyProtocol import org.ooni.probe.data.models.SettingsKey import org.ooni.probe.uitesting.helpers.clickOnContentDescription import org.ooni.probe.uitesting.helpers.clickOnText +import org.ooni.probe.uitesting.helpers.isCrashReportingEnabled import org.ooni.probe.uitesting.helpers.isOoni import org.ooni.probe.uitesting.helpers.preferences import org.ooni.probe.uitesting.helpers.skipOnboarding @@ -141,6 +142,8 @@ class SettingsTest { @Test fun privacy() = runTest { + if (!isCrashReportingEnabled) return@runTest + preferences.setValuesByKey( listOf( SettingsKey.SEND_CRASH to false, diff --git a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/helpers/ApplicationTestHelper.kt b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/helpers/ApplicationTestHelper.kt index 374c6aa04..1eabbbf80 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/helpers/ApplicationTestHelper.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/helpers/ApplicationTestHelper.kt @@ -32,3 +32,9 @@ val isOoni val isNewsMediaScan get() = OrganizationConfig.baseSoftwareName.contains("news") + +val isCrashReportingEnabled + get() = dependencies.flavorConfig.isCrashReportingEnabled + +val isRemoteNotificationsEnabled + get() = dependencies.flavorConfig.isRemoteNotificationsEnabled