|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:getwidget/getwidget.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + const text = '1'; |
| 7 | + const textStyle = TextStyle(fontSize: 14, color: Colors.black); |
| 8 | + const size = GFSize.SMALL; |
| 9 | + const textColor = GFColors.INFO; |
| 10 | + const color = Colors.amber; |
| 11 | + const border = |
| 12 | + BorderSide(color: Colors.tealAccent, width: 1, style: BorderStyle.solid); |
| 13 | + const shape = RoundedRectangleBorder( |
| 14 | + side: BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), |
| 15 | + borderRadius: BorderRadius.zero); |
| 16 | + const childWidget = Text('hey'); |
| 17 | + |
| 18 | + testWidgets('GF Badge without shape', (tester) async { |
| 19 | + // `GFBadge.shape` null. |
| 20 | + expect( |
| 21 | + () => GFBadge( |
| 22 | + shape: null, |
| 23 | + ), |
| 24 | + throwsAssertionError, |
| 25 | + ); |
| 26 | + }); |
| 27 | + |
| 28 | + testWidgets('GF Badge can be constructed', (tester) async { |
| 29 | + const GFBadge badge = GFBadge( |
| 30 | + text: text, |
| 31 | + textStyle: textStyle, |
| 32 | + size: size, |
| 33 | + ); |
| 34 | + |
| 35 | + const TestApp app = TestApp(badge); |
| 36 | + |
| 37 | + await tester.pumpWidget(app); |
| 38 | + |
| 39 | + expect(find.text('1'), findsOneWidget); |
| 40 | + |
| 41 | + expect(app.badge.text, text); |
| 42 | + expect(app.badge.textStyle, textStyle); |
| 43 | + expect(app.badge.size, size); |
| 44 | + |
| 45 | + await tester.pumpWidget(app); |
| 46 | + }); |
| 47 | + |
| 48 | + testWidgets('GF Badge with color and textColor', (tester) async { |
| 49 | + const GFBadge badge = GFBadge( |
| 50 | + text: text, |
| 51 | + size: size, |
| 52 | + textColor: textColor, |
| 53 | + color: color, |
| 54 | + ); |
| 55 | + |
| 56 | + const TestApp app = TestApp(badge); |
| 57 | + |
| 58 | + await tester.pumpWidget(app); |
| 59 | + |
| 60 | + expect(find.text('1'), findsOneWidget); |
| 61 | + |
| 62 | + expect(app.badge.text, text); |
| 63 | + expect(app.badge.size, size); |
| 64 | + expect(app.badge.textColor, textColor); |
| 65 | + expect(app.badge.color, color); |
| 66 | + |
| 67 | + await tester.pumpWidget(app); |
| 68 | + }); |
| 69 | + |
| 70 | + testWidgets( |
| 71 | + 'GF Badge with GFBadgeShape like circle, standard, square and pills', |
| 72 | + (tester) async { |
| 73 | + const GFBadge badge = GFBadge( |
| 74 | + text: text, |
| 75 | + size: size, |
| 76 | + textColor: textColor, |
| 77 | + color: color, |
| 78 | + shape: GFBadgeShape.circle, |
| 79 | + ); |
| 80 | + |
| 81 | + const TestApp app = TestApp(badge); |
| 82 | + |
| 83 | + await tester.pumpWidget(app); |
| 84 | + |
| 85 | + expect(find.text('1'), findsOneWidget); |
| 86 | + |
| 87 | + expect(app.badge.text, text); |
| 88 | + expect(app.badge.size, size); |
| 89 | + expect(app.badge.textColor, textColor); |
| 90 | + expect(app.badge.color, color); |
| 91 | + expect(app.badge.shape, GFBadgeShape.circle); |
| 92 | + |
| 93 | + await tester.pumpWidget(app); |
| 94 | + }); |
| 95 | + |
| 96 | + testWidgets('GF Badge with custom border and shape', (tester) async { |
| 97 | + const GFBadge badge = GFBadge( |
| 98 | + text: text, |
| 99 | + size: size, |
| 100 | + textColor: textColor, |
| 101 | + color: color, |
| 102 | + borderShape: shape, |
| 103 | + border: border, |
| 104 | + ); |
| 105 | + |
| 106 | + const TestApp app = TestApp(badge); |
| 107 | + |
| 108 | + await tester.pumpWidget(app); |
| 109 | + |
| 110 | + expect(find.text('1'), findsOneWidget); |
| 111 | + |
| 112 | + expect(app.badge.text, text); |
| 113 | + expect(app.badge.size, size); |
| 114 | + expect(app.badge.textColor, textColor); |
| 115 | + expect(app.badge.color, color); |
| 116 | + expect(app.badge.borderShape, shape); |
| 117 | + expect(app.badge.border, border); |
| 118 | + |
| 119 | + await tester.pumpWidget(app); |
| 120 | + }); |
| 121 | + |
| 122 | + testWidgets('GF Badge with custom child', (tester) async { |
| 123 | + const GFBadge badge = GFBadge( |
| 124 | + child: childWidget, |
| 125 | + size: size, |
| 126 | + ); |
| 127 | + |
| 128 | + const TestApp app = TestApp(badge); |
| 129 | + |
| 130 | + await tester.pumpWidget(app); |
| 131 | + |
| 132 | + expect(find.text('hey'), findsOneWidget); |
| 133 | + |
| 134 | + expect(app.badge.child, childWidget); |
| 135 | + |
| 136 | + await tester.pumpWidget(app); |
| 137 | + }); |
| 138 | +} |
| 139 | + |
| 140 | +class TestApp extends StatefulWidget { |
| 141 | + const TestApp(this.badge); |
| 142 | + |
| 143 | + final GFBadge badge; |
| 144 | + |
| 145 | + @override |
| 146 | + _TestAppState createState() => _TestAppState(); |
| 147 | +} |
| 148 | + |
| 149 | +class _TestAppState extends State<TestApp> { |
| 150 | + @override |
| 151 | + Widget build(BuildContext context) => MaterialApp( |
| 152 | + home: Scaffold( |
| 153 | + body: Column( |
| 154 | + children: [ |
| 155 | + widget.badge, |
| 156 | + ], |
| 157 | + ), |
| 158 | + ), |
| 159 | + ); |
| 160 | +} |
0 commit comments