Commit 8cde68d7 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Migrate some tests from Block to ListView (#8055)

parent 63964f48
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
home: new Scaffold( home: new Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: new Drawer( drawer: new Drawer(
child: new Block( child: new ListView(
children: <Widget>[ children: <Widget>[
new Text('drawer'), new Text('drawer'),
new Container( new Container(
...@@ -115,7 +115,7 @@ void main() { ...@@ -115,7 +115,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
expect(textBox.localToGlobal(Point.origin).x, equals(textLeft)); expect(textBox.localToGlobal(Point.origin).x, equals(textLeft));
await gesture.moveBy(const Offset(0.0, -50.0)); await gesture.moveBy(const Offset(0.0, 50.0));
// drawer should be returning to visible // drawer should be returning to visible
await tester.pump(); await tester.pump();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
......
...@@ -62,19 +62,19 @@ void main() { ...@@ -62,19 +62,19 @@ void main() {
await gesture.up(); await gesture.up();
}); });
testWidgets('Scroll anchor', (WidgetTester tester) async { testWidgets('ListView reverse', (WidgetTester tester) async {
int first = 0; int first = 0;
int second = 0; int second = 0;
Widget buildBlock(ViewportAnchor scrollAnchor) { Widget buildBlock({ bool reverse: false }) {
return new Block( return new ListView(
key: new UniqueKey(), key: new UniqueKey(),
scrollAnchor: scrollAnchor, reverse: reverse,
children: <Widget>[ children: <Widget>[
new GestureDetector( new GestureDetector(
onTap: () { ++first; }, onTap: () { ++first; },
child: new Container( child: new Container(
height: 2000.0, // more than 600, the height of the test area height: 350.0, // more than half the height of the test area
decoration: const BoxDecoration( decoration: const BoxDecoration(
backgroundColor: const Color(0xFF00FF00) backgroundColor: const Color(0xFF00FF00)
) )
...@@ -83,7 +83,7 @@ void main() { ...@@ -83,7 +83,7 @@ void main() {
new GestureDetector( new GestureDetector(
onTap: () { ++second; }, onTap: () { ++second; },
child: new Container( child: new Container(
height: 2000.0, // more than 600, the height of the test area height: 350.0, // more than half the height of the test area
decoration: const BoxDecoration( decoration: const BoxDecoration(
backgroundColor: const Color(0xFF0000FF) backgroundColor: const Color(0xFF0000FF)
) )
...@@ -93,32 +93,31 @@ void main() { ...@@ -93,32 +93,31 @@ void main() {
); );
} }
await tester.pumpWidget(buildBlock(ViewportAnchor.end)); await tester.pumpWidget(buildBlock(reverse: true));
Point target = const Point(200.0, 200.0); Point target = const Point(200.0, 200.0);
await tester.tapAt(target); await tester.tapAt(target);
expect(first, equals(0)); expect(first, equals(0));
expect(second, equals(1)); expect(second, equals(1));
await tester.pumpWidget(buildBlock(ViewportAnchor.start)); await tester.pumpWidget(buildBlock(reverse: false));
await tester.tapAt(target); await tester.tapAt(target);
expect(first, equals(1)); expect(first, equals(1));
expect(second, equals(1)); expect(second, equals(1));
}); });
testWidgets('Block scrollableKey', (WidgetTester tester) async { testWidgets('ListView controller', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/4046 ScrollController controller = new ScrollController();
// The Block's scrollableKey needs to become its Scrollable descendant's key.
final GlobalKey<ScrollableState<Scrollable>> key = new GlobalKey<ScrollableState<Scrollable>>();
Widget buildBlock() { Widget buildBlock() {
return new Block( return new ListView(
scrollableKey: key, controller: controller,
children: <Widget>[new Text("A"), new Text("B"), new Text("C")] children: <Widget>[new Text("A"), new Text("B"), new Text("C")]
); );
} }
await tester.pumpWidget(buildBlock()); await tester.pumpWidget(buildBlock());
expect(key.currentState.scrollOffset, 0.0); expect(controller.offset, equals(0.0));
}); });
testWidgets('SliverBlockChildListDelegate.estimateMaxScrollOffset hits end', (WidgetTester tester) async { testWidgets('SliverBlockChildListDelegate.estimateMaxScrollOffset hits end', (WidgetTester tester) async {
......
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