Commit 99a9bbbe authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Add a test for 5630 (#5768)

This issue got fixed by a recent check-in, but I had a test specifically
for this incarnation so we should probably keep it just in case.

Closes https://github.com/flutter/flutter/issues/5630
parent 0fe09e52
......@@ -66,8 +66,7 @@ void main() {
})
));
frame += 1;
SizeChangerState state = tester.state(find.byType(SizeChanger));
state.trigger();
tester.state/*<SizeChangerState>*/(find.byType(SizeChanger)).trigger();
await tester.pump();
});
}
......@@ -57,8 +57,7 @@ Future<Null> performTest(WidgetTester tester, bool maintainState) async {
expect(find.text('10'), findsNothing);
expect(find.text('100'), findsNothing);
ScrollableState targetState = tester.state(find.byType(Scrollable));
targetState.scrollTo(1000.0);
tester.state/*<ScrollableState>*/(find.byType(Scrollable)).scrollTo(1000.0);
await tester.pump(new Duration(seconds: 1));
// we're 600 pixels high, each item is 100 pixels high, scroll position is
......
......@@ -20,8 +20,7 @@ void main() {
await tester.fling(find.byType(Scrollable), new Offset(0.0, -200.0), 1000.0);
await tester.pump();
FlipWidgetState flipWidget = tester.state(find.byType(FlipWidget));
flipWidget.flip();
tester.state/*<FlipWidgetState>*/(find.byType(FlipWidget)).flip();
await tester.pump(new Duration(hours: 5));
});
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher;
import 'package:flutter/widgets.dart';
class Foo extends StatefulWidget {
@override
FooState createState() => new FooState();
}
class FooState extends State<Foo> {
final GlobalKey blockKey = new GlobalKey();
GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
@override
Widget build(BuildContext context) {
return new LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return new ScrollConfiguration(
delegate: new FooScrollConfiguration(),
child: new Block(
scrollableKey: scrollableKey,
children: <Widget>[
new GestureDetector(
onTap: () {
setState(() {});
scrollableKey.currentState.scrollBy(200.0, duration: const Duration(milliseconds: 500));
},
child: new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
)
),
new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
),
new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
),
new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
),
new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
),
new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0)),
child: new SizedBox(
height: 200.0,
),
),
],
)
);
}
);
}
}
class FooScrollConfiguration extends ScrollConfigurationDelegate {
@override
TargetPlatform get platform => defaultTargetPlatform;
@override
ExtentScrollBehavior createScrollBehavior() =>
new OverscrollWhenScrollableBehavior(platform: platform);
@override
bool updateShouldNotify(FooScrollConfiguration old) => true;
}
void main() {
testWidgets('https://github.com/flutter/flutter/issues/5630', (WidgetTester tester) async {
await tester.pumpWidget(new Foo());
expect(tester.state/*<ScrollableState>*/(find.byType(Scrollable)).scrollOffset, 0.0);
await tester.tap(find.byType(GestureDetector).first);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(tester.state/*<ScrollableState>*/(find.byType(Scrollable)).scrollOffset, 200.0);
});
}
......@@ -54,6 +54,5 @@ class FlipWidgetState extends State<FlipWidget> {
}
void flipStatefulWidget(WidgetTester tester) {
FlipWidgetState state = tester.state(find.byType(FlipWidget));
state.flip();
tester.state/*<FlipWidgetState>*/(find.byType(FlipWidget)).flip();
}
......@@ -205,6 +205,14 @@ abstract class Finder {
return false;
}
/// Returns a variant of this finder that only matches the first element
/// matched by this finder.
Finder get first => new _FirstFinder(this);
/// Returns a variant of this finder that only matches the last element
/// matched by this finder.
Finder get last => new _LastFinder(this);
@override
String toString() {
final String additional = skipOffstage ? ' (ignoring offstage widgets)' : '';
......@@ -220,6 +228,34 @@ abstract class Finder {
}
}
class _FirstFinder extends Finder {
_FirstFinder(this.parent);
final Finder parent;
@override
String get description => '${parent.description} (ignoring all but first)';
@override
Iterable<Element> apply(Iterable<Element> candidates) sync* {
yield parent.apply(candidates).first;
}
}
class _LastFinder extends Finder {
_LastFinder(this.parent);
final Finder parent;
@override
String get description => '${parent.description} (ignoring all but last)';
@override
Iterable<Element> apply(Iterable<Element> candidates) sync* {
yield parent.apply(candidates).last;
}
}
/// Searches a widget tree and returns nodes that match a particular
/// pattern.
abstract class MatchFinder extends Finder {
......
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