Skip to content

Commit

Permalink
Fix instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Dec 2, 2024
1 parent 7274eb4 commit 11ccc98
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
} ?: ""
}

0 comments on commit 11ccc98

Please sign in to comment.