Skip to content

Commit 2de0b0a

Browse files
committed
gfrating test cases
1 parent 19134dc commit 2de0b0a

File tree

1 file changed

+106
-96
lines changed

1 file changed

+106
-96
lines changed

test/rating_test.dart

Lines changed: 106 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ void main() {
77
const color = Colors.teal;
88
const bordercolor = Colors.black;
99
const spacing = 1.0;
10-
const value = 2.0;
1110
const itemcount = 5;
1211
const size = GFSize.MEDIUM;
1312
const filledicon = Icon(Icons.star);
@@ -23,114 +22,125 @@ void main() {
2322
labelStyle: TextStyle(fontSize: 14, color: Colors.black));
2423
final ratingController = TextEditingController();
2524
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,
25+
double rating = 3;
26+
27+
testWidgets('Basic GF Rating can be created.', (WidgetTester tester) async {
28+
await tester.pumpWidget(
29+
MaterialApp(
30+
home: StatefulBuilder(
31+
builder: (BuildContext context, StateSetter setState) => Material(
32+
child: GFRating(
33+
itemCount: itemcount,
34+
inputDecorations: inputdecorations,
35+
spacing: spacing,
36+
value: rating,
37+
margin: margin,
38+
padding: padding,
39+
size: size,
40+
color: color,
41+
borderColor: bordercolor,
42+
onChanged: (value) {
43+
setState(() {
44+
rating = value;
45+
});
46+
},
47+
))),
48+
),
3849
);
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);
5250
});
5351

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,
52+
testWidgets('GF Rating with icons.', (WidgetTester tester) async {
53+
await tester.pumpWidget(
54+
MaterialApp(
55+
home: StatefulBuilder(
56+
builder: (BuildContext context, StateSetter setState) => Material(
57+
child: GFRating(
58+
itemCount: itemcount,
59+
size: size,
60+
color: color,
61+
filledIcon: filledicon,
62+
value: rating,
63+
onChanged: (value) {
64+
setState(() {
65+
rating = value;
66+
});
67+
},
68+
))),
69+
),
6070
);
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);
6971
});
7072

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,
73+
testWidgets('GF Rating with half rating property.',
74+
(WidgetTester tester) async {
75+
await tester.pumpWidget(
76+
MaterialApp(
77+
home: StatefulBuilder(
78+
builder: (BuildContext context, StateSetter setState) => Material(
79+
child: GFRating(
80+
itemCount: itemcount,
81+
size: size,
82+
color: color,
83+
filledIcon: filledicon,
84+
halfFilledIcon: halffilled,
85+
allowHalfRating: allowhalfRating,
86+
value: rating,
87+
onChanged: (value) {
88+
setState(() {
89+
rating = value;
90+
});
91+
},
92+
))),
93+
),
7994
);
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);
9095
});
9196

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,
97+
testWidgets('GF Rating using textformfield data input.',
98+
(WidgetTester tester) async {
99+
await tester.pumpWidget(
100+
MaterialApp(
101+
home: StatefulBuilder(
102+
builder: (BuildContext context, StateSetter setState) => Material(
103+
child: GFRating(
104+
itemCount: itemcount,
105+
size: size,
106+
color: color,
107+
filledIcon: filledicon,
108+
controller: ratingController,
109+
showTextForm: showtextForm,
110+
value: rating,
111+
onChanged: (value) {
112+
setState(() {
113+
rating = value;
114+
});
115+
},
116+
))),
117+
),
100118
);
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);
111119
});
112120

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,
121+
testWidgets('Custom GF Rating using textformfield & icons.',
122+
(WidgetTester tester) async {
123+
await tester.pumpWidget(
124+
MaterialApp(
125+
home: StatefulBuilder(
126+
builder: (BuildContext context, StateSetter setState) => Material(
127+
child: GFRating(
128+
itemCount: itemcount,
129+
size: size,
130+
color: color,
131+
filledIcon: filledicon,
132+
controller: customController,
133+
suffixIcon: suffixicon,
134+
showTextForm: showtextForm,
135+
value: rating,
136+
onChanged: (value) {
137+
setState(() {
138+
rating = value;
139+
});
140+
},
141+
))),
142+
),
122143
);
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);
134144
});
135145
}
136146

0 commit comments

Comments
 (0)