|
| 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 | + final Widget childWidget = Container( |
| 7 | + width: 11, |
| 8 | + height: 22, |
| 9 | + ); |
| 10 | + |
| 11 | + const icon = Icon(Icons.home); |
| 12 | + const text = 'Hello'; |
| 13 | + |
| 14 | + const dividerRadius = BorderRadius.all(Radius.circular(2)); |
| 15 | + const textcolor = GFColors.INFO; |
| 16 | + const dividerposition = Alignment.center; |
| 17 | + |
| 18 | + testWidgets('GFTypograpgy can be created', (WidgetTester tester) async { |
| 19 | + final GFTypography typography = GFTypography( |
| 20 | + icon: icon, |
| 21 | + dividerBorderRadius: dividerRadius, |
| 22 | + text: text, |
| 23 | + textColor: textcolor, |
| 24 | + dividerAlignment: dividerposition, |
| 25 | + type: GFTypographyType.typo2, |
| 26 | + child: childWidget, |
| 27 | + ); |
| 28 | + |
| 29 | + final TestApp app = TestApp(typography); |
| 30 | + |
| 31 | + await tester.pumpWidget(app); |
| 32 | + |
| 33 | + await tester.pumpWidget(Container(child: childWidget)); |
| 34 | + expect(find.byWidget(childWidget), findsOneWidget); |
| 35 | + |
| 36 | + expect(app.typography.child, childWidget); |
| 37 | + expect(app.typography.icon, icon); |
| 38 | + expect(app.typography.dividerAlignment, Alignment.center); |
| 39 | + expect(app.typography.dividerBorderRadius, dividerRadius); |
| 40 | + expect(app.typography.textColor, textcolor); |
| 41 | + }); |
| 42 | + |
| 43 | + testWidgets('GF Typography with divider', (tester) async { |
| 44 | + const bool divider = true; |
| 45 | + |
| 46 | + const GFTypography typography = GFTypography( |
| 47 | + showDivider: divider, |
| 48 | + ); |
| 49 | + |
| 50 | + const TestApp app = TestApp(typography); |
| 51 | + |
| 52 | + expect(app.typography.showDivider, divider); |
| 53 | + }); |
| 54 | + |
| 55 | + testWidgets('GF Typography with opacity', (tester) async { |
| 56 | + final textopacity = Colors.black.withOpacity(0.56); |
| 57 | + |
| 58 | + final GFTypography typography = GFTypography( |
| 59 | + textColor: textopacity, |
| 60 | + ); |
| 61 | + |
| 62 | + final TestApp app = TestApp(typography); |
| 63 | + |
| 64 | + expect(app.typography.textColor, textopacity); |
| 65 | + }); |
| 66 | + |
| 67 | + testWidgets('GF Typography with Custom Heading', (tester) async { |
| 68 | + final textopacity = Colors.black.withOpacity(0.56); |
| 69 | + const bool divider = true; |
| 70 | + const icon = GFAvatar(); |
| 71 | + const colorfilter = ColorFilter.mode(Colors.black, BlendMode.darken); |
| 72 | + const bgImage = NetworkImage( |
| 73 | + 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', |
| 74 | + ); |
| 75 | + |
| 76 | + final GFTypography typography = GFTypography( |
| 77 | + textColor: textopacity, |
| 78 | + showDivider: divider, |
| 79 | + icon: icon, |
| 80 | + backgroundImage: bgImage, |
| 81 | + backgroundImagecolorFilter: colorfilter, |
| 82 | + ); |
| 83 | + |
| 84 | + final TestApp app = TestApp(typography); |
| 85 | + |
| 86 | + expect(app.typography.textColor, textopacity); |
| 87 | + expect(app.typography.showDivider, divider); |
| 88 | + expect(app.typography.icon, icon); |
| 89 | + expect(app.typography.backgroundImage, bgImage); |
| 90 | + expect(app.typography.backgroundImagecolorFilter, colorfilter); |
| 91 | + }); |
| 92 | +} |
| 93 | + |
| 94 | +class TestApp extends StatefulWidget { |
| 95 | + const TestApp(this.typography); |
| 96 | + |
| 97 | + final GFTypography typography; |
| 98 | + |
| 99 | + @override |
| 100 | + _TestAppState createState() => _TestAppState(); |
| 101 | +} |
| 102 | + |
| 103 | +class _TestAppState extends State<TestApp> { |
| 104 | + @override |
| 105 | + Widget build(BuildContext context) => MaterialApp( |
| 106 | + home: Scaffold( |
| 107 | + body: Column( |
| 108 | + children: [ |
| 109 | + Expanded( |
| 110 | + child: widget.typography, |
| 111 | + ) |
| 112 | + ], |
| 113 | + ), |
| 114 | + ), |
| 115 | + ); |
| 116 | +} |
0 commit comments