|
| 1 | +import 'package:flutter/foundation.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:getwidget/getwidget.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + final Widget childWidget = Container( |
| 8 | + width: 111, |
| 9 | + height: 222, |
| 10 | + ); |
| 11 | + |
| 12 | + const iconOne = Icon(Icons.directions_bike_sharp); |
| 13 | + const iconTwo = Icon(Icons.directions_car); |
| 14 | + const iconThree = Icon(Icons.directions_bus); |
| 15 | + |
| 16 | + const duration = Duration(milliseconds: 1000); |
| 17 | + |
| 18 | + const firstColor = Colors.teal; |
| 19 | + const secondColor = Colors.tealAccent; |
| 20 | + const thirdColor = Colors.tealAccent; |
| 21 | + |
| 22 | + const stroke = 4.0; |
| 23 | + |
| 24 | + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; |
| 25 | + |
| 26 | + // testWidgets('Asserts.', (tester) async { |
| 27 | + // expect( |
| 28 | + // () => GFLoader( |
| 29 | + // |
| 30 | + // ), |
| 31 | + // throwsAssertionError, |
| 32 | + // ); |
| 33 | + // |
| 34 | + // expect( |
| 35 | + // () => GFLoader( |
| 36 | + // |
| 37 | + // ), |
| 38 | + // throwsAssertionError, |
| 39 | + // ); |
| 40 | + // }); |
| 41 | + |
| 42 | + testWidgets('GF Loader can be constructed', (tester) async { |
| 43 | + final GFLoader loader = GFLoader( |
| 44 | + loaderColorOne: firstColor, |
| 45 | + loaderColorTwo: secondColor, |
| 46 | + duration: duration, |
| 47 | + type: GFLoaderType.ios, |
| 48 | + loaderIconOne: iconOne, |
| 49 | + // androidLoaderColor : Colors.amber, |
| 50 | + loaderstrokeWidth: stroke, |
| 51 | + size: GFSize.MEDIUM, |
| 52 | + child: childWidget, |
| 53 | + ); |
| 54 | + |
| 55 | + final TestApp app = TestApp(loader); |
| 56 | + |
| 57 | + await tester.pumpWidget(app); |
| 58 | + |
| 59 | + await tester.pumpWidget(Container(child: childWidget)); |
| 60 | + expect(find.byWidget(childWidget), findsOneWidget); |
| 61 | + await tester.pump(duration); |
| 62 | + |
| 63 | + expect(app.loader.child, childWidget); |
| 64 | + expect(app.loader.loaderIconOne, iconOne); |
| 65 | + expect(app.loader.loaderColorOne, firstColor); |
| 66 | + expect(app.loader.loaderstrokeWidth, stroke); |
| 67 | + expect(app.loader.size, GFSize.MEDIUM); |
| 68 | + |
| 69 | + debugDefaultTargetPlatformOverride = null; |
| 70 | + }); |
| 71 | + |
| 72 | + testWidgets('Basic GF Loader can be constructed', (tester) async { |
| 73 | + const GFLoader loader = GFLoader(); |
| 74 | + |
| 75 | + const TestApp app = TestApp(loader); |
| 76 | + |
| 77 | + await tester.pumpWidget(app); |
| 78 | + }); |
| 79 | + |
| 80 | + testWidgets('GF Loader with icons can be constructed', (tester) async { |
| 81 | + const customType = GFLoaderType.custom; |
| 82 | + |
| 83 | + const GFLoader loader = GFLoader( |
| 84 | + type: customType, |
| 85 | + duration: duration, |
| 86 | + loaderIconOne: iconOne, |
| 87 | + loaderIconTwo: iconTwo, |
| 88 | + loaderIconThree: iconThree, |
| 89 | + loaderstrokeWidth: stroke, |
| 90 | + ); |
| 91 | + |
| 92 | + const TestApp app = TestApp(loader); |
| 93 | + |
| 94 | + await tester.pumpWidget(app); |
| 95 | + |
| 96 | + await tester.pump(duration); |
| 97 | + |
| 98 | + expect(app.loader.type, customType); |
| 99 | + expect(app.loader.loaderIconOne, iconOne); |
| 100 | + expect(app.loader.loaderIconTwo, iconTwo); |
| 101 | + expect(app.loader.loaderIconThree, iconThree); |
| 102 | + expect(app.loader.loaderstrokeWidth, stroke); |
| 103 | + }); |
| 104 | + |
| 105 | + // testWidgets('Asserts.', (tester) async { |
| 106 | + // // when type is null |
| 107 | + // |
| 108 | + // expect(() => GFLoader( |
| 109 | + // type: null, |
| 110 | + // loaderIconOne : iconOne, |
| 111 | + // loaderIconTwo: iconTwo, |
| 112 | + // loaderIconThree: iconThree, |
| 113 | + // ), |
| 114 | + // throwsAssertionError, |
| 115 | + // ); |
| 116 | + // }); |
| 117 | + |
| 118 | + testWidgets('GF Loader with square type can be constructed', (tester) async { |
| 119 | + const customType = GFLoaderType.square; |
| 120 | + |
| 121 | + const GFLoader loader = GFLoader( |
| 122 | + type: customType, |
| 123 | + duration: duration, |
| 124 | + loaderColorOne: firstColor, |
| 125 | + loaderColorTwo: secondColor, |
| 126 | + loaderColorThree: thirdColor, |
| 127 | + loaderstrokeWidth: stroke, |
| 128 | + ); |
| 129 | + |
| 130 | + const TestApp app = TestApp(loader); |
| 131 | + |
| 132 | + await tester.pumpWidget(app); |
| 133 | + |
| 134 | + await tester.pump(duration); |
| 135 | + |
| 136 | + expect(app.loader.type, customType); |
| 137 | + expect(app.loader.loaderColorOne, firstColor); |
| 138 | + expect(app.loader.loaderColorTwo, secondColor); |
| 139 | + expect(app.loader.loaderColorThree, thirdColor); |
| 140 | + expect(app.loader.loaderstrokeWidth, stroke); |
| 141 | + }); |
| 142 | + |
| 143 | + testWidgets('GF Loader with round type can be constructed', (tester) async { |
| 144 | + const customType = GFLoaderType.circle; |
| 145 | + |
| 146 | + const GFLoader loader = GFLoader( |
| 147 | + type: customType, |
| 148 | + duration: duration, |
| 149 | + loaderColorOne: firstColor, |
| 150 | + loaderColorTwo: secondColor, |
| 151 | + loaderColorThree: thirdColor, |
| 152 | + loaderstrokeWidth: stroke, |
| 153 | + ); |
| 154 | + |
| 155 | + const TestApp app = TestApp(loader); |
| 156 | + |
| 157 | + await tester.pumpWidget(app); |
| 158 | + |
| 159 | + await tester.pump(duration); |
| 160 | + |
| 161 | + expect(app.loader.type, customType); |
| 162 | + expect(app.loader.loaderColorOne, firstColor); |
| 163 | + expect(app.loader.loaderColorTwo, secondColor); |
| 164 | + expect(app.loader.loaderColorThree, thirdColor); |
| 165 | + expect(app.loader.loaderstrokeWidth, stroke); |
| 166 | + }); |
| 167 | + |
| 168 | + testWidgets('GF Loader with android type loader can be constructed', |
| 169 | + (tester) async { |
| 170 | + const customType = GFLoaderType.android; |
| 171 | + const color = AlwaysStoppedAnimation<Color>(Colors.green); |
| 172 | + |
| 173 | + const GFLoader loader = |
| 174 | + GFLoader(type: customType, androidLoaderColor: color); |
| 175 | + |
| 176 | + const TestApp app = TestApp(loader); |
| 177 | + |
| 178 | + await tester.pumpWidget(app); |
| 179 | + |
| 180 | + expect(app.loader.type, customType); |
| 181 | + expect(app.loader.androidLoaderColor, color); |
| 182 | + }); |
| 183 | + |
| 184 | + // testWidgets('Asserts.', (tester) async { |
| 185 | + // // when type is null |
| 186 | + // |
| 187 | + // // expect(() => GFLoader( |
| 188 | + // // type: null, |
| 189 | + // // loaderIconOne : iconOne, |
| 190 | + // // loaderIconTwo: iconTwo, |
| 191 | + // // loaderIconThree: iconThree, |
| 192 | + // // ), |
| 193 | + // // throwsAssertionError, |
| 194 | + // // |
| 195 | + // // ); |
| 196 | + // |
| 197 | + // const GFLoader loader = GFLoader( |
| 198 | + // type: null, |
| 199 | + // loaderIconOne : iconOne, |
| 200 | + // loaderIconTwo: iconTwo, |
| 201 | + // loaderIconThree: iconThree, |
| 202 | + // ); |
| 203 | + // |
| 204 | + // const TestApp app = TestApp(loader); |
| 205 | + // |
| 206 | + // await tester.pumpWidget(app); |
| 207 | + // |
| 208 | + // expect( |
| 209 | + // tester.takeException(), |
| 210 | + // isA<FlutterError>().having( |
| 211 | + // (error) => error.message, |
| 212 | + // 'message', |
| 213 | + // 'Type should be custom for icons loader to display', |
| 214 | + // ), |
| 215 | + // ); |
| 216 | + // }); |
| 217 | + |
| 218 | + testWidgets('GF Loader with custom loader can be constructed using child', |
| 219 | + (tester) async { |
| 220 | + const customType = GFLoaderType.custom; |
| 221 | + |
| 222 | + final GFLoader loader = GFLoader(type: customType, child: childWidget); |
| 223 | + |
| 224 | + final TestApp app = TestApp(loader); |
| 225 | + |
| 226 | + await tester.pumpWidget(app); |
| 227 | + |
| 228 | + await tester.pumpWidget(Container(child: childWidget)); |
| 229 | + expect(find.byWidget(childWidget), findsOneWidget); |
| 230 | + await tester.pump(duration); |
| 231 | + |
| 232 | + expect(app.loader.child, childWidget); |
| 233 | + expect(app.loader.type, customType); |
| 234 | + }); |
| 235 | +} |
| 236 | + |
| 237 | +class TestApp extends StatefulWidget { |
| 238 | + const TestApp(this.loader); |
| 239 | + |
| 240 | + final GFLoader loader; |
| 241 | + |
| 242 | + @override |
| 243 | + _TestAppState createState() => _TestAppState(); |
| 244 | +} |
| 245 | + |
| 246 | +class _TestAppState extends State<TestApp> { |
| 247 | + @override |
| 248 | + Widget build(BuildContext context) => MaterialApp( |
| 249 | + home: Scaffold( |
| 250 | + body: Column( |
| 251 | + children: [ |
| 252 | + widget.loader, |
| 253 | + ], |
| 254 | + ), |
| 255 | + ), |
| 256 | + ); |
| 257 | +} |
0 commit comments