From ad1f84389b35282053fff84cbf8695aad91851c1 Mon Sep 17 00:00:00 2001 From: Omar Miatello Date: Mon, 20 Jan 2025 14:07:30 +0000 Subject: Add test for scene animation when distance is not specified yet If the SwipeAnimation's distance hasn't been calculated, the animation shouldn't start. Instead, the scene should remain as it is. Test: atest DraggableHandlerTest Bug: 388803469 Flag: com.android.systemui.scene_container Change-Id: I26f51e4b2155e57c4cbd9b69ec17b4b1ab342d1c --- .../animation/scene/DraggableHandlerTest.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt index 35ff0044f4d6..059112abb1b1 100644 --- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt @@ -36,6 +36,7 @@ import com.android.compose.animation.scene.TestScenes.SceneA import com.android.compose.animation.scene.TestScenes.SceneB import com.android.compose.animation.scene.TestScenes.SceneC import com.android.compose.animation.scene.content.state.TransitionState +import com.android.compose.animation.scene.content.state.TransitionState.Companion.DistanceUnspecified import com.android.compose.animation.scene.content.state.TransitionState.Transition import com.android.compose.animation.scene.subjects.assertThat import com.android.compose.gesture.NestedDraggable @@ -784,6 +785,29 @@ class DraggableHandlerTest { assertIdle(SceneB) } + @Test + fun animateWhenDistanceUnspecified() = runGestureTest { + layoutState.transitions = transitions { + from(SceneA, to = SceneB) { + distance = UserActionDistance { _, _, _ -> DistanceUnspecified } + } + } + + val controller = onDragStarted(overSlop = up(fractionOfScreen = 0.9f)) + + // The distance is not computed yet, so we don't know the "progress" value yet. + assertTransition(fromScene = SceneA, toScene = SceneB, progress = 0.0f) + + controller.onDragStoppedAnimateNow( + // We are animating from SceneA to SceneA, when the distance is still unspecified. + velocity = velocityThreshold, + onAnimationStart = { + assertTransition(fromScene = SceneA, toScene = SceneB, progress = 0.0f) + }, + ) + assertIdle(SceneA) + } + @Test fun showOverlay() = runGestureTest { mutableUserActionsA = mapOf(Swipe.Down to UserActionResult.ShowOverlay(OverlayA)) -- cgit v1.2.3-59-g8ed1b