Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Feb 7, 2024
1 parent db9c684 commit 6df372b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private class AnimatedMouseWheelScrollPhysics(
}
return with(scrollingLogic) {
val delta = scrollDelta.reverseIfNeeded().toFloat()
if (canConsumeDelta(delta)) {
if (delta != 0f && canConsumeDelta(delta)) {
if (mouseWheelScrollConfig.isPreciseWheelScroll(pointerEvent)) {
// In case of high-resolution wheel, such as a freely rotating wheel with no notches
// or trackpads, delta should apply directly without any delays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,19 @@ class ScrollableTest {

@OptIn(ExperimentalTestApi::class)
@Test
fun scrollable_nestedScroll_disabledForMouseWheel() = runSkikoComposeUiTest {
fun scrollable_nestedScroll_childPartialConsumptionForMouseWheel() = runSkikoComposeUiTest {
var innerDrag = 0f
var outerDrag = 0f
val outerState = ScrollableState(
consumeScrollDelta = {
// Since the child has already consumed half, the parent will consume the rest.
outerDrag += it
it
}
)
val innerState = ScrollableState(
consumeScrollDelta = {
// Child consumes half, leaving the rest for the parent to consume.
innerDrag += it / 2
it / 2
}
Expand Down Expand Up @@ -812,7 +814,10 @@ class ScrollableTest {
}
runOnIdle {
assertThat(innerDrag).isGreaterThan(0f)
assertThat(outerDrag).isEqualTo(0f)
assertThat(outerDrag).isGreaterThan(0f)
// Since child (inner) consumes half of the scroll, the parent (outer) consumes the
// remainder (which is half as well), so they will be equal.
assertThat(innerDrag).isEqualTo(outerDrag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class MouseMoveTest {
val collector2 = EventCollector()

setContent {
LazyColumn(Modifier.size(10.dp)) {
LazyColumn(Modifier.size(12.dp)) {
items(2) {
Box(
modifier = Modifier
Expand All @@ -382,16 +382,16 @@ class MouseMoveTest {
}
}

scene.sendPointerEvent(PointerEventType.Enter, Offset(0f, 0f))
scene.sendPointerEvent(PointerEventType.Enter, Offset(5f, 5f))
collector1.assertCounts(enter = 1, exit = 0)
collector2.assertCounts(enter = 0, exit = 0)

scene.sendPointerEvent(PointerEventType.Scroll, Offset(0f, 0f), scrollDelta = Offset(0f, 10000f))
scene.sendPointerEvent(PointerEventType.Scroll, Offset(5f, 5f), scrollDelta = Offset(0f, 10000f))
waitForIdle()
collector1.assertCounts(enter = 1, exit = 1)
collector2.assertCounts(enter = 1, exit = 0)

scene.sendPointerEvent(PointerEventType.Scroll, Offset(0f, 0f), scrollDelta = Offset(0f, -10000f))
scene.sendPointerEvent(PointerEventType.Scroll, Offset(5f, 5f), scrollDelta = Offset(0f, -10000f))
waitForIdle()
collector1.assertCounts(enter = 2, exit = 1)
collector2.assertCounts(enter = 1, exit = 1)
Expand Down

0 comments on commit 6df372b

Please sign in to comment.