Venkataramanan Parameswaran
04/25/2023, 1:39 PMonNodeWithText("LazyColumnTestTag").onChildAt(index).assert(hasAnyDescendant(hasText("text at index")))
But when the list is scrolled the indexes of the list item changes.
is there any other way I could achieve this?
Previously, in the view system’s Recycler view this type of testing is working fine.
Attempted solution:
- scroll for each list item so that, it will come at the 0th index and test with 0th index. But when the list scrolls to the end the list can’t be scrolled after some index. So there the index changes.mattinger
04/25/2023, 10:00 PM@Test
fun testScrolling() {
rule.setContent {
LazyColumn(modifier = Modifier.fillMaxSize().testTag("LazyColumn")) {
items((0 .. 99).toList()) {
Text(text=it.toString())
}
}
}
println(rule.onRoot().printToString())
rule.onNodeWithTag("LazyColumn")
.assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.VerticalScrollAxisRange))
(0 until 100).forEach {
rule.onNodeWithTag("LazyColumn")
.performScrollToIndex(it)
val scrollAxisRange = rule.onNodeWithTag("LazyColumn")
.fetchSemanticsNode()
.config[SemanticsProperties.VerticalScrollAxisRange]
val firstIndex = scrollAxisRange.value().toInt()
rule.onNodeWithTag("LazyColumn")
.onChildAt(
maxOf(0, it-firstIndex)
)
.assert(hasText(it.toString()))
}
}
Venkataramanan Parameswaran
04/26/2023, 5:40 AMonChildren().assertCount()
only matches with the composed children count. I also tried with collectioninfo's row and column count i got the row count as -1 for a LazyColumn