|
4 | 4 | // utility that Flutter provides. For example, you can send tap and scroll |
5 | 5 | // gestures. You can also use WidgetTester to find child widgets in the widget |
6 | 6 | // tree, read text, and verify that the values of widget properties are correct. |
| 7 | +import 'package:flutter/material.dart'; |
7 | 8 | import 'package:flutter_test/flutter_test.dart'; |
| 9 | +import 'package:motion_toast/motion_toast.dart'; |
8 | 10 |
|
9 | | -// TODO: write unit tests for motion toast widget |
10 | 11 | void main() { |
11 | | - test('Counter increments smoke test', () async { |
12 | | - expect(true, isTrue); |
| 12 | + group('Success motion toast testing...', () { |
| 13 | + testWidgets( |
| 14 | + 'Basic motion toast widget test', |
| 15 | + (tester) async { |
| 16 | + var basicMotionToastWidget = MotionToast.success( |
| 17 | + description: const Text( |
| 18 | + 'Elegant notification description', |
| 19 | + ), |
| 20 | + ); |
| 21 | + await tester.pumpWidget( |
| 22 | + MaterialApp( |
| 23 | + home: Scaffold( |
| 24 | + body: Center( |
| 25 | + child: basicMotionToastWidget, |
| 26 | + ), |
| 27 | + ), |
| 28 | + ), |
| 29 | + ); |
| 30 | + expect( |
| 31 | + find.byType(Text), |
| 32 | + findsOneWidget, |
| 33 | + ); |
| 34 | + expect( |
| 35 | + find.byType(Icon), |
| 36 | + findsOneWidget, |
| 37 | + ); |
| 38 | + }, |
| 39 | + ); |
| 40 | + |
| 41 | + testWidgets( |
| 42 | + 'Motion toast with title widget test', |
| 43 | + (tester) async { |
| 44 | + var basicMotionToastWidget = MotionToast.success( |
| 45 | + description: const Text( |
| 46 | + 'Elegant notification description', |
| 47 | + ), |
| 48 | + title: const Text( |
| 49 | + 'Elegant notification title', |
| 50 | + ), |
| 51 | + ); |
| 52 | + await tester.pumpWidget( |
| 53 | + MaterialApp( |
| 54 | + home: Scaffold( |
| 55 | + body: Center( |
| 56 | + child: basicMotionToastWidget, |
| 57 | + ), |
| 58 | + ), |
| 59 | + ), |
| 60 | + ); |
| 61 | + expect( |
| 62 | + find.byType(Text), |
| 63 | + findsAtLeast(2), |
| 64 | + ); |
| 65 | + expect( |
| 66 | + find.byType(Icon), |
| 67 | + findsOneWidget, |
| 68 | + ); |
| 69 | + }, |
| 70 | + ); |
| 71 | + |
| 72 | + testWidgets( |
| 73 | + 'Motion toast with title and toast duration widget test', |
| 74 | + (tester) async { |
| 75 | + var basicMotionToastWidget = MotionToast.success( |
| 76 | + description: const Text( |
| 77 | + 'Elegant notification description', |
| 78 | + ), |
| 79 | + title: const Text( |
| 80 | + 'Elegant notification title', |
| 81 | + ), |
| 82 | + toastDuration: const Duration(seconds: 1), |
| 83 | + ); |
| 84 | + await tester.pumpWidget( |
| 85 | + MaterialApp( |
| 86 | + home: Scaffold( |
| 87 | + body: Center( |
| 88 | + child: basicMotionToastWidget, |
| 89 | + ), |
| 90 | + ), |
| 91 | + ), |
| 92 | + ); |
| 93 | + expect( |
| 94 | + find.byType(Text), |
| 95 | + findsAtLeast(2), |
| 96 | + ); |
| 97 | + expect( |
| 98 | + find.byType(Icon), |
| 99 | + findsOneWidget, |
| 100 | + ); |
| 101 | + expect( |
| 102 | + find.byType(MotionToast), |
| 103 | + findsOneWidget, |
| 104 | + ); |
| 105 | + }, |
| 106 | + ); |
13 | 107 | }); |
14 | 108 | } |
0 commit comments