Skip to content

Commit c1eaa22

Browse files
Merge pull request #4 from sipra-acharya/widget_testing
gfborder & gfalert test cases
2 parents c1871e5 + d8ae8c0 commit c1eaa22

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed

test/alert_test.dart

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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: 100,
9+
height: 100,
10+
);
11+
final bgcolor = Colors.teal;
12+
const contentchild = Icon(Icons.umbrella);
13+
const child = Text('Get Widget');
14+
15+
testWidgets('GF Alert can be created.', (tester) async {
16+
final GFAlert alert = GFAlert(
17+
backgroundColor: bgcolor,
18+
contentChild: contentchild,
19+
child: childWidget);
20+
21+
final TestApp app = TestApp(alert);
22+
23+
await tester.pumpWidget(Container(child: childWidget));
24+
expect(find.byWidget(childWidget), findsOneWidget);
25+
expect(app.alert.backgroundColor, bgcolor);
26+
expect(app.alert.contentChild, contentchild);
27+
expect(app.alert.child, childWidget);
28+
});
29+
30+
testWidgets('Basic GF Alert.', (tester) async {
31+
const basicType = GFAlertType.basic;
32+
33+
final GFAlert alert = GFAlert(
34+
backgroundColor: bgcolor,
35+
contentChild: contentchild,
36+
type: basicType,
37+
child: child);
38+
39+
final TestApp app = TestApp(alert);
40+
41+
await tester.pumpWidget(Container(child: childWidget));
42+
expect(find.byWidget(childWidget), findsOneWidget);
43+
expect(app.alert.backgroundColor, bgcolor);
44+
expect(app.alert.contentChild, contentchild);
45+
expect(app.alert.type, basicType);
46+
expect(app.alert.child, child);
47+
});
48+
49+
testWidgets('Rounded GF Alert.', (tester) async {
50+
const roundedType = GFAlertType.rounded;
51+
52+
const GFAlert alert =
53+
GFAlert(contentChild: contentchild, type: roundedType, child: child);
54+
55+
const TestApp app = TestApp(alert);
56+
57+
await tester.pumpWidget(Container(child: childWidget));
58+
expect(find.byWidget(childWidget), findsOneWidget);
59+
expect(app.alert.contentChild, contentchild);
60+
expect(app.alert.type, roundedType);
61+
expect(app.alert.child, child);
62+
});
63+
64+
testWidgets('Fullwidth GF Alert.', (tester) async {
65+
const basicType = GFAlertType.basic;
66+
const fullWidth = 400.0;
67+
68+
const GFAlert alert = GFAlert(
69+
width: fullWidth,
70+
contentChild: contentchild,
71+
type: basicType,
72+
child: child);
73+
74+
const TestApp app = TestApp(alert);
75+
76+
await tester.pumpWidget(Container(child: childWidget));
77+
expect(find.byWidget(childWidget), findsOneWidget);
78+
expect(app.alert.width, fullWidth);
79+
expect(app.alert.contentChild, contentchild);
80+
expect(app.alert.type, basicType);
81+
expect(app.alert.child, child);
82+
});
83+
84+
testWidgets('Customized GF Alert.', (tester) async {
85+
const basicType = GFAlertType.basic;
86+
final customBottombar = Row(
87+
mainAxisAlignment: MainAxisAlignment.end,
88+
children: <Widget>[
89+
GFButton(
90+
shape: GFButtonShape.square,
91+
color: GFColors.LIGHT,
92+
onPressed: () {},
93+
child: const Text(
94+
'Skip',
95+
style: TextStyle(color: Colors.black),
96+
),
97+
),
98+
const SizedBox(
99+
width: 5,
100+
),
101+
GFButton(
102+
shape: GFButtonShape.square,
103+
type: GFButtonType.outline2x,
104+
icon: const Icon(
105+
Icons.keyboard_arrow_right,
106+
color: GFColors.PRIMARY,
107+
),
108+
position: GFPosition.end,
109+
text: 'Learn More',
110+
onPressed: () {},
111+
)
112+
],
113+
);
114+
final GFAlert alert = GFAlert(
115+
contentChild: contentchild,
116+
type: basicType,
117+
bottombar: customBottombar,
118+
child: child);
119+
120+
final TestApp app = TestApp(alert);
121+
122+
await tester.pumpWidget(Container(child: childWidget));
123+
expect(find.byWidget(childWidget), findsOneWidget);
124+
expect(app.alert.contentChild, contentchild);
125+
expect(app.alert.type, basicType);
126+
expect(app.alert.child, child);
127+
});
128+
129+
testWidgets('GF Alert with alignment.', (tester) async {
130+
const alignment = Alignment.bottomRight;
131+
132+
const GFAlert alert =
133+
GFAlert(contentChild: contentchild, alignment: alignment, child: child);
134+
135+
const TestApp app = TestApp(alert);
136+
137+
await tester.pumpWidget(Container(child: childWidget));
138+
expect(find.byWidget(childWidget), findsOneWidget);
139+
expect(app.alert.contentChild, contentchild);
140+
expect(app.alert.alignment, alignment);
141+
expect(app.alert.child, child);
142+
});
143+
}
144+
145+
class TestApp extends StatefulWidget {
146+
const TestApp(this.alert);
147+
final GFAlert alert;
148+
@override
149+
_TestAppState createState() => _TestAppState();
150+
}
151+
152+
class _TestAppState extends State<TestApp> {
153+
@override
154+
Widget build(BuildContext context) => MaterialApp(
155+
home: Scaffold(
156+
body: Column(
157+
children: [
158+
widget.alert,
159+
],
160+
),
161+
),
162+
);
163+
}

test/border_test.dart

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ void main() {
179179
expect(find.byWidget(childWidget), findsOneWidget);
180180
expect(app.border.color, color);
181181
expect(app.border.type, typeoval);
182+
expect(app.border.strokeWidth, stroke);
183+
expect(app.border.dashedLine, [3, 1]);
182184
expect(app.border.child, text);
183185
});
184186

@@ -200,6 +202,91 @@ void main() {
200202
expect(find.byWidget(childWidget), findsOneWidget);
201203
expect(app.border.color, color);
202204
expect(app.border.type, typecircular);
205+
expect(app.border.dashedLine, [3, 1]);
206+
expect(app.border.strokeWidth, stroke);
207+
expect(app.border.child, text);
208+
});
209+
210+
testWidgets('Dotted GF Border.', (tester) async {
211+
const typerect = GFBorderType.rect;
212+
213+
final GFBorder border = GFBorder(
214+
color: color,
215+
type: typerect,
216+
// ignore: prefer_const_literals_to_create_immutables
217+
dashedLine: [2, 1],
218+
child: text);
219+
220+
final TestApp app = TestApp(border);
221+
222+
await tester.pumpWidget(Container(child: childWidget));
223+
expect(find.byWidget(childWidget), findsOneWidget);
224+
expect(app.border.color, color);
225+
expect(app.border.type, typerect);
226+
expect(app.border.dashedLine, [2, 1]);
227+
expect(app.border.child, text);
228+
});
229+
230+
testWidgets('Dotted GF Border with radius.', (tester) async {
231+
const typerRect = GFBorderType.rRect;
232+
const radius = Radius.circular(20);
233+
234+
final GFBorder border = GFBorder(
235+
color: color,
236+
type: typerRect,
237+
// ignore: prefer_const_literals_to_create_immutables
238+
dashedLine: [2, 1],
239+
radius: radius,
240+
child: text);
241+
242+
final TestApp app = TestApp(border);
243+
244+
await tester.pumpWidget(Container(child: childWidget));
245+
expect(find.byWidget(childWidget), findsOneWidget);
246+
expect(app.border.color, color);
247+
expect(app.border.type, typerRect);
248+
expect(app.border.dashedLine, [2, 1]);
249+
expect(app.border.radius, radius);
250+
expect(app.border.child, text);
251+
});
252+
253+
testWidgets('Oval dotted GF Border.', (tester) async {
254+
const typeoval = GFBorderType.oval;
255+
256+
final GFBorder border = GFBorder(
257+
color: color,
258+
type: typeoval,
259+
// ignore: prefer_const_literals_to_create_immutables
260+
dashedLine: [2, 1],
261+
child: text);
262+
263+
final TestApp app = TestApp(border);
264+
265+
await tester.pumpWidget(Container(child: childWidget));
266+
expect(find.byWidget(childWidget), findsOneWidget);
267+
expect(app.border.color, color);
268+
expect(app.border.type, typeoval);
269+
expect(app.border.dashedLine, [2, 1]);
270+
expect(app.border.child, text);
271+
});
272+
273+
testWidgets('Circular dotted GF Border.', (tester) async {
274+
const typecircle = GFBorderType.circle;
275+
276+
final GFBorder border = GFBorder(
277+
color: color,
278+
type: typecircle,
279+
// ignore: prefer_const_literals_to_create_immutables
280+
dashedLine: [2, 1],
281+
child: text);
282+
283+
final TestApp app = TestApp(border);
284+
285+
await tester.pumpWidget(Container(child: childWidget));
286+
expect(find.byWidget(childWidget), findsOneWidget);
287+
expect(app.border.color, color);
288+
expect(app.border.type, typecircle);
289+
expect(app.border.dashedLine, [2, 1]);
203290
expect(app.border.child, text);
204291
});
205292
}

0 commit comments

Comments
 (0)