Skip to content

Commit

Permalink
Wait until compose is idle before returning from DesktopTestOwner.get…
Browse files Browse the repository at this point in the history
…Roots() (#588)
  • Loading branch information
m-sasha committed Jun 4, 2023
1 parent b90e6e5 commit aae7996
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -98,4 +98,17 @@ class BasicTestTest {
rule.mainClock.advanceTimeBy(1, ignoreFrameDuration = true)
rule.onNodeWithTag("text").assertTextEquals("2")
}

@Test
fun obtainingSemanticsNodeInteractionWaitsUntilIdle() {
var text by mutableStateOf("1")

rule.setContent {
Text(text, modifier = Modifier.testTag("text"))
}

rule.onNodeWithTag("text").assertTextEquals("1")
text = "2"
rule.onNodeWithTag("text").assertTextEquals("2")
}
}
Expand Up @@ -220,7 +220,7 @@ class SkikoComposeUiTest(
++i
}

val hasPendingMeasureOrLayout = testOwner.getRoots(true).any {
val hasPendingMeasureOrLayout = testOwner.roots.any {
(it as SkiaRootForTest).hasPendingMeasureOrLayout
}

Expand Down Expand Up @@ -325,6 +325,9 @@ class SkikoComposeUiTest(
}

private inner class DesktopTestOwner : TestOwner {
val roots: Set<RootForTest>
get() = this@SkikoComposeUiTest.scene.roots

@OptIn(ExperimentalTextApi::class)
override fun performTextInput(node: SemanticsNode, action: TextInputForTests.() -> Unit) {
runOnIdle {
Expand All @@ -337,6 +340,7 @@ class SkikoComposeUiTest(
}

override fun getRoots(atLeastOneRootExpected: Boolean): Set<RootForTest> {
waitForIdle()
return this@SkikoComposeUiTest.scene.roots
}

Expand Down

0 comments on commit aae7996

Please sign in to comment.