tests: include more tests
This commit is contained in:
parent
ba5a39d341
commit
ba2bb6a625
|
|
@ -2,7 +2,7 @@ name: flutter_card_swiper
|
||||||
description: This is a Tinder-like card swiper package. It allows you to swipe left, right, up, and down and define your own business logic for each direction.
|
description: This is a Tinder-like card swiper package. It allows you to swipe left, right, up, and down and define your own business logic for each direction.
|
||||||
homepage: https://github.com/ricardodalarme/flutter_card_swiper
|
homepage: https://github.com/ricardodalarme/flutter_card_swiper
|
||||||
issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues
|
issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues
|
||||||
version: 4.1.0+1
|
version: 4.1.0+2
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
|
||||||
|
|
@ -180,31 +180,175 @@ void main() {
|
||||||
expect(direction, CardSwiperDirection.bottom);
|
expect(direction, CardSwiperDirection.bottom);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('undo() should undo the last swipe', (tester) async {
|
group('undo()', () {
|
||||||
final controller = CardSwiperController();
|
testWidgets('should undo the last swipe', (tester) async {
|
||||||
final swiperKey = GlobalKey();
|
final controller = CardSwiperController();
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
home: CardSwiper(
|
home: CardSwiper(
|
||||||
key: swiperKey,
|
controller: controller,
|
||||||
controller: controller,
|
cardsCount: 10,
|
||||||
cardsCount: 10,
|
cardBuilder: genericBuilder,
|
||||||
cardBuilder: genericBuilder,
|
),
|
||||||
direction: CardSwiperDirection.bottom,
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipe();
|
controller.swipe();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text(getIndexText(1)), findsOneWidget);
|
expect(find.text(getIndexText(1)), findsOneWidget);
|
||||||
|
|
||||||
controller.undo();
|
controller.undo();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text(getIndexText(0)), findsOneWidget);
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe left', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeLeft();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(1)), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.left);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe right', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeRight();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(1)), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.right);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe top', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeTop();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(1)), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.top);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe bottom', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeBottom();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(1)), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.bottom);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should not undo if onUndo returns false', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipe();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsNothing);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -454,5 +454,52 @@ void main() {
|
||||||
|
|
||||||
expect(isCalled, true);
|
expect(isCalled, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('when swipes less than the threshold should go back',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final swiperKey = GlobalKey();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
key: swiperKey,
|
||||||
|
cardsCount: 10,
|
||||||
|
numberOfCardsDisplayed: 1,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.drag(find.byKey(swiperKey), const Offset(50, 0));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text(getIndexText(0)), findsOneWidget);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'when isDisabled is true and tap on card expect to call onTapDisabled',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final swiperKey = GlobalKey();
|
||||||
|
var isCalled = false;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: CardSwiper(
|
||||||
|
key: swiperKey,
|
||||||
|
cardsCount: 10,
|
||||||
|
numberOfCardsDisplayed: 1,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onTapDisabled: () {
|
||||||
|
isCalled = true;
|
||||||
|
},
|
||||||
|
isDisabled: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.byKey(swiperKey));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(isCalled, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue