Skip to content

Commit c4dbcb4

Browse files
committed
added unit test for property assertions
1 parent 846dc82 commit c4dbcb4

1 file changed

Lines changed: 154 additions & 1 deletion

File tree

test/flutter_switch_test.dart

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,160 @@ void main() {
7373
expect(align.alignment, equals(Alignment.centerLeft));
7474
},
7575
);
76+
77+
testWidgets(
78+
"throws an assertion error when both toggleColor and activeToggleColor property is not null",
79+
(WidgetTester tester) async {
80+
await tester.pumpWidget(
81+
_FlutterSwitchTest(
82+
status: false,
83+
toggleColor: Colors.white,
84+
activeToggleColor: Colors.blue,
85+
),
86+
);
87+
88+
final assertion = tester.takeException();
89+
90+
expect(assertion, isAssertionError);
91+
},
92+
);
93+
94+
testWidgets(
95+
"throws an assertion error when both toggleColor and inactiveToggleColor property is not null",
96+
(WidgetTester tester) async {
97+
await tester.pumpWidget(
98+
_FlutterSwitchTest(
99+
status: false,
100+
toggleColor: Colors.blue,
101+
inactiveToggleColor: Colors.blueGrey,
102+
),
103+
);
104+
105+
final assertion = tester.takeException();
106+
107+
expect(assertion, isAssertionError);
108+
},
109+
);
110+
111+
testWidgets(
112+
"throws an assertion error when both switchBorder and activeSwitchBorder property is not null",
113+
(WidgetTester tester) async {
114+
await tester.pumpWidget(
115+
_FlutterSwitchTest(
116+
status: false,
117+
switchBorder: Border.all(
118+
color: Colors.black,
119+
width: 6.0,
120+
),
121+
activeSwitchBorder: Border.all(
122+
color: Colors.blue,
123+
width: 6.0,
124+
),
125+
),
126+
);
127+
128+
final assertion = tester.takeException();
129+
130+
expect(assertion, isAssertionError);
131+
},
132+
);
133+
134+
testWidgets(
135+
"throws an assertion error when both switchBorder and inactiveSwitchBorder property is not null",
136+
(WidgetTester tester) async {
137+
await tester.pumpWidget(
138+
_FlutterSwitchTest(
139+
status: false,
140+
switchBorder: Border.all(
141+
color: Colors.black,
142+
width: 6.0,
143+
),
144+
inactiveSwitchBorder: Border.all(
145+
color: Colors.blueGrey,
146+
width: 6.0,
147+
),
148+
),
149+
);
150+
151+
final assertion = tester.takeException();
152+
153+
expect(assertion, isAssertionError);
154+
},
155+
);
156+
157+
testWidgets(
158+
"throws an assertion error when both toggleBorder and activeToggleBorder property is not null",
159+
(WidgetTester tester) async {
160+
await tester.pumpWidget(
161+
_FlutterSwitchTest(
162+
status: false,
163+
toggleBorder: Border.all(
164+
color: Colors.black,
165+
width: 6.0,
166+
),
167+
activeToggleBorder: Border.all(
168+
color: Colors.blue,
169+
width: 6.0,
170+
),
171+
),
172+
);
173+
174+
final assertion = tester.takeException();
175+
176+
expect(assertion, isAssertionError);
177+
},
178+
);
179+
180+
testWidgets(
181+
"throws an assertion error when both toggleBorder and inactiveToggleBorder property is not null",
182+
(WidgetTester tester) async {
183+
await tester.pumpWidget(
184+
_FlutterSwitchTest(
185+
status: false,
186+
toggleBorder: Border.all(
187+
color: Colors.black,
188+
width: 6.0,
189+
),
190+
inactiveToggleBorder: Border.all(
191+
color: Colors.blueGrey,
192+
width: 6.0,
193+
),
194+
),
195+
);
196+
197+
final assertion = tester.takeException();
198+
199+
expect(assertion, isAssertionError);
200+
},
201+
);
76202
});
77203
}
78204

79205
/// A testbed class needed to test the [FlutterSwitch] widget.
80206
class _FlutterSwitchTest extends StatefulWidget {
81-
final status;
207+
final bool status;
208+
final Color toggleColor;
209+
final Color activeToggleColor;
210+
final Color inactiveToggleColor;
211+
final Border switchBorder;
212+
final Border activeSwitchBorder;
213+
final Border inactiveSwitchBorder;
214+
final Border toggleBorder;
215+
final Border activeToggleBorder;
216+
final Border inactiveToggleBorder;
82217

83218
_FlutterSwitchTest({
84219
Key key,
85220
this.status,
221+
this.toggleColor,
222+
this.activeToggleColor,
223+
this.inactiveToggleColor,
224+
this.switchBorder,
225+
this.activeSwitchBorder,
226+
this.inactiveSwitchBorder,
227+
this.toggleBorder,
228+
this.activeToggleBorder,
229+
this.inactiveToggleBorder,
86230
}) : super(key: key);
87231

88232
@override
@@ -107,6 +251,15 @@ class __FlutterSwitchTestState extends State<_FlutterSwitchTest> {
107251
home: Scaffold(
108252
body: FlutterSwitch(
109253
value: _status,
254+
toggleColor: widget.toggleColor,
255+
activeToggleColor: widget.activeToggleColor,
256+
inactiveToggleColor: widget.inactiveToggleColor,
257+
switchBorder: widget.switchBorder,
258+
activeSwitchBorder: widget.activeSwitchBorder,
259+
inactiveSwitchBorder: widget.inactiveSwitchBorder,
260+
toggleBorder: widget.toggleBorder,
261+
activeToggleBorder: widget.activeToggleBorder,
262+
inactiveToggleBorder: widget.inactiveToggleBorder,
110263
onToggle: (val) {
111264
setState(() {
112265
_status = val;

0 commit comments

Comments
 (0)