Is it possible to assert that a jetpack compose node is scrollable when performing tests?
class MyTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun givenEnoughItems_thenAssertListIsScrollable() {
composeTestRule.setContent {
BasicTheme {
ScrollableComponent(items = List(1000) { "$it" })
}
}
composeTestRule.onRoot().fetchSemanticsNode().assertIsScrollable()
}
}
fun SemanticsNodeInteraction.assertIsScrollable() : SemanticsNodeInteraction {
// What would go here?
}
I'm afraid that to verify the scrollable behaviour is not possible, I think this can be done through UI/Instrumentation Test.
In Unit Test, I think you can only verify if it is ScrollableComponent instance or not
Use hasScrollAction()
.
Example
import androidx.compose.ui.test.hasScrollAction
import androidx.compose.ui.test.assert
private fun assertNodeIsScrollable() {
findNode().assert(hasScrollAction())
}
and findNode()
would be something like
private fun findNode(): SemanticsNodeInteraction {
return composeTestRule.onNodeWithTag(
testTag = "test_tag",
)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.