I have a screen where some content constantly upda...
# compose
l
I have a screen where some content constantly updates. This seems to mess with testing, since performing touch input seems to require the screen to be idle. So far, I have to set mainClock to not autoadvance at the start of each test, then turn it on temporarily when the test cares about timing. Is there a better way to do this?
a
Is “constantly updates” some form of custom animation or something similar?
l
I have a timer animation that responds to a clock updating its state. Right now, the clock is a launced effect with a while true loop calling onFrameMillis.
The timer is always updating while on screen. It's just a canvas drawing an arc. The timer is for 30 seconds and resets at the end of the 30 seconds (this is for a totp entry, which refreshes every 30 seconds).
a
For infinite animations, you might want to use something like
withInfiniteAnimationFrameNanos
, which will change its behavior during tests. Although here it sounds like there’s more core logic that won’t end. I think your main alternative to messing with autoadvance is to have a way to make the test more controllable, instead of directly dependent on time. Maybe in tests, you could replace the controller or “thing” that outputs a signal every 30 seconds with a test version that you could send out a signal manually with. So then in your tests, it would be something like
testTimer.sendTick
, and then you wouldn’t have any time dependency in a test.