Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait until compose is idle before returning from DesktopTestOwner.getRoots() #588

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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")
}
}
Original file line number Diff line number Diff line change
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