Skip to content

Commit 30c4389

Browse files
authored
Added 8 widget tests (#221)
thanks for your contribution
1 parent d650740 commit 30c4389

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

test/percent_indicator_test.dart

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,180 @@ void main() {
1919
await tester.pumpWidget(MaterialApp(home: localWidget));
2020
expect(localWidget.percent, 0.0);
2121
});
22+
23+
testWidgets('show center widget in linear percent indicator widget',
24+
(WidgetTester tester) async {
25+
LinearPercentIndicator localWidget = LinearPercentIndicator(
26+
width: 100.0,
27+
center: Text('linear'),
28+
);
29+
30+
await tester.pumpWidget(MaterialApp(home: localWidget));
31+
32+
expect(find.byType(Center), findsOne);
33+
});
34+
35+
testWidgets('show center widget in circular percent indicator widget',
36+
(WidgetTester tester) async {
37+
CircularPercentIndicator localWidget = CircularPercentIndicator(
38+
radius: 20.0,
39+
center: Text('circular'),
40+
);
41+
42+
await tester.pumpWidget(MaterialApp(home: localWidget));
43+
44+
expect(find.byType(Center), findsOne);
45+
});
46+
47+
testWidgets('show header widget in circular percent indicator widget',
48+
(WidgetTester tester) async {
49+
CircularPercentIndicator localWidget = CircularPercentIndicator(
50+
radius: 20.0,
51+
header: Text('header'),
52+
);
53+
54+
await tester.pumpWidget(MaterialApp(home: localWidget));
55+
56+
final header = find.descendant(
57+
of: find.byType(Column),
58+
matching: find.byType(Text),
59+
);
60+
61+
final container = find.descendant(
62+
of: find.byType(Column),
63+
matching: find.byType(Container),
64+
);
65+
expect(header, findsExactly(1));
66+
expect(container, findsExactly(1));
67+
68+
expect(tester.getTopLeft(header).dy,
69+
lessThan(tester.getTopLeft(container).dy));
70+
});
71+
72+
testWidgets('show footer widget in circular percent indicator widget',
73+
(WidgetTester tester) async {
74+
CircularPercentIndicator localWidget = CircularPercentIndicator(
75+
radius: 20.0,
76+
footer: Text('footer'),
77+
);
78+
79+
await tester.pumpWidget(MaterialApp(home: localWidget));
80+
81+
final header = find.descendant(
82+
of: find.byType(Column),
83+
matching: find.byType(Text),
84+
);
85+
86+
final container = find.descendant(
87+
of: find.byType(Column),
88+
matching: find.byType(Container),
89+
);
90+
expect(header, findsExactly(1));
91+
expect(container, findsExactly(1));
92+
93+
expect(tester.getTopLeft(header).dy,
94+
greaterThan(tester.getTopLeft(container).dy));
95+
});
96+
97+
testWidgets('apply fillColor in circular percent indicator widget',
98+
(WidgetTester tester) async {
99+
CircularPercentIndicator localWidget = CircularPercentIndicator(
100+
radius: 20.0,
101+
fillColor: Colors.red,
102+
);
103+
104+
await tester.pumpWidget(MaterialApp(home: localWidget));
105+
106+
final material = find.byType(Material);
107+
108+
expect(material, findsOne);
109+
110+
expect((tester.firstWidget(material) as Material).color, Colors.red);
111+
});
112+
113+
testWidgets('apply fillColor in linear percent indicator widget',
114+
(WidgetTester tester) async {
115+
LinearPercentIndicator localWidget = LinearPercentIndicator(
116+
width: 100.0,
117+
fillColor: Colors.red,
118+
);
119+
120+
await tester.pumpWidget(MaterialApp(home: localWidget));
121+
122+
final container = find.ancestor(
123+
of: find.byType(Row),
124+
matching: find.byType(Container),
125+
);
126+
127+
expect((tester.firstWidget(container) as Container).color, Colors.red);
128+
});
129+
130+
testWidgets('testing percent animation in circular percent indicator widget',
131+
(WidgetTester tester) async {
132+
final animationController = AnimationController(
133+
vsync: tester,
134+
duration: const Duration(milliseconds: 200),
135+
);
136+
137+
await tester.pumpWidget(
138+
MaterialApp(
139+
home: AnimatedBuilder(
140+
animation: animationController,
141+
builder: (context, child) {
142+
return CircularPercentIndicator(
143+
radius: 100.0,
144+
fillColor: Colors.red,
145+
percent: animationController.value,
146+
);
147+
},
148+
),
149+
),
150+
);
151+
152+
animationController.forward();
153+
154+
await tester.pump(const Duration(milliseconds: 200));
155+
156+
await tester.pumpAndSettle();
157+
158+
final linear = find.byType(CircularPercentIndicator);
159+
160+
expect((tester.firstWidget(linear) as CircularPercentIndicator).percent, 1.0);
161+
162+
animationController.dispose();
163+
});
164+
testWidgets('testing percent animation in linear percent indicator widget',
165+
(WidgetTester tester) async {
166+
final animationController = AnimationController(
167+
vsync: tester,
168+
duration: const Duration(milliseconds: 200),
169+
);
170+
171+
await tester.pumpWidget(
172+
MaterialApp(
173+
home: AnimatedBuilder(
174+
animation: animationController,
175+
builder: (context, child) {
176+
return LinearPercentIndicator(
177+
width: 100.0,
178+
fillColor: Colors.red,
179+
percent: animationController.value,
180+
);
181+
},
182+
),
183+
),
184+
);
185+
186+
animationController.forward();
187+
188+
await tester.pump(const Duration(milliseconds: 200));
189+
190+
await tester.pumpAndSettle();
191+
192+
final linear = find.byType(LinearPercentIndicator);
193+
194+
expect((tester.firstWidget(linear) as LinearPercentIndicator).percent, 1.0);
195+
196+
animationController.dispose();
197+
});
22198
}

0 commit comments

Comments
 (0)