https://kotlinlang.org logo
Title
f

Fabio Berta

01/27/2023, 2:31 PM
Hi, i'm trying to write tests for a composable function that does calculations on a lazy list when it's scrolled. I'm using
listNode.performTouchInput {
  swipeUp(endY = height - 3.dp.toPx())
}
to simulate a scroll. Now this works fine if I'm using higher values than
3dp
but since I want to test a specific edge case, I'd like to use low values. However, by capturing before and after screenshots, I noticed that when using low values like
3.dp
, it doesn't scroll at all. Is there a minimum threshold or something?
k

Kirill Grouchnikov

01/27/2023, 2:51 PM
This is probably under the system-level touch slop
Print the value of
ViewConfiguration.get(context).scaledTouchSlop
to verify that threshold
f

Fabio Berta

01/27/2023, 2:53 PM
that prints 22
ok so I would need to swipe by at least 22px
thx
k

Kirill Grouchnikov

01/27/2023, 2:58 PM
Probably not pixels, you would want to stay in the dp land
Or maybe pixels if that’s what
swipeUp
operates in
One last thing - don’t hardcode 22 into your test. Use
scaledTouchSlop
so that it works across different devices
f

Fabio Berta

01/27/2023, 3:16 PM
yeah, i'm looking into how to incorporate this best. I don't think I can test my edge cases given this limitation.
k

Kirill Grouchnikov

01/27/2023, 3:51 PM
Touch slop will be there for the “real” user interaction on device. Not sure what is the edge case you’re trying to test, but it might be that you’re trying to test something that can not happen in the app / on device.
f

Fabio Berta

01/27/2023, 3:55 PM
yeah, thinking about, my test was not setup right. What I wanted is to test is that something changed at the right moment when scrolling. So I scrolled very close to the breaking point, asserted everything is how it should be, then scrolled just passed it (hence the small value) and asserted the change. But it's clear to me now that this is not how the user would interact. I need to restructure the test to do a bigger swipe just over the breaking point and assert then.
Thanks for your input, very helpful!