Skip to content

Commit 5c2aa69

Browse files
authored
Merge pull request #51 from deepikahr/loader_testing
test cases for loader component added
2 parents 902a8cb + 4ea20ca commit 5c2aa69

File tree

1 file changed

+282
-0
lines changed

1 file changed

+282
-0
lines changed

test/loader_test.dart

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

0 commit comments

Comments
 (0)