Skip to content

Commit 9f92f79

Browse files
authored
Add tests for ScrollController assertions (flutter#8499)
Ensure that read and write operations fail on ScrollControllers associated with a number of positions other than 1.
1 parent 0b7845a commit 9f92f79

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

packages/flutter/test/widgets/scroll_controller_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,73 @@ void main() {
160160
await tester.pumpWidget(new Container(), const Duration(seconds: 2));
161161
});
162162

163+
testWidgets('Read operations on ScrollControllers with no positions fail', (WidgetTester tester) async {
164+
ScrollController controller = new ScrollController();
165+
expect(() => controller.offset, throwsAssertionError);
166+
expect(() => controller.position, throwsAssertionError);
167+
});
168+
169+
testWidgets('Read operations on ScrollControllers with more than one position fail', (WidgetTester tester) async {
170+
ScrollController controller = new ScrollController();
171+
await tester.pumpWidget(new ListView(
172+
children: <Widget>[
173+
new Container(
174+
constraints: const BoxConstraints(maxHeight: 500.0),
175+
child: new ListView(
176+
controller: controller,
177+
children: kStates.map<Widget>((String state) {
178+
return new Container(height: 200.0, child: new Text(state));
179+
}).toList(),
180+
),
181+
),
182+
new Container(
183+
constraints: const BoxConstraints(maxHeight: 500.0),
184+
child: new ListView(
185+
controller: controller,
186+
children: kStates.map<Widget>((String state) {
187+
return new Container(height: 200.0, child: new Text(state));
188+
}).toList(),
189+
),
190+
),
191+
],
192+
));
193+
194+
expect(() => controller.offset, throwsAssertionError);
195+
expect(() => controller.position, throwsAssertionError);
196+
});
197+
198+
testWidgets('Write operations on ScrollControllers with no positions fail', (WidgetTester tester) async {
199+
ScrollController controller = new ScrollController();
200+
expect(() => controller.animateTo(1.0, duration: const Duration(seconds: 1), curve: Curves.linear), throwsAssertionError);
201+
expect(() => controller.jumpTo(1.0), throwsAssertionError);
202+
});
203+
204+
testWidgets('Write operations on ScrollControllers with more than one position fail', (WidgetTester tester) async {
205+
ScrollController controller = new ScrollController();
206+
await tester.pumpWidget(new ListView(
207+
children: <Widget>[
208+
new Container(
209+
constraints: const BoxConstraints(maxHeight: 500.0),
210+
child: new ListView(
211+
controller: controller,
212+
children: kStates.map<Widget>((String state) {
213+
return new Container(height: 200.0, child: new Text(state));
214+
}).toList(),
215+
),
216+
),
217+
new Container(
218+
constraints: const BoxConstraints(maxHeight: 500.0),
219+
child: new ListView(
220+
controller: controller,
221+
children: kStates.map<Widget>((String state) {
222+
return new Container(height: 200.0, child: new Text(state));
223+
}).toList(),
224+
),
225+
),
226+
],
227+
));
228+
229+
expect(() => controller.jumpTo(1.0), throwsAssertionError);
230+
expect(() => controller.animateTo(1.0, duration: const Duration(seconds: 1), curve: Curves.linear), throwsAssertionError);
231+
});
163232
}

0 commit comments

Comments
 (0)