Skip to content

Commit 0b6b39b

Browse files
authored
Move material iOS back swipe test to material (flutter#28855)
1 parent 11678da commit 0b6b39b

File tree

3 files changed

+94
-12
lines changed

3 files changed

+94
-12
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tests for the Cupertino package
2+
3+
Avoid importing the Material 'package:flutter/material.dart' in these tests as
4+
we're trying to test the Cupertino package in standalone scenarios.
5+
6+
Some tests may be replicated in the Material tests when Material reuses
7+
Cupertino components on iOS such as page transitions and text editing.

packages/flutter/test/cupertino/route_test.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/cupertino.dart';
6-
import 'package:flutter/material.dart';
76
import 'package:flutter/rendering.dart';
87
import 'package:flutter_test/flutter_test.dart';
98

@@ -256,20 +255,20 @@ void main() {
256255
});
257256

258257
testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async {
258+
// Regression test for https://github.com/flutter/flutter/issues/28728
259259
final GlobalKey scaffoldKey = GlobalKey();
260260

261261
await tester.pumpWidget(
262-
MaterialApp(
263-
theme: ThemeData(platform: TargetPlatform.iOS),
264-
home: Scaffold(
262+
CupertinoApp(
263+
home: CupertinoPageScaffold(
265264
key: scaffoldKey,
266-
body: Center(
267-
child: RaisedButton(
265+
child: Center(
266+
child: CupertinoButton(
268267
onPressed: () {
269-
Navigator.push<void>(scaffoldKey.currentContext, MaterialPageRoute<void>(
268+
Navigator.push<void>(scaffoldKey.currentContext, CupertinoPageRoute<void>(
270269
builder: (BuildContext context) {
271-
return const Scaffold(
272-
body: Center(child: Text('route')),
270+
return const CupertinoPageScaffold(
271+
child: Center(child: Text('route')),
273272
);
274273
},
275274
));
@@ -294,17 +293,17 @@ void main() {
294293
await gesture.up();
295294
await tester.pump();
296295
expect( // The 'route' route has been dragged to the right, halfway across the screen
297-
tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(Scaffold))),
296+
tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(CupertinoPageScaffold))),
298297
const Offset(400, 0),
299298
);
300299
expect( // The 'push' route is sliding in from the left.
301-
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))).dx,
300+
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(CupertinoPageScaffold))).dx,
302301
lessThan(0),
303302
);
304303
await tester.pumpAndSettle();
305304
expect(find.text('push'), findsOneWidget);
306305
expect(
307-
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))),
306+
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(CupertinoPageScaffold))),
308307
Offset.zero,
309308
);
310309
expect(find.text('route'), findsNothing);

packages/flutter/test/material/page_test.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,80 @@ void main() {
540540
expect(find.text('Page 1'), isOnstage);
541541
expect(find.text('Page 2'), findsNothing);
542542
});
543+
544+
testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async {
545+
// Regression test for https://github.com/flutter/flutter/issues/28728
546+
final GlobalKey scaffoldKey = GlobalKey();
547+
548+
await tester.pumpWidget(
549+
MaterialApp(
550+
theme: ThemeData(platform: TargetPlatform.iOS),
551+
home: Scaffold(
552+
key: scaffoldKey,
553+
body: Center(
554+
child: RaisedButton(
555+
onPressed: () {
556+
Navigator.push<void>(scaffoldKey.currentContext, MaterialPageRoute<void>(
557+
builder: (BuildContext context) {
558+
return const Scaffold(
559+
body: Center(child: Text('route')),
560+
);
561+
},
562+
));
563+
},
564+
child: const Text('push'),
565+
),
566+
),
567+
),
568+
),
569+
);
570+
571+
// Check the basic iOS back-swipe dismiss transition. Dragging the pushed
572+
// route halfway across the screen will trigger the iOS dismiss animation
573+
574+
await tester.tap(find.text('push'));
575+
await tester.pumpAndSettle();
576+
expect(find.text('route'), findsOneWidget);
577+
expect(find.text('push'), findsNothing);
578+
579+
TestGesture gesture = await tester.startGesture(const Offset(5, 300));
580+
await gesture.moveBy(const Offset(400, 0));
581+
await gesture.up();
582+
await tester.pump();
583+
expect( // The 'route' route has been dragged to the right, halfway across the screen
584+
tester.getTopLeft(find.ancestor(of: find.text('route'), matching: find.byType(Scaffold))),
585+
const Offset(400, 0),
586+
);
587+
expect( // The 'push' route is sliding in from the left.
588+
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))).dx,
589+
lessThan(0),
590+
);
591+
await tester.pumpAndSettle();
592+
expect(find.text('push'), findsOneWidget);
593+
expect(
594+
tester.getTopLeft(find.ancestor(of: find.text('push'), matching: find.byType(Scaffold))),
595+
Offset.zero,
596+
);
597+
expect(find.text('route'), findsNothing);
598+
599+
600+
// Run the dismiss animation 75%, which exposes the route "push" button,
601+
// and then press the button. MaterialPageTransition duration is 300ms,
602+
// 275 = 300 * 0.75.
603+
604+
await tester.tap(find.text('push'));
605+
await tester.pumpAndSettle();
606+
expect(find.text('route'), findsOneWidget);
607+
expect(find.text('push'), findsNothing);
608+
609+
gesture = await tester.startGesture(const Offset(5, 300));
610+
await gesture.moveBy(const Offset(400, 0)); // drag halfway
611+
await gesture.up();
612+
await tester.pump(const Duration(milliseconds: 275)); // partially dismiss "route"
613+
expect(find.text('route'), findsOneWidget);
614+
await tester.tap(find.text('push'));
615+
await tester.pumpAndSettle();
616+
expect(find.text('route'), findsOneWidget);
617+
expect(find.text('push'), findsNothing);
618+
});
543619
}

0 commit comments

Comments
 (0)