|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc_app_template/app/localization.dart'; |
| 3 | +import 'package:flutter_bloc_app_template/features/rocket/bloc/rocket_bloc.dart'; |
| 4 | +import 'package:flutter_bloc_app_template/features/rocket/rocket_screen.dart'; |
| 5 | +import 'package:flutter_bloc_app_template/generated/l10n.dart'; |
| 6 | +import 'package:flutter_test/flutter_test.dart'; |
| 7 | +import 'package:integration_test/integration_test.dart'; |
| 8 | +import 'package:mocktail/mocktail.dart'; |
| 9 | + |
| 10 | +import '../test/bloc/utils.dart'; |
| 11 | +import '../test/features/rocket/rocket_screen_test.dart'; |
| 12 | +import '../test/repository/rocket_repository_test.dart'; |
| 13 | + |
| 14 | +void main() { |
| 15 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 16 | + |
| 17 | + late RocketBloc rocketBloc; |
| 18 | + |
| 19 | + setUp(() { |
| 20 | + rocketBloc = MockRocketBloc(); |
| 21 | + }); |
| 22 | + |
| 23 | + Future<void> pumpRocketScreen( |
| 24 | + WidgetTester tester, { |
| 25 | + required Locale locale, |
| 26 | + void Function(BuildContext context)? contextCallback, |
| 27 | + }) async { |
| 28 | + when(() => rocketBloc.state).thenReturn( |
| 29 | + RocketSuccessState( |
| 30 | + rocket: mockRocket, |
| 31 | + ), |
| 32 | + ); |
| 33 | + |
| 34 | + await tester.pumpLocalizedWidgetWithBloc<RocketBloc>( |
| 35 | + bloc: rocketBloc, |
| 36 | + child: const RocketScreenBlocContent(rocketId: 'falcon9'), |
| 37 | + locale: locale, |
| 38 | + ); |
| 39 | + await tester.pumpAndSettle(); |
| 40 | + } |
| 41 | + |
| 42 | + void expectRocketScreenTexts( |
| 43 | + String specificationLabel, { |
| 44 | + List<String> additionalTexts = const [], |
| 45 | + }) { |
| 46 | + expect(find.text('Falcon 9'), findsOneWidget); |
| 47 | + expect(find.text(specificationLabel), findsOneWidget); |
| 48 | + for (final text in additionalTexts) { |
| 49 | + expect(find.text(text), findsAtLeast(1)); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + group('Rocket Screen Tests', () { |
| 54 | + for (final locale in appSupportedLocales) { |
| 55 | + testWidgets('rocket screen $locale test', (tester) async { |
| 56 | + await pumpRocketScreen(tester, locale: locale, contextCallback: (ctx) { |
| 57 | + expectRocketScreenTexts( |
| 58 | + S.of(ctx).specifications, |
| 59 | + additionalTexts: [S.of(ctx).payloadCapacity], |
| 60 | + ); |
| 61 | + }); |
| 62 | + }); |
| 63 | + } |
| 64 | + }); |
| 65 | +} |
0 commit comments