mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
84 lines
2.1 KiB
Dart
84 lines
2.1 KiB
Dart
import 'package:sky/animation.dart';
|
|
import 'package:sky/widgets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'widget_tester.dart';
|
|
|
|
class FirstComponent extends StatelessComponent {
|
|
FirstComponent(this.navigator);
|
|
|
|
final NavigatorState navigator;
|
|
|
|
Widget build(BuildContext context) {
|
|
return new GestureDetector(
|
|
onTap: () {
|
|
navigator.pushNamed('/second');
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFFFF00)
|
|
),
|
|
child: new Text('X')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
class SecondComponent extends StatefulComponent {
|
|
SecondComponent(this.navigator);
|
|
|
|
final NavigatorState navigator;
|
|
|
|
SecondComponentState createState() => new SecondComponentState();
|
|
}
|
|
|
|
class SecondComponentState extends State<SecondComponent> {
|
|
Widget build(BuildContext context) {
|
|
return new GestureDetector(
|
|
onTap: config.navigator.pop,
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFF00FF)
|
|
),
|
|
child: new Text('Y')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test('Can navigator navigate to and from a stateful component', () {
|
|
WidgetTester tester = new WidgetTester();
|
|
|
|
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
|
|
'/': (navigator, route) => new FirstComponent(navigator),
|
|
'/second': (navigator, route) => new SecondComponent(navigator),
|
|
};
|
|
|
|
tester.pumpFrame(new Navigator(routes: routes));
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNull);
|
|
|
|
tester.tap(tester.findText('X'));
|
|
scheduler.beginFrame(10.0);
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNotNull);
|
|
|
|
scheduler.beginFrame(20.0);
|
|
scheduler.beginFrame(30.0);
|
|
scheduler.beginFrame(1000.0);
|
|
|
|
tester.tap(tester.findText('Y'));
|
|
scheduler.beginFrame(1010.0);
|
|
scheduler.beginFrame(1020.0);
|
|
scheduler.beginFrame(1030.0);
|
|
scheduler.beginFrame(2000.0);
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNull);
|
|
|
|
});
|
|
}
|