From 0b6b39b39e23a1f8d1af58e7dbbd50daadd18278 Mon Sep 17 00:00:00 2001 From: xster Date: Wed, 6 Mar 2019 15:48:59 -0800 Subject: [PATCH] Move material iOS back swipe test to material (#28855) --- packages/flutter/test/cupertino/README.md | 7 ++ .../flutter/test/cupertino/route_test.dart | 23 +++--- packages/flutter/test/material/page_test.dart | 76 +++++++++++++++++++ 3 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 packages/flutter/test/cupertino/README.md diff --git a/packages/flutter/test/cupertino/README.md b/packages/flutter/test/cupertino/README.md new file mode 100644 index 0000000000..9fa54b1a40 --- /dev/null +++ b/packages/flutter/test/cupertino/README.md @@ -0,0 +1,7 @@ +# Tests for the Cupertino package + +Avoid importing the Material 'package:flutter/material.dart' in these tests as +we're trying to test the Cupertino package in standalone scenarios. + +Some tests may be replicated in the Material tests when Material reuses +Cupertino components on iOS such as page transitions and text editing. diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index 16396e2d3a..efa7def3e1 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_test.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -256,20 +255,20 @@ void main() { }); testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/28728 final GlobalKey scaffoldKey = GlobalKey(); await tester.pumpWidget( - MaterialApp( - theme: ThemeData(platform: TargetPlatform.iOS), - home: Scaffold( + CupertinoApp( + home: CupertinoPageScaffold( key: scaffoldKey, - body: Center( - child: RaisedButton( + child: Center( + child: CupertinoButton( onPressed: () { - Navigator.push(scaffoldKey.currentContext, MaterialPageRoute( + Navigator.push(scaffoldKey.currentContext, CupertinoPageRoute( builder: (BuildContext context) { - return const Scaffold( - body: Center(child: Text('route')), + return const CupertinoPageScaffold( + child: Center(child: Text('route')), ); }, )); @@ -294,17 +293,17 @@ void main() { await gesture.up(); await tester.pump(); expect( // The 'route' route has been dragged to the right, halfway across the screen - tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(Scaffold))), + tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(CupertinoPageScaffold))), const Offset(400, 0), ); expect( // The 'push' route is sliding in from the left. - tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))).dx, + tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(CupertinoPageScaffold))).dx, lessThan(0), ); await tester.pumpAndSettle(); expect(find.text('push'), findsOneWidget); expect( - tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))), + tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(CupertinoPageScaffold))), Offset.zero, ); expect(find.text('route'), findsNothing); diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 23b06549b9..fd0ff4025d 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -540,4 +540,80 @@ void main() { expect(find.text('Page 1'), isOnstage); expect(find.text('Page 2'), findsNothing); }); + + testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/28728 + final GlobalKey scaffoldKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(platform: TargetPlatform.iOS), + home: Scaffold( + key: scaffoldKey, + body: Center( + child: RaisedButton( + onPressed: () { + Navigator.push(scaffoldKey.currentContext, MaterialPageRoute( + builder: (BuildContext context) { + return const Scaffold( + body: Center(child: Text('route')), + ); + }, + )); + }, + child: const Text('push'), + ), + ), + ), + ), + ); + + // Check the basic iOS back-swipe dismiss transition. Dragging the pushed + // route halfway across the screen will trigger the iOS dismiss animation + + await tester.tap(find.text('push')); + await tester.pumpAndSettle(); + expect(find.text('route'), findsOneWidget); + expect(find.text('push'), findsNothing); + + TestGesture gesture = await tester.startGesture(const Offset(5, 300)); + await gesture.moveBy(const Offset(400, 0)); + await gesture.up(); + await tester.pump(); + expect( // The 'route' route has been dragged to the right, halfway across the screen + tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(Scaffold))), + const Offset(400, 0), + ); + expect( // The 'push' route is sliding in from the left. + tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))).dx, + lessThan(0), + ); + await tester.pumpAndSettle(); + expect(find.text('push'), findsOneWidget); + expect( + tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))), + Offset.zero, + ); + expect(find.text('route'), findsNothing); + + + // Run the dismiss animation 75%, which exposes the route "push" button, + // and then press the button. MaterialPageTransition duration is 300ms, + // 275 = 300 * 0.75. + + await tester.tap(find.text('push')); + await tester.pumpAndSettle(); + expect(find.text('route'), findsOneWidget); + expect(find.text('push'), findsNothing); + + gesture = await tester.startGesture(const Offset(5, 300)); + await gesture.moveBy(const Offset(400, 0)); // drag halfway + await gesture.up(); + await tester.pump(const Duration(milliseconds: 275)); // partially dismiss "route" + expect(find.text('route'), findsOneWidget); + await tester.tap(find.text('push')); + await tester.pumpAndSettle(); + expect(find.text('route'), findsOneWidget); + expect(find.text('push'), findsNothing); + }); }