feat(payment, chat): promo code mocked BottomSheet added

This commit is contained in:
Anatoliy
2026-07-14 15:50:44 +03:00
parent e94681266a
commit b064c7016e
12 changed files with 827 additions and 4 deletions

View File

@@ -0,0 +1,131 @@
import 'package:eatvio_app/generated/l10n.dart';
import 'package:eatvio_app/features/payment/presentation/payment_flow.dart';
import 'package:eatvio_app/features/payment/presentation/widgets/promo_code_modal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Widget createTestApp() {
return const MaterialApp(
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('ru')],
home: Scaffold(body: SizedBox()),
);
}
group('showConsultationPaymentFlow', () {
late bool gateCalled;
late bool? gateResult;
late bool formCalled;
late PromoCodeResult? formResult;
late bool sbpCalled;
late int sbpPlanId;
Future<bool?> mockGate(BuildContext context) async {
gateCalled = true;
return gateResult;
}
Future<PromoCodeResult?> mockForm(
BuildContext context, {
Future<PromoValidation> Function(String)? onValidate,
}) async {
formCalled = true;
return formResult;
}
Future<void> mockSbp(BuildContext context, {required int planId}) async {
sbpCalled = true;
sbpPlanId = planId;
}
setUp(() {
gateCalled = false;
gateResult = null;
formCalled = false;
formResult = null;
sbpCalled = false;
sbpPlanId = 0;
});
testWidgets('Нет → вызывает SbpBanks (не форму)', (tester) async {
gateResult = false;
await tester.pumpWidget(createTestApp());
await showConsultationPaymentFlow(
tester.element(find.byType(SizedBox)),
planId: 42,
showGate: mockGate,
showForm: mockForm,
showSbp: mockSbp,
);
expect(gateCalled, isTrue);
expect(formCalled, isFalse);
expect(sbpCalled, isTrue);
expect(sbpPlanId, 42);
});
testWidgets('Да → форма → Пропустить → вызывает SbpBanks', (tester) async {
gateResult = true;
formResult = PromoCodeResult();
await tester.pumpWidget(createTestApp());
await showConsultationPaymentFlow(
tester.element(find.byType(SizedBox)),
planId: 42,
showGate: mockGate,
showForm: mockForm,
showSbp: mockSbp,
);
expect(gateCalled, isTrue);
expect(formCalled, isTrue);
expect(sbpCalled, isTrue);
expect(sbpPlanId, 42);
});
testWidgets('Да → форма отменена (null) → Sbp не вызывается', (tester) async {
gateResult = true;
formResult = null;
await tester.pumpWidget(createTestApp());
await showConsultationPaymentFlow(
tester.element(find.byType(SizedBox)),
planId: 42,
showGate: mockGate,
showForm: mockForm,
showSbp: mockSbp,
);
expect(gateCalled, isTrue);
expect(formCalled, isTrue);
expect(sbpCalled, isFalse);
});
testWidgets('гейт отменён (null) → ничего не вызывается', (tester) async {
gateResult = null;
await tester.pumpWidget(createTestApp());
await showConsultationPaymentFlow(
tester.element(find.byType(SizedBox)),
planId: 42,
showGate: mockGate,
showForm: mockForm,
showSbp: mockSbp,
);
expect(gateCalled, isTrue);
expect(formCalled, isFalse);
expect(sbpCalled, isFalse);
});
});
}