|
| 1 | +import 'package:card_swiper/card_swiper.dart'; |
| 2 | +import 'package:codephile/presentation/onboarding/onboarding_screen.dart'; |
| 3 | +import 'package:codephile/presentation/onboarding/widgets/onboarding_widgets.dart'; |
| 4 | +import 'package:flutter/material.dart'; |
| 5 | +import 'package:flutter_test/flutter_test.dart'; |
| 6 | + |
| 7 | +import '../../utils/pump_screen.dart'; |
| 8 | + |
| 9 | +void widgetTests() { |
| 10 | + group('OnboardingScreen -', () { |
| 11 | + testWidgets('contains sub-widgets', (tester) async { |
| 12 | + await pumpScreen(tester, () => OnboardingScreen()); |
| 13 | + |
| 14 | + expect(find.byType(BackgroundDecoration), findsOneWidget); |
| 15 | + expect(find.byType(NextButton), findsOneWidget); |
| 16 | + expect(find.byType(Swiper), findsOneWidget); |
| 17 | + expect(find.byType(OnboardingPage), findsOneWidget); |
| 18 | + |
| 19 | + /// The [PaginationDots] widget does not show up as anything special in |
| 20 | + /// the widget tree because of the idiosyncrasies of the package author. |
| 21 | + /// Hence this roundabout way of testing whether the widget is present. |
| 22 | + expect( |
| 23 | + find.byWidgetPredicate( |
| 24 | + (widget) => widget is Align && widget.child is Row, |
| 25 | + ), |
| 26 | + findsOneWidget, |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + testWidgets("contains first feature's data", (tester) async { |
| 31 | + await pumpScreen(tester, () => OnboardingScreen()); |
| 32 | + |
| 33 | + expect(find.text(pages[0].title), findsOneWidget); |
| 34 | + expect(find.text(pages[0].description), findsOneWidget); |
| 35 | + expect( |
| 36 | + find.byWidgetPredicate( |
| 37 | + (widget) => |
| 38 | + widget is Image && |
| 39 | + widget.image is AssetImage && |
| 40 | + (widget.image as AssetImage).assetName == pages[0].asset, |
| 41 | + ), |
| 42 | + findsOneWidget, |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + testWidgets('pressing NextButton takes user to next page', (tester) async { |
| 47 | + await pumpScreen(tester, () => OnboardingScreen()); |
| 48 | + |
| 49 | + for (var i = 0; i < pages.length; i++) { |
| 50 | + // Finds i^th feature's data |
| 51 | + expect(find.text(pages[i].title), findsOneWidget); |
| 52 | + expect(find.text(pages[i].description), findsOneWidget); |
| 53 | + expect( |
| 54 | + find.byWidgetPredicate( |
| 55 | + (widget) => |
| 56 | + widget is Image && |
| 57 | + widget.image is AssetImage && |
| 58 | + (widget.image as AssetImage).assetName == pages[i].asset, |
| 59 | + ), |
| 60 | + findsOneWidget, |
| 61 | + ); |
| 62 | + |
| 63 | + await tester.tap(find.byType(NextButton)); |
| 64 | + await tester.pumpAndSettle(); |
| 65 | + } |
| 66 | + |
| 67 | + // TODO(BURG3R5): Uncomment the next line when a HomeScreen widget has been created. |
| 68 | + // expect(find.byType(HomeScreen), findsOneWidget); |
| 69 | + }); |
| 70 | + }); |
| 71 | +} |
0 commit comments