Repository navigation
When the test main clock is advanced, call ComposeScene.render with the current test time - #584
Conversation
|
Note that I had to modify |
|
And a general question. As I understand, currently the only way to sync the Recomposer with the clock is to call I want to better understand why do we need to make this sync happen automatically? To align the behaviour with android? Or is there something else? |
Yes, but not exactly.
Yes. We want to match Android's behavior, described here: https://developer.android.com/jetpack/compose/testing#sync-auto |
2076c18 to
aeb5c01
Compare
…he current test time.
b9fdfe4 to
072667c
Compare
…he current test time. (#584)
…he current test time. (#584)
…he current test time. (#584)
…he current test time. (#584)
Test: ./gradlew test connectedCheck This is an imported pull request from androidx#584. Resolves #584 Github-Pr-Head-Sha: 514b36c GitOrigin-RevId: b46f27d Change-Id: Ia01ea0db5ab29d40b61a1147742c05f650dadacb
…mposeScene.render with the current test time. (#584)
…poseScene.render with the current test time. (#584)
…he current test time. (JetBrains#584)
Test: ./gradlew test connectedCheck This is an imported pull request from androidx#584. Resolves JetBrains#584 Github-Pr-Head-Sha: 514b36c GitOrigin-RevId: b46f27d Change-Id: Ia01ea0db5ab29d40b61a1147742c05f650dadacb
Proposed Changes
In order to sync the composition with the with the test main clock, call
ComposeScene.renderwhenever the test main clock is advanced.Unfortunately, I couldn't figure how to do this like Android does, so I hope this way will be good enough.
Android appears to use a
TestMonotonicFrameClock(with the scheduler advanced by theMainTestClock) in place of ourBroadcastFrameClockas the parent clock forRecomposer.runRecomposeAndApplyChanges(). This means that when the main test clock advances,Recomposerwakes up (fromparentFrameClock.withFrameNanos) and runs a recomposition.For us, however, using
Recomposer.runRecomposeAndApplyChanges()with aTestMonotonicFrameClockis difficult, because it would requireComposeScene.frameClock(currently aBroadcastFrameClock) to beTestMonotonicFrameClockwhen running in a test context. Unfortunately,ComposeSceneis rather tightly coupled withBroadcastFrameClock.Testing
Test: Added a unit test to verify that when the main test clock is advanced, a recomposition will happen correctly.