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'; ...@@ -7,71 +7,69 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('Scroll notification basics', (WidgetTester tester) async { testWidgets('Scroll notification basics', (WidgetTester tester) async {
ScrollNotification notification; ScrollNotification2 notification;
await tester.pumpWidget(new NotificationListener<ScrollNotification>( await tester.pumpWidget(new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification value) { onNotification: (ScrollNotification2 value) {
notification = value; if (value is ScrollStartNotification || value is ScrollUpdateNotification || value is ScrollEndNotification)
notification = value;
return false; return false;
}, },
child: new ScrollableViewport( child: new SingleChildScrollView(
child: const SizedBox(height: 1200.0) child: const SizedBox(height: 1200.0)
) )
)); ));
TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0)); TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0));
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.started)); expect(notification, const isInstanceOf<ScrollStartNotification>());
expect(notification.depth, equals(0)); expect(notification.depth, equals(1));
expect(notification.dragStartDetails, isNotNull); ScrollStartNotification start = notification;
expect(notification.dragStartDetails.globalPosition, equals(const Point(100.0, 100.0))); expect(start.dragDetails, isNotNull);
expect(notification.dragUpdateDetails, isNull); expect(start.dragDetails.globalPosition, equals(const Point(100.0, 100.0)));
expect(notification.dragEndDetails, isNull);
await gesture.moveBy(const Offset(-10.0, -10.0)); await gesture.moveBy(const Offset(-10.0, -10.0));
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.updated)); expect(notification, const isInstanceOf<ScrollUpdateNotification>());
expect(notification.depth, equals(0)); expect(notification.depth, equals(1));
expect(notification.dragStartDetails, isNull); ScrollUpdateNotification update = notification;
expect(notification.dragUpdateDetails, isNotNull); expect(update.dragDetails, isNotNull);
expect(notification.dragUpdateDetails.globalPosition, equals(const Point(90.0, 90.0))); expect(update.dragDetails.globalPosition, equals(const Point(90.0, 90.0)));
expect(notification.dragUpdateDetails.delta, equals(const Offset(0.0, -10.0))); expect(update.dragDetails.delta, equals(const Offset(0.0, -10.0)));
expect(notification.dragEndDetails, isNull);
await gesture.up(); await gesture.up();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.ended)); expect(notification, const isInstanceOf<ScrollEndNotification>());
expect(notification.depth, equals(0)); expect(notification.depth, equals(1));
expect(notification.dragStartDetails, isNull); ScrollEndNotification end = notification;
expect(notification.dragUpdateDetails, isNull); expect(end.dragDetails, isNotNull);
expect(notification.dragEndDetails, isNotNull); expect(end.dragDetails.velocity, equals(Velocity.zero));
expect(notification.dragEndDetails.velocity, equals(Velocity.zero));
}); });
testWidgets('Scroll notification depth', (WidgetTester tester) async { testWidgets('Scroll notification depth', (WidgetTester tester) async {
final List<ScrollNotificationKind> depth0Kinds = <ScrollNotificationKind>[]; final List<Type> depth0Types = <Type>[];
final List<ScrollNotificationKind> depth1Kinds = <ScrollNotificationKind>[]; final List<Type> depth1Types = <Type>[];
final List<int> depth0Values = <int>[]; final List<int> depth0Values = <int>[];
final List<int> depth1Values = <int>[]; final List<int> depth1Values = <int>[];
await tester.pumpWidget(new NotificationListener<ScrollNotification>( await tester.pumpWidget(new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification value) { onNotification: (ScrollNotification2 value) {
depth1Kinds.add(value.kind); depth1Types.add(value.runtimeType);
depth1Values.add(value.depth); depth1Values.add(value.depth);
return false; return false;
}, },
child: new ScrollableViewport( child: new SingleChildScrollView(
child: new SizedBox( child: new SizedBox(
height: 1200.0, height: 1200.0,
child: new NotificationListener<ScrollNotification>( child: new NotificationListener<ScrollNotification2>(
onNotification: (ScrollNotification value) { onNotification: (ScrollNotification2 value) {
depth0Kinds.add(value.kind); depth0Types.add(value.runtimeType);
depth0Values.add(value.depth); depth0Values.add(value.depth);
return false; return false;
}, },
child: new Container( child: new Container(
padding: const EdgeInsets.all(50.0), 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() { ...@@ -85,15 +83,19 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
final List<ScrollNotificationKind> kinds = <ScrollNotificationKind>[ final List<Type> types = <Type>[
ScrollNotificationKind.started, ScrollStartNotification,
ScrollNotificationKind.updated, UserScrollNotification,
ScrollNotificationKind.ended ScrollUpdateNotification,
ScrollEndNotification,
UserScrollNotification,
]; ];
expect(depth0Kinds, equals(kinds)); expect(depth0Types, equals(types));
expect(depth1Kinds, equals(kinds)); expect(depth1Types, equals(types));
expect(depth0Values, equals(<int>[0, 0, 0])); // These values might not be what we want in the end.
expect(depth1Values, equals(<int>[1, 1, 1])); // 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