forked from eatvio/eatvio_app
feat(promo_codes): added promo codes handling to app
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/payment/models/promo_code_model.dart';
|
||||
import 'package:eatvio_app/features/payment/presentation/widgets/promo_code_modal.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,6 +12,8 @@ void main() {
|
||||
group('ItvioPromoCodeModal', () {
|
||||
Widget createTestWidget({
|
||||
Future<PromoValidation> Function(String)? onValidate,
|
||||
Future<bool> Function()? onRemove,
|
||||
PromoCodeModel? initialPromo,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
@@ -26,6 +29,8 @@ void main() {
|
||||
onPressed: () => ItvioPromoCodeModal.show(
|
||||
context,
|
||||
onValidate: onValidate,
|
||||
onRemove: onRemove,
|
||||
initialPromo: initialPromo,
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
@@ -88,14 +93,84 @@ void main() {
|
||||
expect(find.text('Есть промокод?'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('отсутствует UI applied-состояния (Промокод применён)', (tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
testWidgets('initialPromo показывает applied UI', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
initialPromo: const PromoCodeModel(
|
||||
id: 1,
|
||||
chosenPlanId: 42,
|
||||
promoCode: 'SAVE5',
|
||||
discountPercent: 5,
|
||||
discountAmountRub: 60,
|
||||
state: 'applied',
|
||||
),
|
||||
onRemove: () async => true,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Промокод применён!'), findsOneWidget);
|
||||
expect(find.text('Продолжить'), findsOneWidget);
|
||||
expect(find.text('Убрать промокод'), findsOneWidget);
|
||||
expect(find.text('Применить'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Убрать промокод переводит в input', (tester) async {
|
||||
var removeCalled = false;
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
initialPromo: const PromoCodeModel(
|
||||
id: 1,
|
||||
chosenPlanId: 42,
|
||||
promoCode: 'SAVE5',
|
||||
discountPercent: 5,
|
||||
discountAmountRub: 60,
|
||||
state: 'applied',
|
||||
),
|
||||
onRemove: () async {
|
||||
removeCalled = true;
|
||||
return true;
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Убрать промокод'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(removeCalled, isTrue);
|
||||
expect(find.text('Есть промокод?'), findsOneWidget);
|
||||
expect(find.text('Применить'), findsOneWidget);
|
||||
expect(find.text('Пропустить'), findsOneWidget);
|
||||
expect(find.text('Промокод применён!'), findsNothing);
|
||||
expect(find.text('Продолжить'), findsNothing);
|
||||
expect(find.text('Убрать промокод'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Применить с успешным onValidate закрывает шторку', (tester) async {
|
||||
String? validatedCode;
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
onValidate: (code) async {
|
||||
validatedCode = code;
|
||||
return const PromoValidation.success(
|
||||
discountPercent: 5,
|
||||
discountAmountRub: 60,
|
||||
originalAmountRub: 1200,
|
||||
finalAmountRub: 1140,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'save5');
|
||||
await tester.tap(find.text('Применить'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(validatedCode, 'SAVE5');
|
||||
expect(find.text('Есть промокод?'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user