|
1 | | -import 'package:flutter/foundation.dart'; |
2 | | -import 'package:flutter_bloc_app_template/features/launches/widget/launch_item.dart'; |
3 | | -import 'package:flutter_bloc_app_template/main.dart' as app; |
| 1 | +import 'dart:ui'; |
| 2 | + |
| 3 | +import 'package:flutter_bloc_app_template/features/launch/bloc/launch_bloc.dart'; |
| 4 | +import 'package:flutter_bloc_app_template/features/launch/launch_screen.dart'; |
4 | 5 | import 'package:flutter_test/flutter_test.dart'; |
5 | 6 | import 'package:integration_test/integration_test.dart'; |
| 7 | +import 'package:mocktail/mocktail.dart'; |
| 8 | + |
| 9 | +import '../test/bloc/utils.dart'; |
| 10 | +import '../test/features/launch/launch_screen_test.dart'; |
6 | 11 |
|
7 | 12 | void main() { |
8 | 13 | IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
9 | 14 |
|
10 | | - setUp(() {}); |
| 15 | + late LaunchBloc launchBloc; |
| 16 | + |
| 17 | + setUp(() { |
| 18 | + launchBloc = MockLaunchBloc(); |
| 19 | + }); |
11 | 20 |
|
12 | | - testWidgets('launch test', ( |
13 | | - WidgetTester tester, |
14 | | - ) async { |
15 | | - app.main([]); |
| 21 | + Future<void> pumpLaunchScreen( |
| 22 | + WidgetTester tester, { |
| 23 | + required Locale locale, |
| 24 | + }) async { |
| 25 | + when(() => launchBloc.state).thenReturn( |
| 26 | + const LaunchSuccessState( |
| 27 | + launch: mockLaunchResource, |
| 28 | + ), |
| 29 | + ); |
| 30 | + |
| 31 | + await tester.pumpLocalizedWidgetWithBloc<LaunchBloc>( |
| 32 | + bloc: launchBloc, |
| 33 | + child: const LaunchScreenBlocContent(flightNumber: 1), |
| 34 | + locale: locale, |
| 35 | + ); |
16 | 36 | await tester.pumpAndSettle(); |
| 37 | + } |
17 | 38 |
|
18 | | - final firstItem = find.byKey(const Key('FalconSat1')); |
| 39 | + void expectLaunchTexts( |
| 40 | + String flightName, { |
| 41 | + List<String> additionalTexts = const [], |
| 42 | + }) { |
| 43 | + expect(find.text('Starlink-1'), findsOneWidget); |
| 44 | + expect(find.text(flightName), findsOneWidget); |
| 45 | + for (final text in additionalTexts) { |
| 46 | + expect(find.text(text), findsAtLeast(1)); |
| 47 | + } |
| 48 | + } |
19 | 49 |
|
20 | | - expect(firstItem, findsOneWidget); |
21 | | - await tester.ensureVisible(firstItem); |
22 | | - await tester.tap(find.byType(LaunchItem).first); |
| 50 | + group('Launch Screen Tests', () { |
| 51 | + testWidgets('launch test', (tester) async { |
| 52 | + await pumpLaunchScreen(tester, locale: const Locale('en')); |
| 53 | + expectLaunchTexts('Flight #100'); |
| 54 | + }); |
23 | 55 |
|
24 | | - await tester.pumpAndSettle(); |
25 | | - expect(find.text('FalconSat'), findsOneWidget); |
| 56 | + testWidgets('launch uk test', (tester) async { |
| 57 | + await pumpLaunchScreen(tester, locale: const Locale('uk')); |
| 58 | + expectLaunchTexts( |
| 59 | + 'Політ #100', |
| 60 | + additionalTexts: ['Місія успішна'], |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + testWidgets('launch pt test', (tester) async { |
| 65 | + await pumpLaunchScreen(tester, locale: const Locale('pt')); |
| 66 | + expectLaunchTexts( |
| 67 | + 'Voo #100', |
| 68 | + additionalTexts: ['Missão bem-sucedida'], |
| 69 | + ); |
| 70 | + }); |
| 71 | + testWidgets('launch de test', (tester) async { |
| 72 | + await pumpLaunchScreen(tester, locale: const Locale('de')); |
| 73 | + expectLaunchTexts( |
| 74 | + 'Flug #100', |
| 75 | + additionalTexts: ['Mission erfolgreich'], |
| 76 | + ); |
| 77 | + }); |
26 | 78 | }); |
27 | 79 | } |
0 commit comments