Skip to content

Commit 19134dc

Browse files
committed
gfrating test cases
1 parent d8ae8c0 commit 19134dc

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

test/rating_test.dart

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
const color = Colors.teal;
8+
const bordercolor = Colors.black;
9+
const spacing = 1.0;
10+
const value = 2.0;
11+
const itemcount = 5;
12+
const size = GFSize.MEDIUM;
13+
const filledicon = Icon(Icons.star);
14+
const halffilled = Icon(Icons.star_border);
15+
const allowhalfRating = true;
16+
const showtextForm = false;
17+
const suffixicon = Icon(Icons.face_outlined);
18+
const margin = EdgeInsets.symmetric(vertical: 16);
19+
const padding = EdgeInsets.symmetric(horizontal: 16);
20+
const inputdecorations = InputDecoration(
21+
icon: Icon(Icons.face_outlined),
22+
labelText: 'Hi',
23+
labelStyle: TextStyle(fontSize: 14, color: Colors.black));
24+
final ratingController = TextEditingController();
25+
final customController = TextEditingController();
26+
27+
testWidgets('GF Rating can be created.', (tester) async {
28+
const GFRating rating = GFRating(
29+
itemCount: itemcount,
30+
inputDecorations: inputdecorations,
31+
spacing: spacing,
32+
value: value,
33+
margin: margin,
34+
padding: padding,
35+
size: size,
36+
color: color,
37+
borderColor: bordercolor,
38+
);
39+
40+
const TestApp app = TestApp(rating);
41+
42+
await tester.pumpWidget(app);
43+
expect(app.rating.itemCount, itemcount);
44+
expect(app.rating.inputDecorations, inputdecorations);
45+
expect(app.rating.spacing, spacing);
46+
expect(app.rating.value, value);
47+
expect(app.rating.margin, margin);
48+
expect(app.rating.padding, padding);
49+
expect(app.rating.size, size);
50+
expect(app.rating.color, color);
51+
expect(app.rating.borderColor, bordercolor);
52+
});
53+
54+
testWidgets('GF Rating with icons.', (tester) async {
55+
const GFRating rating = GFRating(
56+
itemCount: itemcount,
57+
size: size,
58+
color: color,
59+
filledIcon: filledicon,
60+
);
61+
62+
const TestApp app = TestApp(rating);
63+
64+
await tester.pumpWidget(app);
65+
expect(app.rating.itemCount, itemcount);
66+
expect(app.rating.size, size);
67+
expect(app.rating.color, color);
68+
expect(app.rating.filledIcon, filledicon);
69+
});
70+
71+
testWidgets('GF Rating with half rating property.', (tester) async {
72+
const GFRating rating = GFRating(
73+
itemCount: itemcount,
74+
size: size,
75+
color: color,
76+
filledIcon: filledicon,
77+
halfFilledIcon: halffilled,
78+
allowHalfRating: allowhalfRating,
79+
);
80+
81+
const TestApp app = TestApp(rating);
82+
83+
await tester.pumpWidget(app);
84+
expect(app.rating.itemCount, itemcount);
85+
expect(app.rating.size, size);
86+
expect(app.rating.color, color);
87+
expect(app.rating.filledIcon, filledicon);
88+
expect(app.rating.halfFilledIcon, halffilled);
89+
expect(app.rating.allowHalfRating, allowhalfRating);
90+
});
91+
92+
testWidgets('GF Rating using textformfield data input.', (tester) async {
93+
final GFRating rating = GFRating(
94+
itemCount: itemcount,
95+
size: size,
96+
color: color,
97+
filledIcon: filledicon,
98+
controller: ratingController,
99+
showTextForm: showtextForm,
100+
);
101+
102+
final TestApp app = TestApp(rating);
103+
104+
await tester.pumpWidget(app);
105+
expect(app.rating.itemCount, itemcount);
106+
expect(app.rating.size, size);
107+
expect(app.rating.color, color);
108+
expect(app.rating.filledIcon, filledicon);
109+
expect(app.rating.controller, ratingController);
110+
expect(app.rating.showTextForm, showtextForm);
111+
});
112+
113+
testWidgets('Custom GF Rating using textformfield & icons.', (tester) async {
114+
final GFRating rating = GFRating(
115+
itemCount: itemcount,
116+
size: size,
117+
color: color,
118+
filledIcon: filledicon,
119+
controller: customController,
120+
suffixIcon: suffixicon,
121+
showTextForm: showtextForm,
122+
);
123+
124+
final TestApp app = TestApp(rating);
125+
126+
await tester.pumpWidget(app);
127+
expect(app.rating.itemCount, itemcount);
128+
expect(app.rating.size, size);
129+
expect(app.rating.color, color);
130+
expect(app.rating.filledIcon, filledicon);
131+
expect(app.rating.controller, customController);
132+
expect(app.rating.suffixIcon, suffixicon);
133+
expect(app.rating.showTextForm, showtextForm);
134+
});
135+
}
136+
137+
class TestApp extends StatefulWidget {
138+
const TestApp(this.rating);
139+
final GFRating rating;
140+
@override
141+
_TestAppState createState() => _TestAppState();
142+
}
143+
144+
class _TestAppState extends State<TestApp> {
145+
@override
146+
Widget build(BuildContext context) => MaterialApp(
147+
home: Scaffold(
148+
body: Column(
149+
children: [
150+
widget.rating,
151+
],
152+
),
153+
),
154+
);
155+
}

0 commit comments

Comments
 (0)