diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesScreen.kt index 0f06e552..69382e9b 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesScreen.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import ooniprobe.composeapp.generated.resources.CustomWebsites_Fab_Text @@ -109,7 +110,8 @@ fun ChooseWebsitesScreen( }, modifier = Modifier.fillMaxWidth() .padding(horizontal = 16.dp) - .padding(top = 16.dp), + .padding(top = 16.dp) + .testTag("ChooseWebsite-UrlField"), ) } diff --git a/composeApp/src/commonTest/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesTest.kt b/composeApp/src/commonTest/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesTest.kt new file mode 100644 index 00000000..dcafeca0 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/org/ooni/probe/ui/choosewebsites/ChooseWebsitesTest.kt @@ -0,0 +1,56 @@ +package org.ooni.probe.ui.choosewebsites + +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.test.onAllNodesWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextReplacement +import androidx.compose.ui.test.runComposeUiTest +import org.ooni.engine.models.TaskOrigin +import org.ooni.engine.models.TestType +import org.ooni.probe.data.models.RunSpecification +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class ChooseWebsitesTest { + private var runSpec: RunSpecification? = null + private val viewModel = ChooseWebsitesViewModel( + onBack = {}, + goToDashboard = {}, + startBackgroundRun = { runSpec = it }, + ) + + @Test + fun showTestDescriptors() = + runComposeUiTest { + setContent { + val state by viewModel.state.collectAsState() + ChooseWebsitesScreen(state, viewModel::onEvent) + } + + val websites = listOf( + "http://website1.com", + "http://website2.com", + "http://website3.com", + ) + + repeat(websites.size - 1) { + onNodeWithText("Add website").performClick() + } + websites.forEachIndexed { index, url -> + onAllNodesWithTag("ChooseWebsite-UrlField")[index] + .performTextReplacement(url) + } + onNodeWithText("Test ${websites.size} URLs").performClick() + + val spec = runSpec + assertNotNull(spec) + assertEquals(false, spec.isRerun) + assertEquals(TaskOrigin.OoniRun, spec.taskOrigin) + assertEquals(1, spec.tests.size) + assertEquals(TestType.WebConnectivity, spec.tests.first().netTests.first().test) + assertEquals(websites, spec.tests.first().netTests.first().inputs) + } +}