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 mockGate(BuildContext context) async { gateCalled = true; return gateResult; } Future mockForm( BuildContext context, { Future Function(String)? onValidate, }) async { formCalled = true; return formResult; } Future 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 = const 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); }); }); }