|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc_app_template/features/launches/bloc/launches_bloc.dart'; |
| 3 | +import 'package:flutter_bloc_app_template/features/launches/launches_screen.dart'; |
| 4 | +import 'package:flutter_bloc_app_template/index.dart'; |
| 5 | +import 'package:flutter_test/flutter_test.dart'; |
| 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/launches/launches_screen_test.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 14 | + |
| 15 | + late LaunchesBloc launchesBloc; |
| 16 | + |
| 17 | + setUp(() { |
| 18 | + launchesBloc = MockLaunchesBloc(); |
| 19 | + }); |
| 20 | + |
| 21 | + group('Launches Screen Tests', () { |
| 22 | + testWidgets( |
| 23 | + 'renders CircularProgressIndicator ' |
| 24 | + 'when launches list state is initial', (tester) async { |
| 25 | + when(() => launchesBloc.state).thenReturn(const LaunchesLoadingState()); |
| 26 | + |
| 27 | + await tester.pumpLocalizedWidgetWithBloc<LaunchesBloc>( |
| 28 | + bloc: launchesBloc, |
| 29 | + child: const LaunchesList(), |
| 30 | + locale: const Locale('en'), |
| 31 | + ); |
| 32 | + |
| 33 | + await tester.pump(); |
| 34 | + |
| 35 | + expect(find.byType(CircularProgressIndicator), findsOneWidget); |
| 36 | + }); |
| 37 | + |
| 38 | + testWidgets( |
| 39 | + 'renders Empty list text ' |
| 40 | + 'when launches list state is success but with 0 items', (tester) async { |
| 41 | + when(() => launchesBloc.state).thenReturn(const LaunchesEmptyState()); |
| 42 | + await tester.pumpLocalizedWidgetWithBloc<LaunchesBloc>( |
| 43 | + bloc: launchesBloc, |
| 44 | + child: const LaunchesList(), |
| 45 | + locale: const Locale('en'), |
| 46 | + ); |
| 47 | + await tester.pumpAndSettle(); |
| 48 | + |
| 49 | + expect(find.text('Empty list'), findsOneWidget); |
| 50 | + }); |
| 51 | + |
| 52 | + testWidgets('launches test', ( |
| 53 | + WidgetTester tester, |
| 54 | + ) async { |
| 55 | + // app.main([]); |
| 56 | + // await tester.pumpAndSettle(); |
| 57 | + |
| 58 | + when(() => launchesBloc.state).thenReturn( |
| 59 | + const LaunchesSuccessState( |
| 60 | + launches: [ |
| 61 | + LaunchResource( |
| 62 | + id: '1', |
| 63 | + flightNumber: 1, |
| 64 | + missionName: 'FalconSat', |
| 65 | + launchDays: Since( |
| 66 | + '2021-10-01T00:00:00Z', |
| 67 | + ), |
| 68 | + launchTime: '00:00', |
| 69 | + rocket: RocketResource( |
| 70 | + rocketName: 'Rocket 1', |
| 71 | + rocketType: 'Type 1', |
| 72 | + ), |
| 73 | + launchSuccess: true, |
| 74 | + ) |
| 75 | + ], |
| 76 | + ), |
| 77 | + ); |
| 78 | + await tester.pumpLocalizedWidgetWithBloc<LaunchesBloc>( |
| 79 | + bloc: launchesBloc, |
| 80 | + child: const LaunchesList(), |
| 81 | + locale: const Locale('en'), |
| 82 | + ); |
| 83 | + await tester.pumpAndSettle(); |
| 84 | + |
| 85 | + final firstItem = find.byKey(const Key('FalconSat1')); |
| 86 | + |
| 87 | + expect(firstItem, findsOneWidget); |
| 88 | + await tester.ensureVisible(firstItem); |
| 89 | + }); |
| 90 | + }); |
| 91 | +} |
0 commit comments