Unverified Commit d8f36071 authored by xster's avatar xster Committed by GitHub

Add a way to generically go back on both Material and Cupertino scaffold pages (#15602)

* Add a way to generically go back on both Material and Cupertino scaffold pages

* review

* lint

* review

* Fix text assert text
parent 4a2217b3
This diff is collapsed.
......@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -15,6 +16,7 @@ import 'all_elements.dart';
import 'binding.dart';
import 'controller.dart';
import 'finders.dart';
import 'matchers.dart';
import 'test_async_utils.dart';
import 'test_text_input.dart';
......@@ -531,6 +533,21 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
await idle();
});
}
/// Makes an effort to dismiss the current page with a Material [Scaffold] or
/// a [CupertinoPageScaffold].
///
/// Will throw an error if there is no back button in the page.
Future<void> pageBack() async {
Finder backButton = find.byTooltip('Back');
if (backButton.evaluate().isEmpty) {
backButton = find.widgetWithIcon(CupertinoButton, CupertinoIcons.back);
}
expect(backButton, findsOneWidget, reason: 'One back button expected on screen');
await tap(backButton);
}
}
typedef void _TickerDisposeCallback(_TestTicker ticker);
......
......@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
const List<Widget> fooBarTexts = const <Text>[
......@@ -195,7 +196,9 @@ void main() {
expect(failure, isNotNull);
expect(
failure.message,
contains('Actual: ?:<zero widgets with text "bar" that has ancestor(s) with type Column with text "foo"')
contains(
'Actual: ?:<zero widgets with text "bar" that has ancestor(s) with type "Column" which is an ancestor of text "foo"',
),
);
});
});
......@@ -255,7 +258,9 @@ void main() {
expect(failure, isNotNull);
expect(
failure.message,
contains('Actual: ?:<zero widgets with type Column with text "foo" which is an ancestor of text "bar"'),
contains(
'Actual: ?:<zero widgets with type "Column" which is an ancestor of text "foo" which is an ancestor of text "bar"',
),
);
});
......@@ -289,6 +294,94 @@ void main() {
});
});
group('pageBack', (){
testWidgets('fails when there are no back buttons', (WidgetTester tester) async {
await tester.pumpWidget(new Container());
expect(
expectAsync0(tester.pageBack),
throwsA(const isInstanceOf<TestFailure>()),
);
});
testWidgets('successfully taps material back buttons', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Center(
child: new Builder(
builder: (BuildContext context) {
return new RaisedButton(
child: const Text('Next'),
onPressed: () {
Navigator.push<void>(context, new MaterialPageRoute<void>(
builder: (BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: const Text('Page 2'),
),
);
},
));
},
);
} ,
),
),
),
);
await tester.tap(find.text('Next'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pageBack();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Next'), findsOneWidget);
expect(find.text('Page 2'), findsNothing);
});
testWidgets('successfully taps cupertino back buttons', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Center(
child: new Builder(
builder: (BuildContext context) {
return new CupertinoButton(
child: const Text('Next'),
onPressed: () {
Navigator.push<void>(context, new CupertinoPageRoute<void>(
builder: (BuildContext context) {
return new CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: const Text('Page 2'),
),
child: new Container(),
);
},
));
},
);
} ,
),
),
),
);
await tester.tap(find.text('Next'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pageBack();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Next'), findsOneWidget);
expect(find.text('Page 2'), findsNothing);
});
});
testWidgets('hasRunningAnimations control test', (WidgetTester tester) async {
final AnimationController controller = new AnimationController(
duration: const Duration(seconds: 1),
......
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