Skip to content

Commit b062239

Browse files
author
Łukasz Paczos
committed
add tests for move threshold when pointers outside of rect
1 parent ef2a4ce commit b062239

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

app/src/androidTest/java/com/mapbox/android/gestures/MoveGestureDetectorTest.kt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,64 @@ class MoveGestureDetectorTest {
122122
Assert.fail("move was not called")
123123
}
124124
}
125+
126+
@Test
127+
fun move_whenOutsideOfRect_executeWhenMoveThresholdMet() {
128+
val latch = CountDownLatch(1)
129+
val rect = RectF(400f, 400f, 600f, 600f)
130+
gesturesManager.setMoveGestureListener(object : MoveGestureDetector.OnMoveGestureListener {
131+
override fun onMoveBegin(detector: MoveGestureDetector) = true
132+
133+
override fun onMove(
134+
detector: MoveGestureDetector,
135+
distanceX: Float,
136+
distanceY: Float
137+
): Boolean {
138+
Assert.assertFalse(rect.contains(detector.focalPoint.x, detector.focalPoint.y))
139+
latch.countDown()
140+
return true
141+
}
142+
143+
override fun onMoveEnd(detector: MoveGestureDetector, velocityX: Float, velocityY: Float) = Unit
144+
145+
})
146+
gesturesManager.moveGestureDetector.moveThresholdRect = rect
147+
gesturesManager.moveGestureDetector.moveThreshold = 50f
148+
Espresso.onView(ViewMatchers.withId(R.id.content)).perform(
149+
move(
150+
deltaX = 100f,
151+
deltaY = 100f,
152+
startPoint = PointF(rect.right + 50f, rect.bottom + 50f)
153+
)
154+
)
155+
if (!latch.await(DEFAULT_GESTURE_DURATION, TimeUnit.MILLISECONDS)) {
156+
Assert.fail("move was not called")
157+
}
158+
}
159+
160+
@Test
161+
fun move_whenOutsideOfRect_ignoredWhenMoveThreshold() {
162+
val rect = RectF(400f, 400f, 600f, 600f)
163+
gesturesManager.setMoveGestureListener(object : MoveGestureDetector.OnMoveGestureListener {
164+
override fun onMoveBegin(detector: MoveGestureDetector) = true
165+
166+
override fun onMove(
167+
detector: MoveGestureDetector,
168+
distanceX: Float,
169+
distanceY: Float
170+
): Boolean = throw AssertionError("onMove shouldn't be called if threshold was not met")
171+
172+
override fun onMoveEnd(detector: MoveGestureDetector, velocityX: Float, velocityY: Float) = Unit
173+
174+
})
175+
gesturesManager.moveGestureDetector.moveThresholdRect = rect
176+
gesturesManager.moveGestureDetector.moveThreshold = 50f
177+
Espresso.onView(ViewMatchers.withId(R.id.content)).perform(
178+
move(
179+
deltaX = 25f,
180+
deltaY = 25f,
181+
startPoint = PointF(rect.right + 50f, rect.bottom + 50f)
182+
)
183+
)
184+
}
125185
}

0 commit comments

Comments
 (0)