Files
eatvio_app/test/features/payment/consultation_payment_flow_test.dart
2026-07-14 16:11:56 +03:00

132 lines
3.6 KiB
Dart

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 = 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);
});
});
}