Skip to content

Commit

Permalink
Choose websites test
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Oct 29, 2024
1 parent d327b1d commit 495c744
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,7 +110,8 @@ fun ChooseWebsitesScreen(
},
modifier = Modifier.fillMaxWidth()
.padding(horizontal = 16.dp)
.padding(top = 16.dp),
.padding(top = 16.dp)
.testTag("ChooseWebsite-UrlField"),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 495c744

Please sign in to comment.