Skip to content

Commit

Permalink
add eagerVictoryOnDrag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo-Olivares committed Apr 30, 2024
1 parent 15a646a commit 69ec079
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/flutter/test/gestures/tap_and_drag_test.dart
Expand Up @@ -17,9 +17,12 @@ void main() {
late List<String> events;
late BaseTapAndDragGestureRecognizer tapAndDrag;

void setUpTapAndPanGestureRecognizer() {
void setUpTapAndPanGestureRecognizer({
bool eagerVictoryOnDrag = true, // This is the default for [BaseTapAndDragGestureRecognizer].
}) {
tapAndDrag = TapAndPanGestureRecognizer()
..dragStartBehavior = DragStartBehavior.down
..eagerVictoryOnDrag = eagerVictoryOnDrag
..maxConsecutiveTap = 3
..onTapDown = (TapDragDownDetails details) {
events.add('down#${details.consecutiveTapCount}');
Expand Down Expand Up @@ -653,6 +656,37 @@ void main() {
'panend#1']);
});

testGesture('Recognizer loses when competing against a DragGestureRecognizer for a drag when eagerVictoryOnDrag is disabled', (GestureTester tester) {
setUpTapAndPanGestureRecognizer(eagerVictoryOnDrag: false);
final PanGestureRecognizer pans = PanGestureRecognizer()
..onStart = (DragStartDetails details) {
events.add('panstart');
}
..onUpdate = (DragUpdateDetails details) {
events.add('panupdate');
}
..onEnd = (DragEndDetails details) {
events.add('panend');
}
..onCancel = () {
events.add('pancancel');
};

final TestPointer pointer = TestPointer(5);
final PointerDownEvent downB = pointer.down(const Offset(10.0, 10.0));
// When competing against another [DragGestureRecognizer], the [TapAndPanGestureRecognizer]
// will only win when it is the last recognizer in the arena.
tapAndDrag.addPointer(downB);
pans.addPointer(downB);
tester.closeArena(5);
tester.route(downB);
tester.route(pointer.move(const Offset(40.0, 45.0)));
tester.route(pointer.up());
expect(events, <String>[
'panstart',
'panend']);
});

testGesture('Beats LongPressGestureRecognizer on a consecutive tap greater than one', (GestureTester tester) {
setUpTapAndPanGestureRecognizer();

Expand Down

0 comments on commit 69ec079

Please sign in to comment.