Commit fbd5460b authored by Adam Barth's avatar Adam Barth

Integrate WidgetTester with FakeAsync

Fixes #1084
parent 67feb40c
...@@ -5,9 +5,8 @@ import 'widget_tester.dart'; ...@@ -5,9 +5,8 @@ import 'widget_tester.dart';
void main() { void main() {
test('Align smoke test', () { test('Align smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Align( new Align(
child: new Container(), child: new Container(),
horizontal: 0.75, horizontal: 0.75,
...@@ -15,13 +14,13 @@ void main() { ...@@ -15,13 +14,13 @@ void main() {
) )
); );
tester.pumpFrame( tester.pumpWidget(
new Align( new Align(
child: new Container(), child: new Container(),
horizontal: 0.5, horizontal: 0.5,
vertical: 0.5 vertical: 0.5
) )
); );
});
}); });
} }
...@@ -8,9 +8,8 @@ final Key blockKey = new Key('test'); ...@@ -8,9 +8,8 @@ final Key blockKey = new Key('test');
void main() { void main() {
test('Cannot scroll a non-overflowing block', () { test('Cannot scroll a non-overflowing block', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Block([ new Block([
new Container( new Container(
height: 200.0, // less than 600, the height of the test area height: 200.0, // less than 600, the height of the test area
...@@ -19,7 +18,7 @@ void main() { ...@@ -19,7 +18,7 @@ void main() {
], ],
key: blockKey) key: blockKey)
); );
tester.pumpFrameWithoutChange(); // for SizeObservers tester.pump(); // for SizeObservers
Point middleOfContainer = tester.getCenter(tester.findText('Hello')); Point middleOfContainer = tester.getCenter(tester.findText('Hello'));
Point target = tester.getCenter(tester.findElementByKey(blockKey)); Point target = tester.getCenter(tester.findElementByKey(blockKey));
...@@ -27,17 +26,17 @@ void main() { ...@@ -27,17 +26,17 @@ void main() {
tester.dispatchEvent(pointer.down(target), target); tester.dispatchEvent(pointer.down(target), target);
tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target);
tester.pumpFrameWithoutChange(1.0); tester.pump(const Duration(milliseconds: 1));
expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isTrue); expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isTrue);
tester.dispatchEvent(pointer.up(), target); tester.dispatchEvent(pointer.up(), target);
}); });
});
test('Can scroll an overflowing block', () { test('Can scroll an overflowing block', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Block([ new Block([
new Container( new Container(
height: 2000.0, // more than 600, the height of the test area height: 2000.0, // more than 600, the height of the test area
...@@ -46,7 +45,7 @@ void main() { ...@@ -46,7 +45,7 @@ void main() {
], ],
key: blockKey) key: blockKey)
); );
tester.pumpFrameWithoutChange(); // for SizeObservers tester.pump(); // for SizeObservers
Point middleOfContainer = tester.getCenter(tester.findText('Hello')); Point middleOfContainer = tester.getCenter(tester.findText('Hello'));
Point target = tester.getCenter(tester.findElementByKey(blockKey)); Point target = tester.getCenter(tester.findElementByKey(blockKey));
...@@ -54,10 +53,11 @@ void main() { ...@@ -54,10 +53,11 @@ void main() {
tester.dispatchEvent(pointer.down(target), target); tester.dispatchEvent(pointer.down(target), target);
tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target);
tester.pumpFrameWithoutChange(1.0); tester.pump(const Duration(milliseconds: 1));
expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isFalse); expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isFalse);
tester.dispatchEvent(pointer.up(), target); tester.dispatchEvent(pointer.up(), target);
}); });
});
} }
...@@ -6,9 +6,8 @@ import 'widget_tester.dart'; ...@@ -6,9 +6,8 @@ import 'widget_tester.dart';
void main() { void main() {
test('Circles can have uniform borders', () { test('Circles can have uniform borders', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Container( new Container(
padding: new EdgeDims.all(50.0), padding: new EdgeDims.all(50.0),
decoration: new BoxDecoration( decoration: new BoxDecoration(
...@@ -18,6 +17,6 @@ void main() { ...@@ -18,6 +17,6 @@ void main() {
) )
) )
); );
});
}); });
} }
...@@ -80,47 +80,47 @@ void main() { ...@@ -80,47 +80,47 @@ void main() {
}); });
test('Legal times for setState', () { test('Legal times for setState', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
GlobalKey flipKey = new GlobalKey(); GlobalKey flipKey = new GlobalKey();
expect(ProbeWidgetState.buildCount, equals(0)); expect(ProbeWidgetState.buildCount, equals(0));
tester.pumpFrame(new ProbeWidget()); tester.pumpWidget(new ProbeWidget());
expect(ProbeWidgetState.buildCount, equals(1)); expect(ProbeWidgetState.buildCount, equals(1));
tester.pumpFrame(new ProbeWidget()); tester.pumpWidget(new ProbeWidget());
expect(ProbeWidgetState.buildCount, equals(2)); expect(ProbeWidgetState.buildCount, equals(2));
tester.pumpFrame(new FlipComponent( tester.pumpWidget(new FlipComponent(
key: flipKey, key: flipKey,
left: new Container(), left: new Container(),
right: new ProbeWidget() right: new ProbeWidget()
)); ));
expect(ProbeWidgetState.buildCount, equals(2)); expect(ProbeWidgetState.buildCount, equals(2));
(flipKey.currentState as FlipComponentState).flip(); (flipKey.currentState as FlipComponentState).flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(ProbeWidgetState.buildCount, equals(3)); expect(ProbeWidgetState.buildCount, equals(3));
(flipKey.currentState as FlipComponentState).flip(); (flipKey.currentState as FlipComponentState).flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(ProbeWidgetState.buildCount, equals(3)); expect(ProbeWidgetState.buildCount, equals(3));
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
expect(ProbeWidgetState.buildCount, equals(3)); expect(ProbeWidgetState.buildCount, equals(3));
}); });
});
test('Setting parent state during build is forbidden', () { test('Setting parent state during build is forbidden', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
expect(cachedException, isNull); expect(cachedException, isNull);
tester.pumpFrame(new BadWidgetParent()); tester.pumpWidget(new BadWidgetParent());
expect(cachedException, isNotNull); expect(cachedException, isNotNull);
cachedException = null; cachedException = null;
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
expect(cachedException, isNull); expect(cachedException, isNull);
}); });
});
test('Setting state during dispose is forbidden', () { test('Setting state during dispose is forbidden', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(new BadDisposeWidget());
tester.pumpFrame(new BadDisposeWidget());
expect(() { expect(() {
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
}, throws); }, throws);
}); });
});
} }
...@@ -5,9 +5,8 @@ import 'widget_tester.dart'; ...@@ -5,9 +5,8 @@ import 'widget_tester.dart';
void main() { void main() {
test('Can be placed in an infinte box', () { test('Can be placed in an infinte box', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(new Block([new Center()]));
tester.pumpFrame(new Block([new Center()])); });
}); });
} }
...@@ -6,12 +6,11 @@ import 'widget_tester.dart'; ...@@ -6,12 +6,11 @@ import 'widget_tester.dart';
void main() { void main() {
test('Comparing coordinates', () { test('Comparing coordinates', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
Key keyA = new GlobalKey(); Key keyA = new GlobalKey();
Key keyB = new GlobalKey(); Key keyB = new GlobalKey();
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
top: 100.0, top: 100.0,
...@@ -43,4 +42,5 @@ void main() { ...@@ -43,4 +42,5 @@ void main() {
expect((tester.findElementByKey(keyB).renderObject as RenderBox).globalToLocal(const Point(110.0, 205.0)), expect((tester.findElementByKey(keyB).renderObject as RenderBox).globalToLocal(const Point(110.0, 205.0)),
equals(const Point(10.0, 5.0))); equals(const Point(10.0, 5.0)));
}); });
});
} }
...@@ -5,8 +5,7 @@ import 'widget_tester.dart'; ...@@ -5,8 +5,7 @@ import 'widget_tester.dart';
void main() { void main() {
test('Can select a day', () { test('Can select a day', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
DateTime currentValue; DateTime currentValue;
Widget widget = new Block([ Widget widget = new Block([
...@@ -20,15 +19,16 @@ void main() { ...@@ -20,15 +19,16 @@ void main() {
) )
]); ]);
tester.pumpFrame(widget); tester.pumpWidget(widget);
expect(currentValue, isNull); expect(currentValue, isNull);
tester.tap(tester.findText('2015')); tester.tap(tester.findText('2015'));
tester.pumpFrame(widget); tester.pumpWidget(widget);
tester.tap(tester.findText('2014')); tester.tap(tester.findText('2014'));
tester.pumpFrame(widget); tester.pumpWidget(widget);
expect(currentValue, equals(new DateTime(2014, 6, 9))); expect(currentValue, equals(new DateTime(2014, 6, 9)));
tester.tap(tester.findText('30')); tester.tap(tester.findText('30'));
expect(currentValue, equals(new DateTime(2013, 1, 30))); expect(currentValue, equals(new DateTime(2013, 1, 30)));
}); });
});
} }
import 'package:quiver/testing/async.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -86,24 +85,19 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect ...@@ -86,24 +85,19 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
tester.dispatchEvent(pointer.move(upLocation), downLocation); tester.dispatchEvent(pointer.move(upLocation), downLocation);
tester.dispatchEvent(pointer.up(), downLocation); tester.dispatchEvent(pointer.up(), downLocation);
double t0 = 0.0; tester.pumpWidget(widgetBuilder()); // start the resize animation
new FakeAsync().run((async) { tester.pumpWidget(widgetBuilder(), const Duration(seconds: 1)); // finish the resize animation
tester.pumpFrame(widgetBuilder(), t0); // start the resize animation tester.pumpWidget(widgetBuilder(), const Duration(seconds: 1)); // dismiss
tester.pumpFrame(widgetBuilder(), t0 + 1000.0); // finish the resize animation
async.elapse(new Duration(seconds: 1));
tester.pumpFrame(widgetBuilder(), t0 + 2000.0); // dismiss
async.elapse(new Duration(seconds: 1));
});
} }
void main() { void main() {
test('Horizontal drag triggers dismiss scrollDirection=vertical', () { test('Horizontal drag triggers dismiss scrollDirection=vertical', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.vertical; scrollDirection = ScrollDirection.vertical;
dismissDirection = DismissDirection.horizontal; dismissDirection = DismissDirection.horizontal;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.right); dismissItem(tester, 0, gestureDirection: DismissDirection.right);
...@@ -114,14 +108,15 @@ void main() { ...@@ -114,14 +108,15 @@ void main() {
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
expect(dismissedItems, equals([0, 1])); expect(dismissedItems, equals([0, 1]));
}); });
});
test('Vertical drag triggers dismiss scrollDirection=horizontal', () { test('Vertical drag triggers dismiss scrollDirection=horizontal', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.horizontal; scrollDirection = ScrollDirection.horizontal;
dismissDirection = DismissDirection.vertical; dismissDirection = DismissDirection.vertical;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.up); dismissItem(tester, 0, gestureDirection: DismissDirection.up);
...@@ -132,14 +127,15 @@ void main() { ...@@ -132,14 +127,15 @@ void main() {
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
expect(dismissedItems, equals([0, 1])); expect(dismissedItems, equals([0, 1]));
}); });
});
test('drag-left with DismissDirection.left triggers dismiss', () { test('drag-left with DismissDirection.left triggers dismiss', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.vertical; scrollDirection = ScrollDirection.vertical;
dismissDirection = DismissDirection.left; dismissDirection = DismissDirection.left;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.right); dismissItem(tester, 0, gestureDirection: DismissDirection.right);
...@@ -150,14 +146,15 @@ void main() { ...@@ -150,14 +146,15 @@ void main() {
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
}); });
});
test('drag-right with DismissDirection.right triggers dismiss', () { test('drag-right with DismissDirection.right triggers dismiss', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.vertical; scrollDirection = ScrollDirection.vertical;
dismissDirection = DismissDirection.right; dismissDirection = DismissDirection.right;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.left); dismissItem(tester, 0, gestureDirection: DismissDirection.left);
...@@ -168,14 +165,15 @@ void main() { ...@@ -168,14 +165,15 @@ void main() {
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
}); });
});
test('drag-up with DismissDirection.up triggers dismiss', () { test('drag-up with DismissDirection.up triggers dismiss', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.horizontal; scrollDirection = ScrollDirection.horizontal;
dismissDirection = DismissDirection.up; dismissDirection = DismissDirection.up;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.down); dismissItem(tester, 0, gestureDirection: DismissDirection.down);
...@@ -186,14 +184,15 @@ void main() { ...@@ -186,14 +184,15 @@ void main() {
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
}); });
});
test('drag-down with DismissDirection.down triggers dismiss', () { test('drag-down with DismissDirection.down triggers dismiss', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.horizontal; scrollDirection = ScrollDirection.horizontal;
dismissDirection = DismissDirection.down; dismissDirection = DismissDirection.down;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
dismissItem(tester, 0, gestureDirection: DismissDirection.up); dismissItem(tester, 0, gestureDirection: DismissDirection.up);
...@@ -204,16 +203,17 @@ void main() { ...@@ -204,16 +203,17 @@ void main() {
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0])); expect(dismissedItems, equals([0]));
}); });
});
// This is a regression test for // This is a regression test for
// https://github.com/domokit/sky_engine/issues/1068 // https://github.com/domokit/sky_engine/issues/1068
test('Verify that drag-move events do not assert', () { test('Verify that drag-move events do not assert', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
scrollDirection = ScrollDirection.horizontal; scrollDirection = ScrollDirection.horizontal;
dismissDirection = DismissDirection.down; dismissDirection = DismissDirection.down;
dismissedItems = []; dismissedItems = [];
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
Element itemElement = tester.findText('0'); Element itemElement = tester.findText('0');
TestPointer pointer = new TestPointer(5); TestPointer pointer = new TestPointer(5);
...@@ -221,12 +221,13 @@ void main() { ...@@ -221,12 +221,13 @@ void main() {
Offset offset = new Offset(0.0, 5.0); Offset offset = new Offset(0.0, 5.0);
tester.dispatchEvent(pointer.down(location), location); tester.dispatchEvent(pointer.down(location), location);
tester.dispatchEvent(pointer.move(location + offset), location); tester.dispatchEvent(pointer.move(location + offset), location);
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
tester.dispatchEvent(pointer.move(location + (offset * 2.0)), location); tester.dispatchEvent(pointer.move(location + (offset * 2.0)), location);
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
tester.dispatchEvent(pointer.move(location + (offset * 3.0)), location); tester.dispatchEvent(pointer.move(location + (offset * 3.0)), location);
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
tester.dispatchEvent(pointer.move(location + (offset * 4.0)), location); tester.dispatchEvent(pointer.move(location + (offset * 4.0)), location);
tester.pumpFrame(widgetBuilder()); tester.pumpWidget(widgetBuilder());
});
}); });
} }
...@@ -6,12 +6,12 @@ import 'widget_tester.dart'; ...@@ -6,12 +6,12 @@ import 'widget_tester.dart';
void main() { void main() {
test('Drag and drop - control test', () { test('Drag and drop - control test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
TestPointer pointer = new TestPointer(7); TestPointer pointer = new TestPointer(7);
List accepted = []; List accepted = [];
tester.pumpFrame(new Navigator( tester.pumpWidget(new Navigator(
routes: { routes: {
'/': (NavigatorState navigator, Route route) { return new Column([ '/': (NavigatorState navigator, Route route) { return new Column([
new Draggable( new Draggable(
...@@ -43,7 +43,7 @@ void main() { ...@@ -43,7 +43,7 @@ void main() {
Point firstLocation = tester.getCenter(tester.findText('Source')); Point firstLocation = tester.getCenter(tester.findText('Source'));
tester.dispatchEvent(pointer.down(firstLocation), firstLocation); tester.dispatchEvent(pointer.down(firstLocation), firstLocation);
tester.pumpFrameWithoutChange(); tester.pump();
expect(accepted, isEmpty); expect(accepted, isEmpty);
expect(tester.findText('Source'), isNotNull); expect(tester.findText('Source'), isNotNull);
...@@ -52,7 +52,7 @@ void main() { ...@@ -52,7 +52,7 @@ void main() {
Point secondLocation = tester.getCenter(tester.findText('Target')); Point secondLocation = tester.getCenter(tester.findText('Target'));
tester.dispatchEvent(pointer.move(secondLocation), firstLocation); tester.dispatchEvent(pointer.move(secondLocation), firstLocation);
tester.pumpFrameWithoutChange(); tester.pump();
expect(accepted, isEmpty); expect(accepted, isEmpty);
expect(tester.findText('Source'), isNotNull); expect(tester.findText('Source'), isNotNull);
...@@ -60,12 +60,12 @@ void main() { ...@@ -60,12 +60,12 @@ void main() {
expect(tester.findText('Target'), isNotNull); expect(tester.findText('Target'), isNotNull);
tester.dispatchEvent(pointer.up(), firstLocation); tester.dispatchEvent(pointer.up(), firstLocation);
tester.pumpFrameWithoutChange(); tester.pump();
expect(accepted, equals([1])); expect(accepted, equals([1]));
expect(tester.findText('Source'), isNotNull); expect(tester.findText('Source'), isNotNull);
expect(tester.findText('Dragging'), isNull); expect(tester.findText('Dragging'), isNull);
expect(tester.findText('Target'), isNotNull); expect(tester.findText('Target'), isNotNull);
});
}); });
} }
...@@ -42,14 +42,15 @@ Widget builder() { ...@@ -42,14 +42,15 @@ Widget builder() {
void main() { void main() {
test('duplicate key smoke test', () { test('duplicate key smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(builder()); tester.pumpWidget(builder());
StatefulLeafState leaf = tester.findStateOfType(StatefulLeafState); StatefulLeafState leaf = tester.findStateOfType(StatefulLeafState);
leaf.test(); leaf.test();
tester.pumpFrameWithoutChange(); tester.pump();
Item lastItem = items[1]; Item lastItem = items[1];
items.remove(lastItem); items.remove(lastItem);
items.insert(0, lastItem); items.insert(0, lastItem);
tester.pumpFrame(builder()); // this marks the app dirty and rebuilds it tester.pumpWidget(builder()); // this marks the app dirty and rebuilds it
});
}); });
} }
...@@ -5,10 +5,9 @@ import 'widget_tester.dart'; ...@@ -5,10 +5,9 @@ import 'widget_tester.dart';
void main() { void main() {
test('Can hit test flex children of stacks', () { test('Can hit test flex children of stacks', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
bool didReceiveTap = false; bool didReceiveTap = false;
tester.pumpFrame( tester.pumpWidget(
new Container( new Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
backgroundColor: const Color(0xFF00FF00) backgroundColor: const Color(0xFF00FF00)
...@@ -42,4 +41,5 @@ void main() { ...@@ -42,4 +41,5 @@ void main() {
tester.tap(tester.findText('X')); tester.tap(tester.findText('X'));
expect(didReceiveTap, isTrue); expect(didReceiveTap, isTrue);
}); });
});
} }
...@@ -6,7 +6,7 @@ import 'widget_tester.dart'; ...@@ -6,7 +6,7 @@ import 'widget_tester.dart';
void main() { void main() {
test('Uncontested scrolls start immediately', () { test('Uncontested scrolls start immediately', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
TestPointer pointer = new TestPointer(7); TestPointer pointer = new TestPointer(7);
bool didStartDrag = false; bool didStartDrag = false;
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
child: new Container() child: new Container()
); );
tester.pumpFrame(widget); tester.pumpWidget(widget);
expect(didStartDrag, isFalse); expect(didStartDrag, isFalse);
expect(updatedDragDelta, isNull); expect(updatedDragDelta, isNull);
expect(didEndDrag, isFalse); expect(didEndDrag, isFalse);
...@@ -51,11 +51,12 @@ void main() { ...@@ -51,11 +51,12 @@ void main() {
expect(didEndDrag, isTrue); expect(didEndDrag, isTrue);
didEndDrag = false; didEndDrag = false;
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
});
}); });
test('Match two scroll gestures in succession', () { test('Match two scroll gestures in succession', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
TestPointer pointer = new TestPointer(7); TestPointer pointer = new TestPointer(7);
int gestureCount = 0; int gestureCount = 0;
...@@ -71,7 +72,7 @@ void main() { ...@@ -71,7 +72,7 @@ void main() {
onHorizontalDragEnd: (Offset velocity) { fail("gesture should not match"); }, onHorizontalDragEnd: (Offset velocity) { fail("gesture should not match"); },
child: new Container() child: new Container()
); );
tester.pumpFrame(widget); tester.pumpWidget(widget);
tester.dispatchEvent(pointer.down(downLocation), downLocation); tester.dispatchEvent(pointer.down(downLocation), downLocation);
tester.dispatchEvent(pointer.move(upLocation), downLocation); tester.dispatchEvent(pointer.move(upLocation), downLocation);
...@@ -84,6 +85,7 @@ void main() { ...@@ -84,6 +85,7 @@ void main() {
expect(gestureCount, 2); expect(gestureCount, 2);
expect(dragDistance, 20.0); expect(dragDistance, 20.0);
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
});
}); });
} }
...@@ -6,8 +6,7 @@ import 'test_widgets.dart'; ...@@ -6,8 +6,7 @@ import 'test_widgets.dart';
void main() { void main() {
test('HomogeneousViewport mount/dismount smoke test', () { test('HomogeneousViewport mount/dismount smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -35,7 +34,7 @@ void main() { ...@@ -35,7 +34,7 @@ void main() {
); );
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent);
FlipComponentState testComponent = element.state; FlipComponentState testComponent = element.state;
...@@ -44,20 +43,20 @@ void main() { ...@@ -44,20 +43,20 @@ void main() {
callbackTracker.clear(); callbackTracker.clear();
testComponent.flip(); testComponent.flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(callbackTracker, equals([])); expect(callbackTracker, equals([]));
callbackTracker.clear(); callbackTracker.clear();
testComponent.flip(); testComponent.flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); expect(callbackTracker, equals([0, 1, 2, 3, 4, 5]));
}); });
});
test('HomogeneousViewport vertical', () { test('HomogeneousViewport vertical', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -93,7 +92,7 @@ void main() { ...@@ -93,7 +92,7 @@ void main() {
return testComponent; return testComponent;
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
expect(callbackTracker, equals([1, 2, 3, 4])); expect(callbackTracker, equals([1, 2, 3, 4]));
...@@ -101,16 +100,16 @@ void main() { ...@@ -101,16 +100,16 @@ void main() {
offset = 400.0; // now only 3 should fit, numbered 2-4. offset = 400.0; // now only 3 should fit, numbered 2-4.
tester.pumpFrame(builder()); tester.pumpWidget(builder());
expect(callbackTracker, equals([2, 3, 4])); expect(callbackTracker, equals([2, 3, 4]));
callbackTracker.clear(); callbackTracker.clear();
}); });
});
test('HomogeneousViewport horizontal', () { test('HomogeneousViewport horizontal', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -147,7 +146,7 @@ void main() { ...@@ -147,7 +146,7 @@ void main() {
return testComponent; return testComponent;
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
expect(callbackTracker, equals([1, 2, 3, 4, 5])); expect(callbackTracker, equals([1, 2, 3, 4, 5]));
...@@ -155,10 +154,11 @@ void main() { ...@@ -155,10 +154,11 @@ void main() {
offset = 400.0; // now only 4 should fit, numbered 2-5. offset = 400.0; // now only 4 should fit, numbered 2-5.
tester.pumpFrame(builder()); tester.pumpWidget(builder());
expect(callbackTracker, equals([2, 3, 4, 5])); expect(callbackTracker, equals([2, 3, 4, 5]));
callbackTracker.clear(); callbackTracker.clear();
}); });
});
} }
import 'package:mojo_services/keyboard/keyboard.mojom.dart'; import 'package:mojo_services/keyboard/keyboard.mojom.dart';
import 'package:quiver/testing/async.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
...@@ -25,8 +24,7 @@ void main() { ...@@ -25,8 +24,7 @@ void main() {
serviceMocker.registerMockService(KeyboardServiceName, mockKeyboard); serviceMocker.registerMockService(KeyboardServiceName, mockKeyboard);
test('Editable text has consistent width', () { test('Editable text has consistent width', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
GlobalKey inputKey = new GlobalKey(); GlobalKey inputKey = new GlobalKey();
String inputValue; String inputValue;
...@@ -40,7 +38,7 @@ void main() { ...@@ -40,7 +38,7 @@ void main() {
); );
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
Element input = tester.findElementByKey(inputKey); Element input = tester.findElementByKey(inputKey);
Size emptyInputSize = (input.renderObject as RenderBox).size; Size emptyInputSize = (input.renderObject as RenderBox).size;
...@@ -53,15 +51,15 @@ void main() { ...@@ -53,15 +51,15 @@ void main() {
// Check that the onChanged event handler fired. // Check that the onChanged event handler fired.
expect(inputValue, equals(testValue)); expect(inputValue, equals(testValue));
tester.pumpFrame(builder()); tester.pumpWidget(builder());
// Check that the Input with text has the same size as the empty Input. // Check that the Input with text has the same size as the empty Input.
expect((input.renderObject as RenderBox).size, equals(emptyInputSize)); expect((input.renderObject as RenderBox).size, equals(emptyInputSize));
}); });
});
test('Cursor blinks', () { test('Cursor blinks', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
GlobalKey inputKey = new GlobalKey(); GlobalKey inputKey = new GlobalKey();
Widget builder() { Widget builder() {
...@@ -73,17 +71,16 @@ void main() { ...@@ -73,17 +71,16 @@ void main() {
); );
} }
new FakeAsync().run((async) { tester.pumpWidget(builder());
tester.pumpFrame(builder());
EditableTextState editableText = tester.findStateOfType(EditableTextState); EditableTextState editableText = tester.findStateOfType(EditableTextState);
// Check that the cursor visibility toggles after each blink interval. // Check that the cursor visibility toggles after each blink interval.
void checkCursorToggle() { void checkCursorToggle() {
bool initialShowCursor = editableText.test_showCursor; bool initialShowCursor = editableText.test_showCursor;
async.elapse(editableText.test_cursorBlinkPeriod); tester.async.elapse(editableText.test_cursorBlinkPeriod);
expect(editableText.test_showCursor, equals(!initialShowCursor)); expect(editableText.test_showCursor, equals(!initialShowCursor));
async.elapse(editableText.test_cursorBlinkPeriod); tester.async.elapse(editableText.test_cursorBlinkPeriod);
expect(editableText.test_showCursor, equals(initialShowCursor)); expect(editableText.test_showCursor, equals(initialShowCursor));
} }
......
...@@ -5,11 +5,10 @@ import 'widget_tester.dart'; ...@@ -5,11 +5,10 @@ import 'widget_tester.dart';
void main() { void main() {
test('Events bubble up the tree', () { test('Events bubble up the tree', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<String> log = new List<String>(); List<String> log = new List<String>();
tester.pumpFrame( tester.pumpWidget(
new Listener( new Listener(
onPointerDown: (_) { onPointerDown: (_) {
log.add('top'); log.add('top');
...@@ -39,4 +38,5 @@ void main() { ...@@ -39,4 +38,5 @@ void main() {
'top', 'top',
])); ]));
}); });
});
} }
...@@ -6,8 +6,7 @@ import 'test_widgets.dart'; ...@@ -6,8 +6,7 @@ import 'test_widgets.dart';
void main() { void main() {
test('MixedViewport mount/dismount smoke test', () { test('MixedViewport mount/dismount smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -30,7 +29,7 @@ void main() { ...@@ -30,7 +29,7 @@ void main() {
); );
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent);
FlipComponentState testComponent = element.state; FlipComponentState testComponent = element.state;
...@@ -39,21 +38,20 @@ void main() { ...@@ -39,21 +38,20 @@ void main() {
callbackTracker.clear(); callbackTracker.clear();
testComponent.flip(); testComponent.flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(callbackTracker, equals([])); expect(callbackTracker, equals([]));
callbackTracker.clear(); callbackTracker.clear();
testComponent.flip(); testComponent.flip();
tester.pumpFrameWithoutChange(); tester.pump();
expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); expect(callbackTracker, equals([0, 1, 2, 3, 4, 5]));
});
}); });
test('MixedViewport vertical', () { test('MixedViewport vertical', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -82,7 +80,7 @@ void main() { ...@@ -82,7 +80,7 @@ void main() {
); );
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
// 0 is built to find its width // 0 is built to find its width
expect(callbackTracker, equals([0, 1, 2, 3, 4])); expect(callbackTracker, equals([0, 1, 2, 3, 4]));
...@@ -91,18 +89,17 @@ void main() { ...@@ -91,18 +89,17 @@ void main() {
offset = 400.0; // now only 3 should fit, numbered 2-4. offset = 400.0; // now only 3 should fit, numbered 2-4.
tester.pumpFrame(builder()); tester.pumpWidget(builder());
// 0 and 1 aren't built, we know their size and nothing else changed // 0 and 1 aren't built, we know their size and nothing else changed
expect(callbackTracker, equals([2, 3, 4])); expect(callbackTracker, equals([2, 3, 4]));
callbackTracker.clear(); callbackTracker.clear();
});
}); });
test('MixedViewport horizontal', () { test('MixedViewport horizontal', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[]; List<int> callbackTracker = <int>[];
// the root view is 800x600 in the test environment // the root view is 800x600 in the test environment
...@@ -132,7 +129,7 @@ void main() { ...@@ -132,7 +129,7 @@ void main() {
); );
} }
tester.pumpFrame(builder()); tester.pumpWidget(builder());
// 0 is built to find its width // 0 is built to find its width
expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); expect(callbackTracker, equals([0, 1, 2, 3, 4, 5]));
...@@ -141,12 +138,12 @@ void main() { ...@@ -141,12 +138,12 @@ void main() {
offset = 400.0; // now only 4 should fit, numbered 2-5. offset = 400.0; // now only 4 should fit, numbered 2-5.
tester.pumpFrame(builder()); tester.pumpWidget(builder());
// 0 and 1 aren't built, we know their size and nothing else changed // 0 and 1 aren't built, we know their size and nothing else changed
expect(callbackTracker, equals([2, 3, 4, 5])); expect(callbackTracker, equals([2, 3, 4, 5]));
callbackTracker.clear(); callbackTracker.clear();
});
}); });
} }
...@@ -28,9 +28,9 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) { ...@@ -28,9 +28,9 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
void main() { void main() {
test('MultiChildRenderObjectElement control test', () { test('MultiChildRenderObjectElement control test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new DecoratedBox(decoration: kBoxDecorationB), new DecoratedBox(decoration: kBoxDecorationB),
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new DecoratedBox(decoration: kBoxDecorationC), new DecoratedBox(decoration: kBoxDecorationC),
...@@ -49,7 +49,7 @@ void main() { ...@@ -49,7 +49,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB),
...@@ -59,7 +59,7 @@ void main() { ...@@ -59,7 +59,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB),
new DecoratedBox(decoration: kBoxDecorationC), new DecoratedBox(decoration: kBoxDecorationC),
...@@ -69,7 +69,7 @@ void main() { ...@@ -69,7 +69,7 @@ void main() {
checkTree(tester, [kBoxDecorationB, kBoxDecorationC, kBoxDecorationA]); checkTree(tester, [kBoxDecorationB, kBoxDecorationC, kBoxDecorationA]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA), new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA),
new DecoratedBox(decoration: kBoxDecorationC), new DecoratedBox(decoration: kBoxDecorationC),
...@@ -79,7 +79,7 @@ void main() { ...@@ -79,7 +79,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationC, kBoxDecorationB]); checkTree(tester, [kBoxDecorationA, kBoxDecorationC, kBoxDecorationB]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationC), new DecoratedBox(decoration: kBoxDecorationC),
]) ])
...@@ -87,17 +87,19 @@ void main() { ...@@ -87,17 +87,19 @@ void main() {
checkTree(tester, [kBoxDecorationC]); checkTree(tester, [kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([]) new Stack([])
); );
checkTree(tester, []); checkTree(tester, []);
});
}); });
test('MultiChildRenderObjectElement with stateless components', () { test('MultiChildRenderObjectElement with stateless components', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new DecoratedBox(decoration: kBoxDecorationB), new DecoratedBox(decoration: kBoxDecorationB),
...@@ -107,7 +109,7 @@ void main() { ...@@ -107,7 +109,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new Container( new Container(
...@@ -119,7 +121,7 @@ void main() { ...@@ -119,7 +121,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new Container( new Container(
...@@ -133,7 +135,7 @@ void main() { ...@@ -133,7 +135,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Container( new Container(
child: new Container( child: new Container(
...@@ -149,7 +151,7 @@ void main() { ...@@ -149,7 +151,7 @@ void main() {
checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Container( new Container(
child: new DecoratedBox(decoration: kBoxDecorationB) child: new DecoratedBox(decoration: kBoxDecorationB)
...@@ -163,7 +165,7 @@ void main() { ...@@ -163,7 +165,7 @@ void main() {
checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Container( new Container(
key: new Key('b'), key: new Key('b'),
...@@ -178,7 +180,7 @@ void main() { ...@@ -178,7 +180,7 @@ void main() {
checkTree(tester, [kBoxDecorationB, kBoxDecorationA]); checkTree(tester, [kBoxDecorationB, kBoxDecorationA]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Container( new Container(
key: new Key('a'), key: new Key('a'),
...@@ -193,17 +195,17 @@ void main() { ...@@ -193,17 +195,17 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ ]) new Stack([ ])
); );
checkTree(tester, []); checkTree(tester, []);
}); });
});
test('MultiChildRenderObjectElement with stateful components', () { test('MultiChildRenderObjectElement with stateful components', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new DecoratedBox(decoration: kBoxDecorationB), new DecoratedBox(decoration: kBoxDecorationB),
...@@ -212,7 +214,7 @@ void main() { ...@@ -212,7 +214,7 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); checkTree(tester, [kBoxDecorationA, kBoxDecorationB]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new FlipComponent( new FlipComponent(
left: new DecoratedBox(decoration: kBoxDecorationA), left: new DecoratedBox(decoration: kBoxDecorationA),
...@@ -225,11 +227,11 @@ void main() { ...@@ -225,11 +227,11 @@ void main() {
checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); checkTree(tester, [kBoxDecorationA, kBoxDecorationC]);
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationB, kBoxDecorationC]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new FlipComponent( new FlipComponent(
left: new DecoratedBox(decoration: kBoxDecorationA), left: new DecoratedBox(decoration: kBoxDecorationA),
...@@ -241,11 +243,11 @@ void main() { ...@@ -241,11 +243,11 @@ void main() {
checkTree(tester, [kBoxDecorationB]); checkTree(tester, [kBoxDecorationB]);
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(tester, [kBoxDecorationA]); checkTree(tester, [kBoxDecorationA]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new FlipComponent( new FlipComponent(
key: new Key('flip'), key: new Key('flip'),
...@@ -255,7 +257,7 @@ void main() { ...@@ -255,7 +257,7 @@ void main() {
]) ])
); );
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC), new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC),
new FlipComponent( new FlipComponent(
...@@ -269,11 +271,11 @@ void main() { ...@@ -269,11 +271,11 @@ void main() {
checkTree(tester, [kBoxDecorationC, kBoxDecorationA]); checkTree(tester, [kBoxDecorationC, kBoxDecorationA]);
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(tester, [kBoxDecorationC, kBoxDecorationB]); checkTree(tester, [kBoxDecorationC, kBoxDecorationB]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new FlipComponent( new FlipComponent(
key: new Key('flip'), key: new Key('flip'),
...@@ -285,6 +287,6 @@ void main() { ...@@ -285,6 +287,6 @@ void main() {
); );
checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); checkTree(tester, [kBoxDecorationB, kBoxDecorationC]);
});
}); });
} }
import 'package:sky/animation.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -48,36 +47,35 @@ class SecondComponentState extends State<SecondComponent> { ...@@ -48,36 +47,35 @@ class SecondComponentState extends State<SecondComponent> {
void main() { void main() {
test('Can navigator navigate to and from a stateful component', () { test('Can navigator navigate to and from a stateful component', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/': (navigator, route) => new FirstComponent(navigator), '/': (navigator, route) => new FirstComponent(navigator),
'/second': (navigator, route) => new SecondComponent(navigator), '/second': (navigator, route) => new SecondComponent(navigator),
}; };
tester.pumpFrame(new Navigator(routes: routes)); tester.pumpWidget(new Navigator(routes: routes));
expect(tester.findText('X'), isNotNull); expect(tester.findText('X'), isNotNull);
expect(tester.findText('Y'), isNull); expect(tester.findText('Y'), isNull);
tester.tap(tester.findText('X')); tester.tap(tester.findText('X'));
scheduler.beginFrame(10.0); tester.pump(const Duration(milliseconds: 10));
expect(tester.findText('X'), isNotNull); expect(tester.findText('X'), isNotNull);
expect(tester.findText('Y'), isNotNull); expect(tester.findText('Y'), isNotNull);
scheduler.beginFrame(20.0); tester.pump(const Duration(milliseconds: 10));
scheduler.beginFrame(30.0); tester.pump(const Duration(milliseconds: 10));
scheduler.beginFrame(1000.0); tester.pump(const Duration(seconds: 1));
tester.tap(tester.findText('Y')); tester.tap(tester.findText('Y'));
scheduler.beginFrame(1010.0); tester.pump(const Duration(milliseconds: 10));
scheduler.beginFrame(1020.0); tester.pump(const Duration(milliseconds: 10));
scheduler.beginFrame(1030.0); tester.pump(const Duration(milliseconds: 10));
scheduler.beginFrame(2000.0); tester.pump(const Duration(seconds: 1));
expect(tester.findText('X'), isNotNull); expect(tester.findText('X'), isNotNull);
expect(tester.findText('Y'), isNull); expect(tester.findText('Y'), isNull);
});
}); });
} }
import 'package:quiver/testing/async.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -33,13 +32,10 @@ Widget buildFrame() { ...@@ -33,13 +32,10 @@ Widget buildFrame() {
void page(WidgetTester tester, Offset offset) { void page(WidgetTester tester, Offset offset) {
String itemText = currentPage != null ? currentPage.toString() : '0'; String itemText = currentPage != null ? currentPage.toString() : '0';
new FakeAsync().run((async) {
tester.scroll(tester.findText(itemText), offset); tester.scroll(tester.findText(itemText), offset);
// One frame to start the animation, a second to complete it. // One frame to start the animation, a second to complete it.
tester.pumpFrameWithoutChange(); tester.pump();
tester.pumpFrameWithoutChange(1000.0); tester.pump(const Duration(seconds: 1));
async.elapse(new Duration(seconds: 1));
});
} }
void pageLeft(WidgetTester tester) { void pageLeft(WidgetTester tester) {
...@@ -54,59 +50,65 @@ void main() { ...@@ -54,59 +50,65 @@ void main() {
// PageableList with itemsWrap: false // PageableList with itemsWrap: false
test('Scroll left from page 0 to page 1', () { test('Scroll left from page 0 to page 1', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
currentPage = null; currentPage = null;
itemsWrap = false; itemsWrap = false;
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, isNull); expect(currentPage, isNull);
pageLeft(tester); pageLeft(tester);
expect(currentPage, equals(1)); expect(currentPage, equals(1));
}); });
});
test('Scroll right from page 1 to page 0', () { test('Scroll right from page 1 to page 0', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
itemsWrap = false; itemsWrap = false;
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, equals(1)); expect(currentPage, equals(1));
pageRight(tester); pageRight(tester);
expect(currentPage, equals(0)); expect(currentPage, equals(0));
}); });
});
test('Scroll right from page 0 does nothing (underscroll)', () { test('Scroll right from page 0 does nothing (underscroll)', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
itemsWrap = false; itemsWrap = false;
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, equals(0)); expect(currentPage, equals(0));
pageRight(tester); pageRight(tester);
expect(currentPage, equals(0)); expect(currentPage, equals(0));
}); });
});
// PageableList with itemsWrap: true // PageableList with itemsWrap: true
test('Scroll left page 0 to page 1, itemsWrap: true', () { test('Scroll left page 0 to page 1, itemsWrap: true', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.reset(); tester.pumpWidget(new Container());
currentPage = null; currentPage = null;
itemsWrap = true; itemsWrap = true;
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, isNull); expect(currentPage, isNull);
pageLeft(tester); pageLeft(tester);
expect(currentPage, equals(1)); expect(currentPage, equals(1));
}); });
});
test('Scroll right from page 1 to page 0, itemsWrap: true', () { test('Scroll right from page 1 to page 0, itemsWrap: true', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, equals(1)); expect(currentPage, equals(1));
pageRight(tester); pageRight(tester);
expect(currentPage, equals(0)); expect(currentPage, equals(0));
}); });
});
test('Scroll right from page 0 to page 5, itemsWrap: true (underscroll)', () { test('Scroll right from page 0 to page 5, itemsWrap: true (underscroll)', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
expect(currentPage, equals(0)); expect(currentPage, equals(0));
pageRight(tester); pageRight(tester);
expect(currentPage, equals(5)); expect(currentPage, equals(5));
}); });
});
} }
...@@ -58,9 +58,9 @@ void main() { ...@@ -58,9 +58,9 @@ void main() {
}); });
test('ParentDataWidget control test', () { test('ParentDataWidget control test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new DecoratedBox(decoration: kBoxDecorationA), new DecoratedBox(decoration: kBoxDecorationA),
new Positioned( new Positioned(
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
kNonPositioned, kNonPositioned,
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
bottom: 5.0, bottom: 5.0,
...@@ -104,7 +104,7 @@ void main() { ...@@ -104,7 +104,7 @@ void main() {
DecoratedBox kDecoratedBoxB = new DecoratedBox(decoration: kBoxDecorationB); DecoratedBox kDecoratedBoxB = new DecoratedBox(decoration: kBoxDecorationB);
DecoratedBox kDecoratedBoxC = new DecoratedBox(decoration: kBoxDecorationC); DecoratedBox kDecoratedBoxC = new DecoratedBox(decoration: kBoxDecorationC);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
bottom: 5.0, bottom: 5.0,
...@@ -126,7 +126,7 @@ void main() { ...@@ -126,7 +126,7 @@ void main() {
kNonPositioned, kNonPositioned,
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
bottom: 6.0, bottom: 6.0,
...@@ -148,7 +148,7 @@ void main() { ...@@ -148,7 +148,7 @@ void main() {
kNonPositioned, kNonPositioned,
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
kDecoratedBoxA, kDecoratedBoxA,
new Positioned( new Positioned(
...@@ -166,7 +166,7 @@ void main() { ...@@ -166,7 +166,7 @@ void main() {
kNonPositioned, kNonPositioned,
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
kDecoratedBoxA, kDecoratedBoxA,
new Positioned( new Positioned(
...@@ -188,7 +188,7 @@ void main() { ...@@ -188,7 +188,7 @@ void main() {
new TestParentData(top: 8.0), new TestParentData(top: 8.0),
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
right: 10.0, right: 10.0,
...@@ -202,13 +202,13 @@ void main() { ...@@ -202,13 +202,13 @@ void main() {
]); ]);
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(tester, [ checkTree(tester, [
new TestParentData(right: 10.0), new TestParentData(right: 10.0),
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
top: 7.0, top: 7.0,
...@@ -222,25 +222,25 @@ void main() { ...@@ -222,25 +222,25 @@ void main() {
]); ]);
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(tester, [ checkTree(tester, [
new TestParentData(top: 7.0), new TestParentData(top: 7.0),
]); ]);
tester.pumpFrame( tester.pumpWidget(
new Stack([]) new Stack([])
); );
checkTree(tester, []); checkTree(tester, []);
}); });
});
test('ParentDataWidget conflicting data', () { test('ParentDataWidget conflicting data', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
expect(cachedException, isNull); expect(cachedException, isNull);
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
top: 5.0, top: 5.0,
...@@ -257,12 +257,12 @@ void main() { ...@@ -257,12 +257,12 @@ void main() {
expect(cachedException, isNotNull); expect(cachedException, isNotNull);
cachedException = null; cachedException = null;
tester.pumpFrame(new Stack([])); tester.pumpWidget(new Stack([]));
checkTree(tester, []); checkTree(tester, []);
expect(cachedException, isNull); expect(cachedException, isNull);
tester.pumpFrame( tester.pumpWidget(
new Container( new Container(
child: new Flex([ child: new Flex([
new Positioned( new Positioned(
...@@ -277,11 +277,11 @@ void main() { ...@@ -277,11 +277,11 @@ void main() {
expect(cachedException, isNotNull); expect(cachedException, isNotNull);
cachedException = null; cachedException = null;
tester.pumpFrame( tester.pumpWidget(
new Stack([]) new Stack([])
); );
checkTree(tester, []); checkTree(tester, []);
}); });
});
} }
...@@ -7,15 +7,15 @@ import 'widget_tester.dart'; ...@@ -7,15 +7,15 @@ import 'widget_tester.dart';
void main() { void main() {
test('LinearProgressIndicator changes when its value changes', () { test('LinearProgressIndicator changes when its value changes', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(new Block([new LinearProgressIndicator(value: 0.0)]));
tester.pumpFrame(new Block([new LinearProgressIndicator(value: 0.0)]));
List<Layer> layers1 = tester.layers; List<Layer> layers1 = tester.layers;
tester.pumpFrame(new Block([new LinearProgressIndicator(value: 0.5)])); tester.pumpWidget(new Block([new LinearProgressIndicator(value: 0.5)]));
List<Layer> layers2 = tester.layers; List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2))); expect(layers1, isNot(equals(layers2)));
}); });
});
} }
...@@ -16,9 +16,8 @@ class TestComponent extends StatelessComponent { ...@@ -16,9 +16,8 @@ class TestComponent extends StatelessComponent {
void main() { void main() {
test('RenderObjectWidget smoke test', () { test('RenderObjectWidget smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(new DecoratedBox(decoration: kBoxDecorationA));
tester.pumpFrame(new DecoratedBox(decoration: kBoxDecorationA));
OneChildRenderObjectElement element = OneChildRenderObjectElement element =
tester.findElement((element) => element is OneChildRenderObjectElement); tester.findElement((element) => element is OneChildRenderObjectElement);
expect(element, isNotNull); expect(element, isNotNull);
...@@ -27,7 +26,7 @@ void main() { ...@@ -27,7 +26,7 @@ void main() {
expect(renderObject.decoration, equals(kBoxDecorationA)); expect(renderObject.decoration, equals(kBoxDecorationA));
expect(renderObject.position, equals(BoxDecorationPosition.background)); expect(renderObject.position, equals(BoxDecorationPosition.background));
tester.pumpFrame(new DecoratedBox(decoration: kBoxDecorationB)); tester.pumpWidget(new DecoratedBox(decoration: kBoxDecorationB));
element = tester.findElement((element) => element is OneChildRenderObjectElement); element = tester.findElement((element) => element is OneChildRenderObjectElement);
expect(element, isNotNull); expect(element, isNotNull);
expect(element.renderObject is RenderDecoratedBox, isTrue); expect(element.renderObject is RenderDecoratedBox, isTrue);
...@@ -35,9 +34,10 @@ void main() { ...@@ -35,9 +34,10 @@ void main() {
expect(renderObject.decoration, equals(kBoxDecorationB)); expect(renderObject.decoration, equals(kBoxDecorationB));
expect(renderObject.position, equals(BoxDecorationPosition.background)); expect(renderObject.position, equals(BoxDecorationPosition.background));
}); });
});
test('RenderObjectWidget can add and remove children', () { test('RenderObjectWidget can add and remove children', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
void checkFullTree() { void checkFullTree() {
OneChildRenderObjectElement element = OneChildRenderObjectElement element =
...@@ -66,7 +66,7 @@ void main() { ...@@ -66,7 +66,7 @@ void main() {
expect(renderObject.child, isNull); expect(renderObject.child, isNull);
} }
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA, decoration: kBoxDecorationA,
child: new DecoratedBox( child: new DecoratedBox(
decoration: kBoxDecorationB decoration: kBoxDecorationB
...@@ -75,7 +75,7 @@ void main() { ...@@ -75,7 +75,7 @@ void main() {
checkFullTree(); checkFullTree();
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA, decoration: kBoxDecorationA,
child: new TestComponent( child: new TestComponent(
child: new DecoratedBox( child: new DecoratedBox(
...@@ -86,7 +86,7 @@ void main() { ...@@ -86,7 +86,7 @@ void main() {
checkFullTree(); checkFullTree();
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA, decoration: kBoxDecorationA,
child: new DecoratedBox( child: new DecoratedBox(
decoration: kBoxDecorationB decoration: kBoxDecorationB
...@@ -95,13 +95,13 @@ void main() { ...@@ -95,13 +95,13 @@ void main() {
checkFullTree(); checkFullTree();
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA decoration: kBoxDecorationA
)); ));
childBareTree(); childBareTree();
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA, decoration: kBoxDecorationA,
child: new TestComponent( child: new TestComponent(
child: new TestComponent( child: new TestComponent(
...@@ -114,17 +114,18 @@ void main() { ...@@ -114,17 +114,18 @@ void main() {
checkFullTree(); checkFullTree();
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA decoration: kBoxDecorationA
)); ));
childBareTree(); childBareTree();
}); });
});
test('Detached render tree is intact', () { test('Detached render tree is intact', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA, decoration: kBoxDecorationA,
child: new DecoratedBox( child: new DecoratedBox(
decoration: kBoxDecorationB, decoration: kBoxDecorationB,
...@@ -146,7 +147,7 @@ void main() { ...@@ -146,7 +147,7 @@ void main() {
expect(grandChild.decoration, equals(kBoxDecorationC)); expect(grandChild.decoration, equals(kBoxDecorationC));
expect(grandChild.child, isNull); expect(grandChild.child, isNull);
tester.pumpFrame(new DecoratedBox( tester.pumpWidget(new DecoratedBox(
decoration: kBoxDecorationA decoration: kBoxDecorationA
)); ));
...@@ -163,4 +164,5 @@ void main() { ...@@ -163,4 +164,5 @@ void main() {
expect(grandChild.decoration, equals(kBoxDecorationC)); expect(grandChild.decoration, equals(kBoxDecorationC));
expect(grandChild.child, isNull); expect(grandChild.child, isNull);
}); });
});
} }
...@@ -8,11 +8,10 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5]; ...@@ -8,11 +8,10 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
List<int> tapped = <int>[]; List<int> tapped = <int>[];
void main() { void main() {
double t = 0.0;
WidgetTester tester = new WidgetTester();
test('Tap item after scroll - horizontal', () { test('Tap item after scroll - horizontal', () {
tester.pumpFrame(new Center( testWidgets((WidgetTester tester) {
tester.pumpWidget(new Container());
tester.pumpWidget(new Center(
child: new Container( child: new Container(
height: 50.0, height: 50.0,
child: new ScrollableList<int>( child: new ScrollableList<int>(
...@@ -31,9 +30,9 @@ void main() { ...@@ -31,9 +30,9 @@ void main() {
scrollDirection: ScrollDirection.horizontal scrollDirection: ScrollDirection.horizontal
) )
) )
), t); ));
tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -280..10 = 0 // -280..10 = 0
// 10..300 = 1 // 10..300 = 1
...@@ -49,9 +48,12 @@ void main() { ...@@ -49,9 +48,12 @@ void main() {
tester.tap(tester.findText('2')); tester.tap(tester.findText('2'));
expect(tapped, equals([2])); expect(tapped, equals([2]));
}); });
});
test('Tap item after scroll - vertical', () { test('Tap item after scroll - vertical', () {
tester.pumpFrame(new Center( testWidgets((WidgetTester tester) {
tester.pumpWidget(new Container());
tester.pumpWidget(new Center(
child: new Container( child: new Container(
width: 50.0, width: 50.0,
child: new ScrollableList<int>( child: new ScrollableList<int>(
...@@ -70,9 +72,9 @@ void main() { ...@@ -70,9 +72,9 @@ void main() {
scrollDirection: ScrollDirection.vertical scrollDirection: ScrollDirection.vertical
) )
) )
), t); ));
tester.scroll(tester.findText('1'), const Offset(0.0, -280.0)); tester.scroll(tester.findText('1'), const Offset(0.0, -280.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 600px tall, and has the following items: // screen is 600px tall, and has the following items:
// -280..10 = 0 // -280..10 = 0
// 10..300 = 1 // 10..300 = 1
...@@ -90,5 +92,5 @@ void main() { ...@@ -90,5 +92,5 @@ void main() {
tester.tap(tester.findText('3')); tester.tap(tester.findText('3'));
expect(tapped, equals([2, 1])); // the center of the third item is off-screen so it shouldn't get hit expect(tapped, equals([2, 1])); // the center of the third item is off-screen so it shouldn't get hit
}); });
});
} }
...@@ -26,14 +26,13 @@ Widget buildFrame() { ...@@ -26,14 +26,13 @@ Widget buildFrame() {
} }
void main() { void main() {
double t = 0.0; test('Drag horizontally', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(buildFrame()); tester.pumpWidget(buildFrame());
test('Drag to the left using item 1', () { tester.pump(const Duration(seconds: 1));
tester.pumpFrameWithoutChange(t += 1000.0);
tester.scroll(tester.findText('1'), const Offset(-300.0, 0.0)); tester.scroll(tester.findText('1'), const Offset(-300.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -10..280 = 1 // -10..280 = 1
// 280..570 = 2 // 280..570 = 2
...@@ -44,15 +43,13 @@ void main() { ...@@ -44,15 +43,13 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNull); expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
});
test('Drag to the left using item 3', () {
// the center of item 3 is visible, so this works; // the center of item 3 is visible, so this works;
// if item 3 was a bit wider, such that it's center was past the 800px mark, this would fail, // if item 3 was a bit wider, such that it's center was past the 800px mark, this would fail,
// because it wouldn't be hit tested when scrolling from its center, as scroll() does. // because it wouldn't be hit tested when scrolling from its center, as scroll() does.
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -10..280 = 2 // -10..280 = 2
// 280..570 = 3 // 280..570 = 3
...@@ -63,12 +60,10 @@ void main() { ...@@ -63,12 +60,10 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
});
test('Drag up using item 3', () { tester.pump(const Duration(seconds: 1));
tester.pumpFrameWithoutChange(t += 1000.0);
tester.scroll(tester.findText('3'), const Offset(0.0, -290.0)); tester.scroll(tester.findText('3'), const Offset(0.0, -290.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// unchanged // unchanged
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
...@@ -76,12 +71,10 @@ void main() { ...@@ -76,12 +71,10 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
});
test('Drag to the left using item 3 again', () { tester.pump(const Duration(seconds: 1));
tester.pumpFrameWithoutChange(t += 1000.0);
tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -10..280 = 3 // -10..280 = 3
// 280..570 = 4 // 280..570 = 4
...@@ -92,17 +85,15 @@ void main() { ...@@ -92,17 +85,15 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNotNull); expect(tester.findText('5'), isNotNull);
});
test('Drag to the left using item 3 again again (past the end of the list)', () { tester.pump(const Duration(seconds: 1));
tester.pumpFrameWithoutChange(t += 1000.0);
// at this point we can drag 60 pixels further before we hit the friction zone // at this point we can drag 60 pixels further before we hit the friction zone
// then, every pixel we drag is equivalent to half a pixel of movement // then, every pixel we drag is equivalent to half a pixel of movement
// to move item 3 entirely off screen therefore takes: // to move item 3 entirely off screen therefore takes:
// 60 + (290-60)*2 = 520 pixels // 60 + (290-60)*2 = 520 pixels
// plus a couple more to be sure // plus a couple more to be sure
tester.scroll(tester.findText('3'), const Offset(-522.0, 0.0)); tester.scroll(tester.findText('3'), const Offset(-522.0, 0.0));
tester.pumpFrameWithoutChange(t += 0.0); // just after release tester.pump(); // just after release
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -11..279 = 4 // -11..279 = 4
// 279..569 = 5 // 279..569 = 5
...@@ -112,7 +103,7 @@ void main() { ...@@ -112,7 +103,7 @@ void main() {
expect(tester.findText('3'), isNull); expect(tester.findText('3'), isNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNotNull); expect(tester.findText('5'), isNotNull);
tester.pumpFrameWithoutChange(t += 1000.0); // a second after release tester.pump(const Duration(seconds: 1)); // a second after release
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -70..220 = 3 // -70..220 = 3
// 220..510 = 4 // 220..510 = 4
...@@ -123,13 +114,11 @@ void main() { ...@@ -123,13 +114,11 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNotNull); expect(tester.findText('5'), isNotNull);
});
test('Drag to the left using item 2 when the scroll offset is big', () { tester.pumpWidget(new Container());
tester.reset(); tester.pumpWidget(buildFrame(), const Duration(seconds: 1));
tester.pumpFrame(buildFrame(), t += 1000.0);
tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -280..10 = 0 // -280..10 = 0
// 10..300 = 1 // 10..300 = 1
...@@ -141,9 +130,9 @@ void main() { ...@@ -141,9 +130,9 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNull); expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
tester.scroll(tester.findText('2'), const Offset(-290.0, 0.0)); tester.scroll(tester.findText('2'), const Offset(-290.0, 0.0));
tester.pumpFrameWithoutChange(t += 1000.0); tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
// -280..10 = 1 // -280..10 = 1
// 10..300 = 2 // 10..300 = 2
...@@ -156,5 +145,5 @@ void main() { ...@@ -156,5 +145,5 @@ void main() {
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
}); });
});
} }
...@@ -20,13 +20,13 @@ Widget buildFrame() { ...@@ -20,13 +20,13 @@ Widget buildFrame() {
} }
void main() { void main() {
WidgetTester tester = new WidgetTester(); test('Drag vertically', () {
tester.pumpFrame(buildFrame()); testWidgets((WidgetTester tester) {
tester.pumpWidget(buildFrame());
test('Drag up using item 1', () { tester.pump();
tester.pumpFrameWithoutChange();
tester.scroll(tester.findText('1'), const Offset(0.0, -300.0)); tester.scroll(tester.findText('1'), const Offset(0.0, -300.0));
tester.pumpFrameWithoutChange(); tester.pump();
// screen is 600px high, and has the following items: // screen is 600px high, and has the following items:
// -10..280 = 1 // -10..280 = 1
// 280..570 = 2 // 280..570 = 2
...@@ -37,12 +37,10 @@ void main() { ...@@ -37,12 +37,10 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNull); expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
});
test('Drag up using item 2', () { tester.pump();
tester.pumpFrameWithoutChange();
tester.scroll(tester.findText('2'), const Offset(0.0, -290.0)); tester.scroll(tester.findText('2'), const Offset(0.0, -290.0));
tester.pumpFrameWithoutChange(); tester.pump();
// screen is 600px high, and has the following items: // screen is 600px high, and has the following items:
// -10..280 = 2 // -10..280 = 2
// 280..570 = 3 // 280..570 = 3
...@@ -53,12 +51,10 @@ void main() { ...@@ -53,12 +51,10 @@ void main() {
expect(tester.findText('3'), isNotNull); expect(tester.findText('3'), isNotNull);
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
});
test('Drag to the left using item 3', () { tester.pump();
tester.pumpFrameWithoutChange();
tester.scroll(tester.findText('3'), const Offset(-300.0, 0.0)); tester.scroll(tester.findText('3'), const Offset(-300.0, 0.0));
tester.pumpFrameWithoutChange(); tester.pump();
// nothing should have changed // nothing should have changed
expect(tester.findText('0'), isNull); expect(tester.findText('0'), isNull);
expect(tester.findText('1'), isNull); expect(tester.findText('1'), isNull);
...@@ -67,5 +63,5 @@ void main() { ...@@ -67,5 +63,5 @@ void main() {
expect(tester.findText('4'), isNotNull); expect(tester.findText('4'), isNotNull);
expect(tester.findText('5'), isNull); expect(tester.findText('5'), isNull);
}); });
});
} }
...@@ -48,10 +48,11 @@ class LeafState extends State<Leaf> { ...@@ -48,10 +48,11 @@ class LeafState extends State<Leaf> {
void main() { void main() {
test('three-way setState() smoke test', () { test('three-way setState() smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(new Changer(new Wrapper(new Leaf()))); tester.pumpWidget(new Changer(new Wrapper(new Leaf())));
tester.pumpFrame(new Changer(new Wrapper(new Leaf()))); tester.pumpWidget(new Changer(new Wrapper(new Leaf())));
changer.test(); changer.test();
tester.pumpFrameWithoutChange(); tester.pump();
});
}); });
} }
...@@ -54,13 +54,14 @@ class OutsideState extends State<Outside> { ...@@ -54,13 +54,14 @@ class OutsideState extends State<Outside> {
void main() { void main() {
test('setState() smoke test', () { test('setState() smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame(new Outside()); tester.pumpWidget(new Outside());
TestPointer pointer = new TestPointer(1); TestPointer pointer = new TestPointer(1);
Point location = tester.getCenter(tester.findText('INSIDE')); Point location = tester.getCenter(tester.findText('INSIDE'));
tester.dispatchEvent(pointer.down(location), location); tester.dispatchEvent(pointer.down(location), location);
tester.pumpFrameWithoutChange(); tester.pump();
tester.dispatchEvent(pointer.up(), location); tester.dispatchEvent(pointer.up(), location);
tester.pumpFrameWithoutChange(); tester.pump();
});
}); });
} }
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import 'package:quiver/testing/async.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -59,91 +58,60 @@ Future fling(double velocity) { ...@@ -59,91 +58,60 @@ Future fling(double velocity) {
} }
void main() { void main() {
WidgetTester tester = new WidgetTester();
tester.pumpFrame(buildFrame());
test('ScrollableList snap scrolling, fling(-800)', () { test('ScrollableList snap scrolling, fling(-800)', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(buildFrame());
scrollOffset = 0.0; scrollOffset = 0.0;
tester.pumpFrameWithoutChange(); tester.pump();
expect(scrollOffset, 0.0); expect(scrollOffset, 0.0);
double t0 = 0.0; Duration dt = const Duration(seconds: 2);
int dt = 2000;
new FakeAsync().run((async) {
fling(-800.0); fling(-800.0);
tester.pumpFrameWithoutChange(t0); // Start the scheduler at 0.0 tester.pump(); // Start the scheduler at 0.0
tester.pumpFrameWithoutChange(t0 + dt); tester.pump(dt);
async.elapse(new Duration(milliseconds: dt));
expect(scrollOffset, closeTo(200.0, 1.0)); expect(scrollOffset, closeTo(200.0, 1.0));
});
});
test('ScrollableList snap scrolling, fling(-2000)', () {
scrollOffset = 0.0; scrollOffset = 0.0;
tester.pumpFrameWithoutChange(); tester.pump();
expect(scrollOffset, 0.0); expect(scrollOffset, 0.0);
double t0 = 0.0;
int dt = 2000;
new FakeAsync().run((async) {
fling(-2000.0); fling(-2000.0);
tester.pumpFrameWithoutChange(t0); tester.pump();
tester.pumpFrameWithoutChange(t0 + dt); tester.pump(dt);
async.elapse(new Duration(milliseconds: dt));
expect(scrollOffset, closeTo(400.0, 1.0)); expect(scrollOffset, closeTo(400.0, 1.0));
});
});
test('ScrollableList snap scrolling, fling(800)', () {
scrollOffset = 400.0; scrollOffset = 400.0;
tester.pumpFrameWithoutChange(); tester.pump();
expect(scrollOffset, 400.0); expect(scrollOffset, 400.0);
double t0 = 0.0;
int dt = 2000;
new FakeAsync().run((async) {
fling(800.0); fling(800.0);
tester.pumpFrameWithoutChange(t0); tester.pump();
tester.pumpFrameWithoutChange(t0 + dt); tester.pump(dt);
async.elapse(new Duration(milliseconds: dt));
expect(scrollOffset, closeTo(0.0, 1.0)); expect(scrollOffset, closeTo(0.0, 1.0));
});
});
test('ScrollableList snap scrolling, fling(2000)', () {
scrollOffset = 800.0; scrollOffset = 800.0;
tester.pumpFrameWithoutChange(); tester.pump();
expect(scrollOffset, 800.0); expect(scrollOffset, 800.0);
double t0 = 0.0;
int dt = 2000;
new FakeAsync().run((async) {
fling(2000.0); fling(2000.0);
tester.pumpFrameWithoutChange(t0); tester.pump();
tester.pumpFrameWithoutChange(t0 + dt); tester.pump(dt);
async.elapse(new Duration(milliseconds: dt));
expect(scrollOffset, closeTo(200.0, 1.0)); expect(scrollOffset, closeTo(200.0, 1.0));
});
});
test('ScrollableList snap scrolling, fling(2000).then()', () {
scrollOffset = 800.0; scrollOffset = 800.0;
tester.pumpFrameWithoutChange(); tester.pump();
expect(scrollOffset, 800.0); expect(scrollOffset, 800.0);
double t0 = 0.0;
int dt = 2000;
bool completed = false; bool completed = false;
new FakeAsync().run((async) {
fling(2000.0).then((_) { fling(2000.0).then((_) {
completed = true; completed = true;
expect(scrollOffset, closeTo(200.0, 1.0)); expect(scrollOffset, closeTo(200.0, 1.0));
}); });
tester.pumpFrameWithoutChange(t0); tester.pump();
tester.pumpFrameWithoutChange(t0 + dt); tester.pump(dt);
async.elapse(new Duration(milliseconds: dt));
expect(completed, true); expect(completed, true);
}); });
}); });
} }
...@@ -5,11 +5,10 @@ import 'widget_tester.dart'; ...@@ -5,11 +5,10 @@ import 'widget_tester.dart';
void main() { void main() {
test('Can change position data', () { test('Can change position data', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
Key key = new Key('container'); Key key = new Key('container');
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
left: 10.0, left: 10.0,
...@@ -28,7 +27,7 @@ void main() { ...@@ -28,7 +27,7 @@ void main() {
expect(container.renderObject.parentData.bottom, isNull); expect(container.renderObject.parentData.bottom, isNull);
expect(container.renderObject.parentData.left, equals(10.0)); expect(container.renderObject.parentData.left, equals(10.0));
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
right: 10.0, right: 10.0,
...@@ -47,14 +46,14 @@ void main() { ...@@ -47,14 +46,14 @@ void main() {
expect(container.renderObject.parentData.bottom, isNull); expect(container.renderObject.parentData.bottom, isNull);
expect(container.renderObject.parentData.left, isNull); expect(container.renderObject.parentData.left, isNull);
}); });
});
test('Can remove parent data', () { test('Can remove parent data', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
Key key = new Key('container'); Key key = new Key('container');
Container container = new Container(key: key, width: 10.0, height: 10.0); Container container = new Container(key: key, width: 10.0, height: 10.0);
tester.pumpFrame(new Stack([ new Positioned(left: 10.0, child: container) ])); tester.pumpWidget(new Stack([ new Positioned(left: 10.0, child: container) ]));
Element containerElement = tester.findElementByKey(key); Element containerElement = tester.findElementByKey(key);
expect(containerElement.renderObject.parentData.top, isNull); expect(containerElement.renderObject.parentData.top, isNull);
...@@ -62,7 +61,7 @@ void main() { ...@@ -62,7 +61,7 @@ void main() {
expect(containerElement.renderObject.parentData.bottom, isNull); expect(containerElement.renderObject.parentData.bottom, isNull);
expect(containerElement.renderObject.parentData.left, equals(10.0)); expect(containerElement.renderObject.parentData.left, equals(10.0));
tester.pumpFrame(new Stack([ container ])); tester.pumpWidget(new Stack([ container ]));
containerElement = tester.findElementByKey(key); containerElement = tester.findElementByKey(key);
expect(containerElement.renderObject.parentData.top, isNull); expect(containerElement.renderObject.parentData.top, isNull);
...@@ -70,5 +69,5 @@ void main() { ...@@ -70,5 +69,5 @@ void main() {
expect(containerElement.renderObject.parentData.bottom, isNull); expect(containerElement.renderObject.parentData.bottom, isNull);
expect(containerElement.renderObject.parentData.left, isNull); expect(containerElement.renderObject.parentData.left, isNull);
}); });
});
} }
...@@ -7,7 +7,7 @@ import 'test_widgets.dart'; ...@@ -7,7 +7,7 @@ import 'test_widgets.dart';
void main() { void main() {
test('Stateful component smoke test', () { test('Stateful component smoke test', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
void checkTree(BoxDecoration expectedDecoration) { void checkTree(BoxDecoration expectedDecoration) {
OneChildRenderObjectElement element = OneChildRenderObjectElement element =
...@@ -18,7 +18,7 @@ void main() { ...@@ -18,7 +18,7 @@ void main() {
expect(renderObject.decoration, equals(expectedDecoration)); expect(renderObject.decoration, equals(expectedDecoration));
} }
tester.pumpFrame( tester.pumpWidget(
new FlipComponent( new FlipComponent(
left: new DecoratedBox(decoration: kBoxDecorationA), left: new DecoratedBox(decoration: kBoxDecorationA),
right: new DecoratedBox(decoration: kBoxDecorationB) right: new DecoratedBox(decoration: kBoxDecorationB)
...@@ -27,7 +27,7 @@ void main() { ...@@ -27,7 +27,7 @@ void main() {
checkTree(kBoxDecorationA); checkTree(kBoxDecorationA);
tester.pumpFrame( tester.pumpWidget(
new FlipComponent( new FlipComponent(
left: new DecoratedBox(decoration: kBoxDecorationB), left: new DecoratedBox(decoration: kBoxDecorationB),
right: new DecoratedBox(decoration: kBoxDecorationA) right: new DecoratedBox(decoration: kBoxDecorationA)
...@@ -38,11 +38,11 @@ void main() { ...@@ -38,11 +38,11 @@ void main() {
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
checkTree(kBoxDecorationA); checkTree(kBoxDecorationA);
tester.pumpFrame( tester.pumpWidget(
new FlipComponent( new FlipComponent(
left: new DecoratedBox(decoration: kBoxDecorationA), left: new DecoratedBox(decoration: kBoxDecorationA),
right: new DecoratedBox(decoration: kBoxDecorationB) right: new DecoratedBox(decoration: kBoxDecorationB)
...@@ -50,12 +50,12 @@ void main() { ...@@ -50,12 +50,12 @@ void main() {
); );
checkTree(kBoxDecorationB); checkTree(kBoxDecorationB);
});
}); });
test('Don\'t rebuild subcomponents', () { test('Don\'t rebuild subcomponents', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpFrame( tester.pumpWidget(
new FlipComponent( new FlipComponent(
key: new Key('rebuild test'), // this is so we don't get the state from the TestComponentConfig in the last test, but instead instantiate a new element with a new state. key: new Key('rebuild test'), // this is so we don't get the state from the TestComponentConfig in the last test, but instead instantiate a new element with a new state.
left: new TestBuildCounter(), left: new TestBuildCounter(),
...@@ -67,8 +67,9 @@ void main() { ...@@ -67,8 +67,9 @@ void main() {
flipStatefulComponent(tester); flipStatefulComponent(tester);
tester.pumpFrameWithoutChange(); tester.pump();
expect(TestBuildCounter.buildCount, equals(1)); expect(TestBuildCounter.buildCount, equals(1));
}); });
});
} }
...@@ -37,9 +37,7 @@ class OuterContainerState extends State<OuterContainer> { ...@@ -37,9 +37,7 @@ class OuterContainerState extends State<OuterContainer> {
void main() { void main() {
test('resync stateful widget', () { test('resync stateful widget', () {
testWidgets((WidgetTester tester) {
WidgetTester tester = new WidgetTester();
Key innerKey = new Key('inner'); Key innerKey = new Key('inner');
Key outerKey = new Key('outer'); Key outerKey = new Key('outer');
...@@ -48,7 +46,7 @@ void main() { ...@@ -48,7 +46,7 @@ void main() {
OuterContainer outer1 = new OuterContainer(key: outerKey, child: inner1); OuterContainer outer1 = new OuterContainer(key: outerKey, child: inner1);
OuterContainer outer2; OuterContainer outer2;
tester.pumpFrame(outer1); tester.pumpWidget(outer1);
StatefulComponentElement innerElement = tester.findElementByKey(innerKey); StatefulComponentElement innerElement = tester.findElementByKey(innerKey);
InnerComponentState innerElementState = innerElement.state; InnerComponentState innerElementState = innerElement.state;
...@@ -59,7 +57,7 @@ void main() { ...@@ -59,7 +57,7 @@ void main() {
inner2 = new InnerComponent(key: innerKey); inner2 = new InnerComponent(key: innerKey);
outer2 = new OuterContainer(key: outerKey, child: inner2); outer2 = new OuterContainer(key: outerKey, child: inner2);
tester.pumpFrame(outer2); tester.pumpWidget(outer2);
expect(tester.findElementByKey(innerKey), equals(innerElement)); expect(tester.findElementByKey(innerKey), equals(innerElement));
expect(innerElement.state, equals(innerElementState)); expect(innerElement.state, equals(innerElementState));
...@@ -71,11 +69,12 @@ void main() { ...@@ -71,11 +69,12 @@ void main() {
StatefulComponentElement outerElement = tester.findElementByKey(outerKey); StatefulComponentElement outerElement = tester.findElementByKey(outerKey);
expect(outerElement.state.config, equals(outer2)); expect(outerElement.state.config, equals(outer2));
outerElement.state.setState(() {}); outerElement.state.setState(() {});
tester.pumpFrameWithoutChange(0.0); tester.pump();
expect(tester.findElementByKey(innerKey), equals(innerElement)); expect(tester.findElementByKey(innerKey), equals(innerElement));
expect(innerElement.state, equals(innerElementState)); expect(innerElement.state, equals(innerElementState));
expect(innerElementState.config, equals(inner2)); expect(innerElementState.config, equals(inner2));
expect(innerElement.renderObject.attached, isTrue); expect(innerElement.renderObject.attached, isTrue);
}); });
});
} }
...@@ -37,9 +37,8 @@ class TestWidgetState extends State<TestWidget> { ...@@ -37,9 +37,8 @@ class TestWidgetState extends State<TestWidget> {
void main() { void main() {
test('no change', () { test('no change', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
tester.pumpWidget(
tester.pumpFrame(
new Container( new Container(
child: new Container( child: new Container(
child: new TestWidget( child: new TestWidget(
...@@ -55,7 +54,7 @@ void main() { ...@@ -55,7 +54,7 @@ void main() {
expect(state.persistentState, equals(1)); expect(state.persistentState, equals(1));
expect(state.updates, equals(0)); expect(state.updates, equals(0));
tester.pumpFrame( tester.pumpWidget(
new Container( new Container(
child: new Container( child: new Container(
child: new TestWidget( child: new TestWidget(
...@@ -69,14 +68,13 @@ void main() { ...@@ -69,14 +68,13 @@ void main() {
expect(state.persistentState, equals(1)); expect(state.persistentState, equals(1));
expect(state.updates, equals(1)); expect(state.updates, equals(1));
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
});
}); });
test('remove one', () { test('remove one', () {
testWidgets((WidgetTester tester) {
WidgetTester tester = new WidgetTester(); tester.pumpWidget(
tester.pumpFrame(
new Container( new Container(
child: new Container( child: new Container(
child: new TestWidget( child: new TestWidget(
...@@ -92,7 +90,7 @@ void main() { ...@@ -92,7 +90,7 @@ void main() {
expect(state.persistentState, equals(10)); expect(state.persistentState, equals(10));
expect(state.updates, equals(0)); expect(state.updates, equals(0));
tester.pumpFrame( tester.pumpWidget(
new Container( new Container(
child: new TestWidget( child: new TestWidget(
persistentState: 11, persistentState: 11,
...@@ -106,21 +104,20 @@ void main() { ...@@ -106,21 +104,20 @@ void main() {
expect(state.persistentState, equals(11)); expect(state.persistentState, equals(11));
expect(state.updates, equals(0)); expect(state.updates, equals(0));
tester.pumpFrame(new Container()); tester.pumpWidget(new Container());
});
}); });
test('swap instances around', () { test('swap instances around', () {
testWidgets((WidgetTester tester) {
WidgetTester tester = new WidgetTester();
Widget a = new TestWidget(persistentState: 0x61, syncedState: 0x41, child: new Text('apple')); Widget a = new TestWidget(persistentState: 0x61, syncedState: 0x41, child: new Text('apple'));
Widget b = new TestWidget(persistentState: 0x62, syncedState: 0x42, child: new Text('banana')); Widget b = new TestWidget(persistentState: 0x62, syncedState: 0x42, child: new Text('banana'));
tester.pumpFrame(new Column([])); tester.pumpWidget(new Column([]));
GlobalKey keyA = new GlobalKey(); GlobalKey keyA = new GlobalKey();
GlobalKey keyB = new GlobalKey(); GlobalKey keyB = new GlobalKey();
tester.pumpFrame( tester.pumpWidget(
new Column([ new Column([
new Container( new Container(
key: keyA, key: keyA,
...@@ -145,7 +142,7 @@ void main() { ...@@ -145,7 +142,7 @@ void main() {
expect(second.persistentState, equals(0x62)); expect(second.persistentState, equals(0x62));
expect(second.syncedState, equals(0x42)); expect(second.syncedState, equals(0x42));
tester.pumpFrame( tester.pumpWidget(
new Column([ new Column([
new Container( new Container(
key: keyA, key: keyA,
...@@ -172,7 +169,7 @@ void main() { ...@@ -172,7 +169,7 @@ void main() {
// now we swap the nodes over // now we swap the nodes over
// since they are both "old" nodes, they shouldn't sync with each other even though they look alike // since they are both "old" nodes, they shouldn't sync with each other even though they look alike
tester.pumpFrame( tester.pumpWidget(
new Column([ new Column([
new Container( new Container(
key: keyA, key: keyA,
...@@ -194,7 +191,6 @@ void main() { ...@@ -194,7 +191,6 @@ void main() {
expect(second.config, equals(a)); expect(second.config, equals(a));
expect(second.persistentState, equals(0x62)); expect(second.persistentState, equals(0x62));
expect(second.syncedState, equals(0x41)); expect(second.syncedState, equals(0x41));
}); });
});
} }
...@@ -5,10 +5,9 @@ import 'widget_tester.dart'; ...@@ -5,10 +5,9 @@ import 'widget_tester.dart';
void main() { void main() {
test('Transform origin', () { test('Transform origin', () {
WidgetTester tester = new WidgetTester(); testWidgets((WidgetTester tester) {
bool didReceiveTap = false; bool didReceiveTap = false;
tester.pumpFrame( tester.pumpWidget(
new Stack([ new Stack([
new Positioned( new Positioned(
top: 100.0, top: 100.0,
...@@ -48,4 +47,5 @@ void main() { ...@@ -48,4 +47,5 @@ void main() {
tester.tapAt(new Point(190.0, 150.0)); tester.tapAt(new Point(190.0, 150.0));
expect(didReceiveTap, isTrue); expect(didReceiveTap, isTrue);
}); });
});
} }
...@@ -3,6 +3,8 @@ import 'dart:sky' as sky; ...@@ -3,6 +3,8 @@ import 'dart:sky' as sky;
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:quiver/testing/async.dart';
import 'package:quiver/time.dart';
import '../engine/mock_events.dart'; import '../engine/mock_events.dart';
...@@ -24,21 +26,24 @@ class RootComponentState extends State<RootComponent> { ...@@ -24,21 +26,24 @@ class RootComponentState extends State<RootComponent> {
} }
class WidgetTester { class WidgetTester {
WidgetTester._(FakeAsync async)
: async = async,
clock = async.getClock(new DateTime.utc(2015, 1, 1)) {
}
// See thttps://github.com/flutter/engine/issues/1084 regarding frameTimeMs vs FakeAsync final FakeAsync async;
final Clock clock;
void pumpFrame(Widget widget, [ double frameTimeMs = 0.0 ]) { void pumpWidget(Widget widget, [ Duration duration ]) {
runApp(widget); runApp(widget);
scheduler.beginFrame(frameTimeMs); pump(duration);
}
void pumpFrameWithoutChange([ double frameTimeMs = 0.0 ]) {
scheduler.beginFrame(frameTimeMs);
} }
void reset() { void pump([ Duration duration ]) {
runApp(new Container()); if (duration != null)
scheduler.beginFrame(0.0); async.elapse(duration);
scheduler.beginFrame(clock.now().millisecondsSinceEpoch.toDouble());
async.flushMicrotasks();
} }
List<Layer> _layers(Layer layer) { List<Layer> _layers(Layer layer) {
...@@ -162,3 +167,9 @@ class WidgetTester { ...@@ -162,3 +167,9 @@ class WidgetTester {
} }
} }
void testWidgets(callback(WidgetTester tester)) {
new FakeAsync().run((FakeAsync async) {
callback(new WidgetTester._(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