|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:getwidget/getwidget.dart'; |
| 4 | +import 'package:flutter/cupertino.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + final childWidget = Container( |
| 8 | + width: 60, |
| 9 | + height: 60, |
| 10 | + ); |
| 11 | + final bgcolor = Colors.teal; |
| 12 | + final fgcolor = Colors.transparent; |
| 13 | + |
| 14 | + testWidgets('GF Avatar can be created', (tester) async { |
| 15 | + final GFAvatar avatar = GFAvatar( |
| 16 | + backgroundColor: bgcolor, |
| 17 | + foregroundColor: fgcolor, |
| 18 | + size: GFSize.MEDIUM, |
| 19 | + child: childWidget); |
| 20 | + final TestApp app = TestApp(avatar); |
| 21 | + await tester.pumpWidget(app); |
| 22 | + await tester.pumpWidget(Container(child: childWidget)); |
| 23 | + expect(find.byWidget(childWidget), findsOneWidget); |
| 24 | + expect(app.avatar.backgroundColor, bgcolor); |
| 25 | + expect(app.avatar.foregroundColor, fgcolor); |
| 26 | + expect(app.avatar.size, GFSize.MEDIUM); |
| 27 | + expect(app.avatar.child, childWidget); |
| 28 | + }); |
| 29 | + |
| 30 | + testWidgets('GF Avatar with minradius & maxradius', (tester) async { |
| 31 | + const minradius = 10.0; |
| 32 | + const maxradius = 20.0; |
| 33 | + final GFAvatar avatar = GFAvatar( |
| 34 | + backgroundColor: bgcolor, |
| 35 | + foregroundColor: fgcolor, |
| 36 | + minRadius: minradius, |
| 37 | + maxRadius: maxradius, |
| 38 | + size: GFSize.MEDIUM, |
| 39 | + child: childWidget); |
| 40 | + final TestApp app = TestApp(avatar); |
| 41 | + await tester.pumpWidget(app); |
| 42 | + await tester.pumpWidget(Container(child: childWidget)); |
| 43 | + expect(find.byWidget(childWidget), findsOneWidget); |
| 44 | + expect(app.avatar.backgroundColor, bgcolor); |
| 45 | + expect(app.avatar.foregroundColor, fgcolor); |
| 46 | + expect(app.avatar.minRadius, minradius); |
| 47 | + expect(app.avatar.maxRadius, maxradius); |
| 48 | + expect(app.avatar.size, GFSize.MEDIUM); |
| 49 | + expect(app.avatar.child, childWidget); |
| 50 | + }); |
| 51 | + |
| 52 | + testWidgets('Circular GF Avatar with bgImage', (tester) async { |
| 53 | + const bgImage = NetworkImage( |
| 54 | + 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', |
| 55 | + ); |
| 56 | + |
| 57 | + const GFAvatar avatar = GFAvatar( |
| 58 | + backgroundImage: bgImage, |
| 59 | + shape: GFAvatarShape.circle, |
| 60 | + ); |
| 61 | + |
| 62 | + const TestApp app = TestApp(avatar); |
| 63 | + |
| 64 | + expect(app.avatar.backgroundImage, bgImage); |
| 65 | + expect(app.avatar.shape, GFAvatarShape.circle); |
| 66 | + }); |
| 67 | + |
| 68 | + testWidgets('Square GF Avatar with bgImage', (tester) async { |
| 69 | + const bgImage = NetworkImage( |
| 70 | + 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', |
| 71 | + ); |
| 72 | + |
| 73 | + const GFAvatar avatar = GFAvatar( |
| 74 | + backgroundImage: bgImage, |
| 75 | + shape: GFAvatarShape.square, |
| 76 | + ); |
| 77 | + |
| 78 | + const TestApp app = TestApp(avatar); |
| 79 | + |
| 80 | + expect(app.avatar.backgroundImage, bgImage); |
| 81 | + expect(app.avatar.shape, GFAvatarShape.square); |
| 82 | + }); |
| 83 | + |
| 84 | + testWidgets('Standard shape GF Avatar with bgImage', (tester) async { |
| 85 | + const bgImage = NetworkImage( |
| 86 | + 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', |
| 87 | + ); |
| 88 | + |
| 89 | + const GFAvatar avatar = GFAvatar( |
| 90 | + backgroundImage: bgImage, |
| 91 | + shape: GFAvatarShape.standard, |
| 92 | + ); |
| 93 | + |
| 94 | + const TestApp app = TestApp(avatar); |
| 95 | + |
| 96 | + expect(app.avatar.backgroundImage, bgImage); |
| 97 | + expect(app.avatar.shape, GFAvatarShape.standard); |
| 98 | + }); |
| 99 | +} |
| 100 | + |
| 101 | +class TestApp extends StatefulWidget { |
| 102 | + const TestApp(this.avatar); |
| 103 | + final GFAvatar avatar; |
| 104 | + @override |
| 105 | + _TestAppState createState() => _TestAppState(); |
| 106 | +} |
| 107 | + |
| 108 | +class _TestAppState extends State<TestApp> { |
| 109 | + @override |
| 110 | + Widget build(BuildContext context) => MaterialApp( |
| 111 | + home: Scaffold( |
| 112 | + body: Column( |
| 113 | + children: [ |
| 114 | + widget.avatar, |
| 115 | + ], |
| 116 | + ), |
| 117 | + ), |
| 118 | + ); |
| 119 | +} |
0 commit comments