-
Notifications
You must be signed in to change notification settings - Fork 85
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
Adopt IdlingResource move from commonMain to supporting platforms #1822
Changes from all commits
9f9b6e4
6986cc9
2c5b530
a16705a
5fb8173
209418a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,7 @@ import kotlin.test.assertTrue | |
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlinx.atomicfu.atomic | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
|
||
|
||
|
@@ -124,47 +121,6 @@ class TestBasicsTest { | |
} | ||
} | ||
|
||
@Test | ||
fun testIdlingResource() = runComposeUiTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move it to (if you do move it, please also fix the typo in the kdoc for that class: "specified" -> "specific"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
var text by mutableStateOf("") | ||
setContent { | ||
Text( | ||
text = text, | ||
modifier = Modifier.testTag("text") | ||
) | ||
} | ||
|
||
var isIdle = true | ||
val idlingResource = object : IdlingResource { | ||
override val isIdleNow: Boolean | ||
get() = isIdle | ||
} | ||
|
||
fun test(expectedValue: String) { | ||
text = "first" | ||
isIdle = false | ||
val job = CoroutineScope(Dispatchers.Default).launch { | ||
delay(1000) | ||
text = "second" | ||
isIdle = true | ||
} | ||
try { | ||
onNodeWithTag("text").assertTextEquals(expectedValue) | ||
} finally { | ||
job.cancel() | ||
} | ||
} | ||
|
||
// With the idling resource registered, we expect the test to wait until the second value | ||
// has been set. | ||
registerIdlingResource(idlingResource) | ||
test(expectedValue = "second") | ||
|
||
// Without the idling resource registered, we expect the test to see the first value | ||
unregisterIdlingResource(idlingResource) | ||
test(expectedValue = "first") | ||
} | ||
|
||
@Test | ||
fun infiniteDelayLoopInLaunchedEffectDoesNotHang() = runComposeUiTest { | ||
runTest(timeout = 500.milliseconds) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why I think it's okay to make it
open
:ComposeUiTest
interface.scene
, which is convenient, but it's not supposed to be used outside of Compose - InternalComposeUiApi.