-
-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathloader_test.dart
More file actions
207 lines (156 loc) · 5.57 KB
/
loader_test.dart
File metadata and controls
207 lines (156 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:getwidget/getwidget.dart';
void main() {
final Widget childWidget = Container(
width: 111,
height: 222,
);
const iconOne = Icon(Icons.directions_bike_sharp);
const iconTwo = Icon(Icons.directions_car);
const iconThree = Icon(Icons.directions_bus);
const duration = Duration(milliseconds: 1000);
const firstColor = Colors.teal;
const secondColor = Colors.tealAccent;
const thirdColor = Colors.tealAccent;
const stroke = 4.0;
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
testWidgets('GF Loader can be constructed', (tester) async {
final GFLoader loader = GFLoader(
loaderColorOne: firstColor,
loaderColorTwo: secondColor,
duration: duration,
type: GFLoaderType.ios,
loaderIconOne: iconOne,
loaderstrokeWidth: stroke,
size: GFSize.MEDIUM,
child: childWidget,
);
final TestApp app = TestApp(loader);
await tester.pumpWidget(app);
await tester.pumpWidget(Container(child: childWidget));
expect(find.byWidget(childWidget), findsOneWidget);
await tester.pump(duration);
expect(app.loader.child, childWidget);
expect(app.loader.loaderIconOne, iconOne);
expect(app.loader.loaderColorOne, firstColor);
expect(app.loader.loaderstrokeWidth, stroke);
expect(app.loader.size, GFSize.MEDIUM);
debugDefaultTargetPlatformOverride = null;
});
testWidgets('Basic GF Loader can be constructed', (tester) async {
const GFLoader loader = GFLoader();
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
});
testWidgets('GF Loader with icons can be constructed', (tester) async {
const customType = GFLoaderType.custom;
const GFLoader loader = GFLoader(
type: customType,
duration: duration,
loaderIconOne: iconOne,
loaderIconTwo: iconTwo,
loaderIconThree: iconThree,
loaderstrokeWidth: stroke,
);
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
await tester.pump(duration);
expect(app.loader.type, customType);
expect(app.loader.loaderIconOne, iconOne);
expect(app.loader.loaderIconTwo, iconTwo);
expect(app.loader.loaderIconThree, iconThree);
expect(app.loader.loaderstrokeWidth, stroke);
});
testWidgets('GF Loader with square type can be constructed', (tester) async {
const customType = GFLoaderType.square;
const GFLoader loader = GFLoader(
type: customType,
duration: duration,
loaderColorOne: firstColor,
loaderColorTwo: secondColor,
loaderColorThree: thirdColor,
loaderstrokeWidth: stroke,
);
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
await tester.pump(duration);
expect(app.loader.type, customType);
expect(app.loader.loaderColorOne, firstColor);
expect(app.loader.loaderColorTwo, secondColor);
expect(app.loader.loaderColorThree, thirdColor);
expect(app.loader.loaderstrokeWidth, stroke);
});
testWidgets('GF Loader with round type can be constructed', (tester) async {
const customType = GFLoaderType.circle;
const GFLoader loader = GFLoader(
type: customType,
duration: duration,
loaderColorOne: firstColor,
loaderColorTwo: secondColor,
loaderColorThree: thirdColor,
loaderstrokeWidth: stroke,
);
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
await tester.pump(duration);
expect(app.loader.type, customType);
expect(app.loader.loaderColorOne, firstColor);
expect(app.loader.loaderColorTwo, secondColor);
expect(app.loader.loaderColorThree, thirdColor);
expect(app.loader.loaderstrokeWidth, stroke);
});
testWidgets('GF Loader with android type loader can be constructed',
(tester) async {
const customType = GFLoaderType.android;
const color = AlwaysStoppedAnimation<Color>(Colors.green);
const GFLoader loader =
GFLoader(type: customType, androidLoaderColor: color);
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
expect(app.loader.type, customType);
expect(app.loader.androidLoaderColor, color);
});
testWidgets('GF Loader with custom loader can be constructed using child',
(tester) async {
const customType = GFLoaderType.custom;
final GFLoader loader = GFLoader(type: customType, child: childWidget);
final TestApp app = TestApp(loader);
await tester.pumpWidget(app);
await tester.pumpWidget(Container(child: childWidget));
expect(find.byWidget(childWidget), findsOneWidget);
await tester.pump(duration);
expect(app.loader.child, childWidget);
expect(app.loader.type, customType);
});
testWidgets('Custom GF Loader can be constructed with wrong type',
(tester) async {
const GFLoader loader = GFLoader(
type: GFLoaderType.custom,
loaderIconOne: iconOne,
);
const TestApp app = TestApp(loader);
await tester.pumpWidget(app);
expect(app.loader.type, GFLoaderType.custom, reason: 'custom icon');
expect(app.loader.loaderIconOne, iconOne);
});
}
class TestApp extends StatefulWidget {
const TestApp(this.loader);
final GFLoader loader;
@override
_TestAppState createState() => _TestAppState();
}
class _TestAppState extends State<TestApp> {
@override
Widget build(BuildContext context) => MaterialApp(
home: Scaffold(
body: Column(
children: [
widget.loader,
],
),
),
);
}