Commit 9e07e9f2 authored by yangwu.jia's avatar yangwu.jia

Add test

parent 5a70c578
......@@ -166,7 +166,7 @@ void main() {
// ),
// SizedBox(
// height: 300.0,
// child: BoostContainer(
// child: Navigator(
// onGenerateRoute: (RouteSettings settings) {
// if (settings.isInitialRoute) {
// return MaterialPageRoute<void>(
......@@ -174,13 +174,13 @@ void main() {
// return RaisedButton(
// child: const Text('Next'),
// onPressed: () {
// Navigator.of(context).push(
// BoostContainer.of(context).push(
// MaterialPageRoute<void>(
// builder: (BuildContext context) {
// return RaisedButton(
// child: const Text('Inner page'),
// onPressed: () {
// Navigator.of(context, rootNavigator: true)
// BoostContainer.of(context)
// .push(
// MaterialPageRoute<void>(
// builder: (BuildContext context) {
......@@ -204,21 +204,21 @@ void main() {
// ),
// ),
// ));
//
// await tester.tap(find.text('Next'));
// await tester.pump();
// await tester.pump(const Duration(milliseconds: 300));
////
//// await tester.tap(find.text('Next'));
//// await tester.pump();
//// await tester.pump(const Duration(milliseconds: 300));
//
// // Both elements are on screen.
// expect(tester.getTopLeft(find.text('Root page')).dy, 0.0);
// expect(tester.getTopLeft(find.text('Inner page')).dy, greaterThan(300.0));
//
// await tester.tap(find.text('Inner page'));
// await tester.pump();
// await tester.pump(const Duration(milliseconds: 300));
//
// // Dialog is pushed to the whole page and is at the top of the screen, not
// // inside the inner page.
// expect(tester.getTopLeft(find.text('Dialog')).dy, 0.0);
// expect(find.text('Next'), findsOneWidget);
//// expect(tester.getTopLeft(find.text('Inner page')).dy, greaterThan(300.0));
////
//// await tester.tap(find.text('Inner page'));
//// await tester.pump();
//// await tester.pump(const Duration(milliseconds: 300));
////
//// // Dialog is pushed to the whole page and is at the top of the screen, not
//// // inside the inner page.
//// expect(tester.getTopLeft(find.text('Dialog')).dy, 0.0);
// });
}
import 'package:flutter_boost/container/boost_page_route.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('boost_page_route', () {
testWidgets('test iOS edge swipe then drop back at starting point works',
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
onGenerateRoute: (RouteSettings settings) {
return BoostPageRoute<void>(
settings: settings,
builder: (BuildContext context) {
final String pageNumber = settings.name == '/' ? '1' : '2';
return Center(child: Text('Page $pageNumber'));
},
);
},
),
);
});
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage);
}
\ No newline at end of file
final TestGesture gesture = await tester.startGesture(const Offset(5, 200));
await gesture.moveBy(const Offset(300, 0));
await tester.pump();
// Bring it exactly back such that there's nothing to animate when releasing.
await gesture.moveBy(const Offset(-300, 0));
await gesture.up();
await tester.pump();
expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage);
});
}
......@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('container_coordinator', () {
......
......@@ -2,10 +2,115 @@ import 'package:flutter_boost/container/container_manager.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_boost/flutter_boost.dart';
final GlobalKey scaffoldKey = GlobalKey();
class FirstRouteWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('First'),
onPressed: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map value) {
print(
"call me when page is finished. did recieve second route result $value");
});
},
),
],
),
),
);
}
}
class SecondRouteWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Route'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('Second'),
onPressed: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map value) {
print(
"call me when page is finished. did recieve second route result $value");
});
},
),
],
),
),
);
}
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
FlutterBoost.singleton.registerPageBuilders({
'first': (pageName, params, _) => FirstRouteWidget(),
'second': (pageName, params, _) => SecondRouteWidget(),
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Boost example',
key: scaffoldKey,
builder: (BuildContext context, Widget child) {
assert(child is Navigator, 'child must be Navigator, what is wrong?');
final BoostContainerManager manager = BoostContainerManager(
initNavigator: child,
);
return manager;
},
home: Container());
}
void _onRoutePushed(
String pageName, String uniqueId, Map params, Route route, Future _) {}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
testWidgets('test iOS edge swipe then drop back at starting point works',
(WidgetTester tester) async {
await tester.pumpWidget(MyApp());
group('container_manager', () {
// Navigator.pushNamed(scaffoldKey.currentContext, "first");
expect(find.text('First'), findsNothing);
});
}
\ No newline at end of file
}
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