Commit 63964f48 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Port ScrollNotification tests (#8057)

These now test ScrollNotification2.
parent 67462b43
......@@ -7,71 +7,69 @@ import 'package:flutter/widgets.dart';
void main() {
testWidgets('Scroll notification basics', (WidgetTester tester) async {
ScrollNotification notification;
ScrollNotification2 notification;
await tester.pumpWidget(new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
notification = value;
await tester.pumpWidget(new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification2 value) {
if (value is ScrollStartNotification || value is ScrollUpdateNotification || value is ScrollEndNotification)
notification = value;
return false;
},
child: new ScrollableViewport(
child: new SingleChildScrollView(
child: const SizedBox(height: 1200.0)
)
));
TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0));
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.started));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNotNull);
expect(notification.dragStartDetails.globalPosition, equals(const Point(100.0, 100.0)));
expect(notification.dragUpdateDetails, isNull);
expect(notification.dragEndDetails, isNull);
expect(notification, const isInstanceOf<ScrollStartNotification>());
expect(notification.depth, equals(1));
ScrollStartNotification start = notification;
expect(start.dragDetails, isNotNull);
expect(start.dragDetails.globalPosition, equals(const Point(100.0, 100.0)));
await gesture.moveBy(const Offset(-10.0, -10.0));
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.updated));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNull);
expect(notification.dragUpdateDetails, isNotNull);
expect(notification.dragUpdateDetails.globalPosition, equals(const Point(90.0, 90.0)));
expect(notification.dragUpdateDetails.delta, equals(const Offset(0.0, -10.0)));
expect(notification.dragEndDetails, isNull);
expect(notification, const isInstanceOf<ScrollUpdateNotification>());
expect(notification.depth, equals(1));
ScrollUpdateNotification update = notification;
expect(update.dragDetails, isNotNull);
expect(update.dragDetails.globalPosition, equals(const Point(90.0, 90.0)));
expect(update.dragDetails.delta, equals(const Offset(0.0, -10.0)));
await gesture.up();
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.ended));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNull);
expect(notification.dragUpdateDetails, isNull);
expect(notification.dragEndDetails, isNotNull);
expect(notification.dragEndDetails.velocity, equals(Velocity.zero));
expect(notification, const isInstanceOf<ScrollEndNotification>());
expect(notification.depth, equals(1));
ScrollEndNotification end = notification;
expect(end.dragDetails, isNotNull);
expect(end.dragDetails.velocity, equals(Velocity.zero));
});
testWidgets('Scroll notification depth', (WidgetTester tester) async {
final List<ScrollNotificationKind> depth0Kinds = <ScrollNotificationKind>[];
final List<ScrollNotificationKind> depth1Kinds = <ScrollNotificationKind>[];
final List<Type> depth0Types = <Type>[];
final List<Type> depth1Types = <Type>[];
final List<int> depth0Values = <int>[];
final List<int> depth1Values = <int>[];
await tester.pumpWidget(new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
depth1Kinds.add(value.kind);
await tester.pumpWidget(new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification2 value) {
depth1Types.add(value.runtimeType);
depth1Values.add(value.depth);
return false;
},
child: new ScrollableViewport(
child: new SingleChildScrollView(
child: new SizedBox(
height: 1200.0,
child: new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
depth0Kinds.add(value.kind);
child: new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification2 value) {
depth0Types.add(value.runtimeType);
depth0Values.add(value.depth);
return false;
},
child: new Container(
padding: const EdgeInsets.all(50.0),
child: new ScrollableViewport(child: const SizedBox(height: 1200.0))
child: new SingleChildScrollView(child: const SizedBox(height: 1200.0))
)
)
)
......@@ -85,15 +83,19 @@ void main() {
await gesture.up();
await tester.pump(const Duration(seconds: 1));
final List<ScrollNotificationKind> kinds = <ScrollNotificationKind>[
ScrollNotificationKind.started,
ScrollNotificationKind.updated,
ScrollNotificationKind.ended
final List<Type> types = <Type>[
ScrollStartNotification,
UserScrollNotification,
ScrollUpdateNotification,
ScrollEndNotification,
UserScrollNotification,
];
expect(depth0Kinds, equals(kinds));
expect(depth1Kinds, equals(kinds));
expect(depth0Types, equals(types));
expect(depth1Types, equals(types));
expect(depth0Values, equals(<int>[0, 0, 0]));
expect(depth1Values, equals(<int>[1, 1, 1]));
// These values might not be what we want in the end.
// See <https://github.com/flutter/flutter/issues/8017>.
expect(depth0Values, equals(<int>[1, 1, 1, 1, 1]));
expect(depth1Values, equals(<int>[2, 2, 2, 2, 2]));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment