From 11ccc9808d852b27b15039272c8abd4be99e9750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Mon, 2 Dec 2024 12:46:29 +0000 Subject: [PATCH] Fix instrumentation tests --- .../ooni/probe/uitesting/RunningTestsTest.kt | 37 ++++++++++++------- .../org/ooni/probe/uitesting/SettingsTest.kt | 4 +- .../ooni/probe/uitesting/UploadResultTest.kt | 6 +-- .../org/ooni/probe/shared/ResourceExt.kt | 12 ++++++ 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/RunningTestsTest.kt b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/RunningTestsTest.kt index 358c9fc9..ffff25fd 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/RunningTestsTest.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/RunningTestsTest.kt @@ -2,6 +2,7 @@ package org.ooni.probe.uitesting import androidx.compose.ui.test.hasText import androidx.compose.ui.test.isDisplayed +import androidx.compose.ui.test.junit4.ComposeTestRule import androidx.compose.ui.test.junit4.createEmptyComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithTag @@ -14,6 +15,7 @@ import kotlinx.coroutines.test.runTest import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Label import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_SelectNone import ooniprobe.composeapp.generated.resources.Dashboard_RunV2_RunFinished +import ooniprobe.composeapp.generated.resources.Measurement_Title import ooniprobe.composeapp.generated.resources.OONIRun_Run import ooniprobe.composeapp.generated.resources.Res import ooniprobe.composeapp.generated.resources.Test_Circumvention_Fullname @@ -22,16 +24,15 @@ import ooniprobe.composeapp.generated.resources.Test_InstantMessaging_Fullname import ooniprobe.composeapp.generated.resources.Test_Performance_Fullname import ooniprobe.composeapp.generated.resources.Test_Psiphon_Fullname import ooniprobe.composeapp.generated.resources.Test_Signal_Fullname -import ooniprobe.composeapp.generated.resources.measurement -import org.jetbrains.compose.resources.getPluralString import org.junit.Before import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.ooni.probe.data.models.SettingsKey -import org.ooni.probe.uitesting.helpers.checkTextAnywhereInsideWebView +import org.ooni.probe.shared.getPluralStringResourceItem import org.ooni.probe.uitesting.helpers.checkSummaryInsideWebView +import org.ooni.probe.uitesting.helpers.checkTextAnywhereInsideWebView import org.ooni.probe.uitesting.helpers.clickOnText import org.ooni.probe.uitesting.helpers.isNewsMediaScan import org.ooni.probe.uitesting.helpers.isOoni @@ -64,13 +65,13 @@ class RunningTestsTest { clickOnText(Res.string.Dashboard_RunTests_SelectNone) clickOnText(Res.string.Test_Signal_Fullname) - clickOnText(getPluralString(Res.plurals.Dashboard_RunTests_RunButton_Label, 1, 1)) + clickOnRunButton(1) clickOnText(Res.string.Dashboard_RunV2_RunFinished, timeout = TEST_WAIT_TIMEOUT) clickOnText(Res.string.Test_InstantMessaging_Fullname) clickOnText(Res.string.Test_Signal_Fullname) - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("Signal") } } @@ -84,13 +85,13 @@ class RunningTestsTest { clickOnText(Res.string.Dashboard_RunTests_SelectNone) clickOnText(Res.string.Test_Psiphon_Fullname) - clickOnText(getPluralString(Res.plurals.Dashboard_RunTests_RunButton_Label, 1, 1)) + clickOnRunButton(1) clickOnText(Res.string.Dashboard_RunV2_RunFinished, timeout = TEST_WAIT_TIMEOUT) clickOnText(Res.string.Test_Circumvention_Fullname) clickOnText(Res.string.Test_Psiphon_Fullname) - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("Psiphon") } } @@ -107,13 +108,13 @@ class RunningTestsTest { .performScrollToNode(hasText("HTTP Header", substring = true)) .performTouchInput { swipeUp() } clickOnText("HTTP Header", substring = true) - clickOnText(getPluralString(Res.plurals.Dashboard_RunTests_RunButton_Label, 1, 1)) + clickOnRunButton(1) clickOnText(Res.string.Dashboard_RunV2_RunFinished, timeout = TEST_WAIT_TIMEOUT) clickOnText(Res.string.Test_Performance_Fullname) clickOnText("HTTP Header", substring = true) - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("middleboxes") } } @@ -130,13 +131,13 @@ class RunningTestsTest { .performScrollToNode(hasText("stunreachability")) .performTouchInput { swipeUp() } clickOnText("stunreachability", substring = true) - clickOnText(getPluralString(Res.plurals.Dashboard_RunTests_RunButton_Label, 1, 1)) + clickOnRunButton(1) clickOnText(Res.string.Dashboard_RunV2_RunFinished, timeout = TEST_WAIT_TIMEOUT) clickOnText(Res.string.Test_Experimental_Fullname) compose.onAllNodesWithText("stunreachability")[0].performClick() - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkTextAnywhereInsideWebView("stunreachability") } } @@ -151,17 +152,27 @@ class RunningTestsTest { clickOnText(Res.string.Dashboard_RunTests_SelectNone) clickOnText("Trusted International Media") - clickOnText(getPluralString(Res.plurals.Dashboard_RunTests_RunButton_Label, 1, 1)) + clickOnRunButton(1) clickOnText(Res.string.Dashboard_RunV2_RunFinished, timeout = TEST_WAIT_TIMEOUT) clickOnText("Trusted International Media") clickOnText("https://www.dw.com") - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("https://www.dw.com") } } + private suspend fun ComposeTestRule.clickOnRunButton(quantity: Int) { + clickOnText( + getPluralStringResourceItem( + Res.plurals.Dashboard_RunTests_RunButton_Label, + quantity, + quantity, + ), + ) + } + companion object { private val TEST_WAIT_TIMEOUT = 3.minutes } 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 5746055b..8664f18b 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/SettingsTest.kt @@ -7,6 +7,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import ooniprobe.composeapp.generated.resources.CategoryCode_ANON_Name +import ooniprobe.composeapp.generated.resources.Common_Back import ooniprobe.composeapp.generated.resources.Res import ooniprobe.composeapp.generated.resources.Settings_Advanced_DebugLogs import ooniprobe.composeapp.generated.resources.Settings_Advanced_Label @@ -25,7 +26,6 @@ import ooniprobe.composeapp.generated.resources.Settings_Title import ooniprobe.composeapp.generated.resources.Settings_WarmVPNInUse_Label import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Description import ooniprobe.composeapp.generated.resources.Settings_Websites_Categories_Label -import ooniprobe.composeapp.generated.resources.back import org.jetbrains.compose.resources.getString import org.junit.Assert.assertTrue import org.junit.Before @@ -126,7 +126,7 @@ class SettingsTest { clickOnText(Res.string.Settings_Websites_Categories_Label) clickOnText(Res.string.CategoryCode_ANON_Name) - clickOnContentDescription(Res.string.back) + clickOnContentDescription(Res.string.Common_Back) onNodeWithText(getString(Res.string.Settings_Websites_Categories_Description, 1)) .assertIsDisplayed() diff --git a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/UploadResultTest.kt b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/UploadResultTest.kt index e319b44b..46592b4e 100644 --- a/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/UploadResultTest.kt +++ b/composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/uitesting/UploadResultTest.kt @@ -9,13 +9,13 @@ import kotlinx.coroutines.test.runTest import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Label import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_SelectNone import ooniprobe.composeapp.generated.resources.Dashboard_RunV2_RunFinished +import ooniprobe.composeapp.generated.resources.Measurement_Title import ooniprobe.composeapp.generated.resources.Modal_ResultsNotUploaded_Uploading import ooniprobe.composeapp.generated.resources.OONIRun_Run import ooniprobe.composeapp.generated.resources.Res import ooniprobe.composeapp.generated.resources.Snackbar_ResultsSomeNotUploaded_UploadAll import ooniprobe.composeapp.generated.resources.Test_InstantMessaging_Fullname import ooniprobe.composeapp.generated.resources.Test_Signal_Fullname -import ooniprobe.composeapp.generated.resources.measurement import org.jetbrains.compose.resources.getPluralString import org.jetbrains.compose.resources.getString import org.junit.Before @@ -75,7 +75,7 @@ class UploadResultTest { clickOnText(Res.string.Test_Signal_Fullname) - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("Signal") } } @@ -105,7 +105,7 @@ class UploadResultTest { clickOnText("https://www.dw.com") - wait { onNodeWithText(Res.string.measurement).isDisplayed() } + wait { onNodeWithText(Res.string.Measurement_Title).isDisplayed() } checkSummaryInsideWebView("https://www.dw.com") } } diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt index 5453e18b..6579c836 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt @@ -23,6 +23,8 @@ import ooniprobe.composeapp.generated.resources.Measurements_Count_One import ooniprobe.composeapp.generated.resources.Measurements_Count_Other import ooniprobe.composeapp.generated.resources.Res import org.jetbrains.compose.resources.PluralStringResource +import org.jetbrains.compose.resources.getPluralString +import org.jetbrains.compose.resources.getString import org.jetbrains.compose.resources.pluralStringResource import org.jetbrains.compose.resources.stringResource @@ -65,3 +67,13 @@ fun pluralStringResourceItem( return stringResource(it, *formatArgs) } ?: "" } + +suspend fun getPluralStringResourceItem( + resource: PluralStringResource, + quantity: Int, + vararg formatArgs: Any, +): String { + return stringMap[getPluralString(resource, quantity, formatArgs)]?.let { + return getString(it, *formatArgs) + } ?: "" +}