diff --git a/sky/unit/test/widget/align_test.dart b/sky/unit/test/widget/align_test.dart index 2706c14d03a..40f617b837d 100644 --- a/sky/unit/test/widget/align_test.dart +++ b/sky/unit/test/widget/align_test.dart @@ -5,23 +5,22 @@ import 'widget_tester.dart'; void main() { test('Align smoke test', () { - WidgetTester tester = new WidgetTester(); - - tester.pumpFrame( - new Align( - child: new Container(), - horizontal: 0.75, - vertical: 0.75 - ) - ); - - tester.pumpFrame( - new Align( - child: new Container(), - horizontal: 0.5, - vertical: 0.5 - ) - ); + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Align( + child: new Container(), + horizontal: 0.75, + vertical: 0.75 + ) + ); + tester.pumpWidget( + new Align( + child: new Container(), + horizontal: 0.5, + vertical: 0.5 + ) + ); + }); }); } diff --git a/sky/unit/test/widget/block_test.dart b/sky/unit/test/widget/block_test.dart index fef6d818e44..1f3c9eb3ed8 100644 --- a/sky/unit/test/widget/block_test.dart +++ b/sky/unit/test/widget/block_test.dart @@ -8,56 +8,56 @@ final Key blockKey = new Key('test'); void main() { test('Cannot scroll a non-overflowing block', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Block([ + new Container( + height: 200.0, // less than 600, the height of the test area + child: new Text('Hello') + ) + ], + key: blockKey) + ); + tester.pump(); // for SizeObservers - tester.pumpFrame( - new Block([ - new Container( - height: 200.0, // less than 600, the height of the test area - child: new Text('Hello') - ) - ], - key: blockKey) - ); - tester.pumpFrameWithoutChange(); // for SizeObservers + Point middleOfContainer = tester.getCenter(tester.findText('Hello')); + Point target = tester.getCenter(tester.findElementByKey(blockKey)); + TestPointer pointer = new TestPointer(); + tester.dispatchEvent(pointer.down(target), target); + tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); - Point middleOfContainer = tester.getCenter(tester.findText('Hello')); - Point target = tester.getCenter(tester.findElementByKey(blockKey)); - TestPointer pointer = new TestPointer(); - tester.dispatchEvent(pointer.down(target), target); - tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); + tester.pump(const Duration(milliseconds: 1)); - tester.pumpFrameWithoutChange(1.0); + 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', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Block([ + new Container( + height: 2000.0, // more than 600, the height of the test area + child: new Text('Hello') + ) + ], + key: blockKey) + ); + tester.pump(); // for SizeObservers - tester.pumpFrame( - new Block([ - new Container( - height: 2000.0, // more than 600, the height of the test area - child: new Text('Hello') - ) - ], - key: blockKey) - ); - tester.pumpFrameWithoutChange(); // for SizeObservers + Point middleOfContainer = tester.getCenter(tester.findText('Hello')); + Point target = tester.getCenter(tester.findElementByKey(blockKey)); + TestPointer pointer = new TestPointer(); + tester.dispatchEvent(pointer.down(target), target); + tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); - Point middleOfContainer = tester.getCenter(tester.findText('Hello')); - Point target = tester.getCenter(tester.findElementByKey(blockKey)); - TestPointer pointer = new TestPointer(); - tester.dispatchEvent(pointer.down(target), target); - tester.dispatchEvent(pointer.move(target + const Offset(0.0, -10.0)), target); + tester.pump(const Duration(milliseconds: 1)); - tester.pumpFrameWithoutChange(1.0); + 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); + }); }); } diff --git a/sky/unit/test/widget/box_decoration_test.dart b/sky/unit/test/widget/box_decoration_test.dart index 7ad8b3ef2c8..5c162430647 100644 --- a/sky/unit/test/widget/box_decoration_test.dart +++ b/sky/unit/test/widget/box_decoration_test.dart @@ -6,18 +6,17 @@ import 'widget_tester.dart'; void main() { test('Circles can have uniform borders', () { - WidgetTester tester = new WidgetTester(); - - tester.pumpFrame( - new Container( - padding: new EdgeDims.all(50.0), - decoration: new BoxDecoration( - shape: Shape.circle, - border: new Border.all(width: 10.0, color: const Color(0x80FF00FF)), - backgroundColor: Colors.teal[600] + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Container( + padding: new EdgeDims.all(50.0), + decoration: new BoxDecoration( + shape: Shape.circle, + border: new Border.all(width: 10.0, color: const Color(0x80FF00FF)), + backgroundColor: Colors.teal[600] + ) ) - ) - ); - + ); + }); }); } diff --git a/sky/unit/test/widget/build_scope_test.dart b/sky/unit/test/widget/build_scope_test.dart index 63e55ceb7ab..927c1e46a9a 100644 --- a/sky/unit/test/widget/build_scope_test.dart +++ b/sky/unit/test/widget/build_scope_test.dart @@ -80,47 +80,47 @@ void main() { }); test('Legal times for setState', () { - WidgetTester tester = new WidgetTester(); - - GlobalKey flipKey = new GlobalKey(); - expect(ProbeWidgetState.buildCount, equals(0)); - tester.pumpFrame(new ProbeWidget()); - expect(ProbeWidgetState.buildCount, equals(1)); - tester.pumpFrame(new ProbeWidget()); - expect(ProbeWidgetState.buildCount, equals(2)); - tester.pumpFrame(new FlipComponent( - key: flipKey, - left: new Container(), - right: new ProbeWidget() - )); - expect(ProbeWidgetState.buildCount, equals(2)); - (flipKey.currentState as FlipComponentState).flip(); - tester.pumpFrameWithoutChange(); - expect(ProbeWidgetState.buildCount, equals(3)); - (flipKey.currentState as FlipComponentState).flip(); - tester.pumpFrameWithoutChange(); - expect(ProbeWidgetState.buildCount, equals(3)); - tester.pumpFrame(new Container()); - expect(ProbeWidgetState.buildCount, equals(3)); + testWidgets((WidgetTester tester) { + GlobalKey flipKey = new GlobalKey(); + expect(ProbeWidgetState.buildCount, equals(0)); + tester.pumpWidget(new ProbeWidget()); + expect(ProbeWidgetState.buildCount, equals(1)); + tester.pumpWidget(new ProbeWidget()); + expect(ProbeWidgetState.buildCount, equals(2)); + tester.pumpWidget(new FlipComponent( + key: flipKey, + left: new Container(), + right: new ProbeWidget() + )); + expect(ProbeWidgetState.buildCount, equals(2)); + (flipKey.currentState as FlipComponentState).flip(); + tester.pump(); + expect(ProbeWidgetState.buildCount, equals(3)); + (flipKey.currentState as FlipComponentState).flip(); + tester.pump(); + expect(ProbeWidgetState.buildCount, equals(3)); + tester.pumpWidget(new Container()); + expect(ProbeWidgetState.buildCount, equals(3)); + }); }); test('Setting parent state during build is forbidden', () { - WidgetTester tester = new WidgetTester(); - - expect(cachedException, isNull); - tester.pumpFrame(new BadWidgetParent()); - expect(cachedException, isNotNull); - cachedException = null; - tester.pumpFrame(new Container()); - expect(cachedException, isNull); + testWidgets((WidgetTester tester) { + expect(cachedException, isNull); + tester.pumpWidget(new BadWidgetParent()); + expect(cachedException, isNotNull); + cachedException = null; + tester.pumpWidget(new Container()); + expect(cachedException, isNull); + }); }); test('Setting state during dispose is forbidden', () { - WidgetTester tester = new WidgetTester(); - - tester.pumpFrame(new BadDisposeWidget()); - expect(() { - tester.pumpFrame(new Container()); - }, throws); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new BadDisposeWidget()); + expect(() { + tester.pumpWidget(new Container()); + }, throws); + }); }); } diff --git a/sky/unit/test/widget/center_test.dart b/sky/unit/test/widget/center_test.dart index c2b6f2cabe6..a8d74b806d9 100644 --- a/sky/unit/test/widget/center_test.dart +++ b/sky/unit/test/widget/center_test.dart @@ -5,9 +5,8 @@ import 'widget_tester.dart'; void main() { test('Can be placed in an infinte box', () { - WidgetTester tester = new WidgetTester(); - - tester.pumpFrame(new Block([new Center()])); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Block([new Center()])); + }); }); - } diff --git a/sky/unit/test/widget/coordinates_test.dart b/sky/unit/test/widget/coordinates_test.dart index 972356ecf20..460d2e45a6c 100644 --- a/sky/unit/test/widget/coordinates_test.dart +++ b/sky/unit/test/widget/coordinates_test.dart @@ -6,41 +6,41 @@ import 'widget_tester.dart'; void main() { test('Comparing coordinates', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + Key keyA = new GlobalKey(); + Key keyB = new GlobalKey(); - Key keyA = new GlobalKey(); - Key keyB = new GlobalKey(); + tester.pumpWidget( + new Stack([ + new Positioned( + top: 100.0, + left: 100.0, + child: new SizedBox( + key: keyA, + width: 10.0, + height: 10.0 + ) + ), + new Positioned( + left: 100.0, + top: 200.0, + child: new SizedBox( + key: keyB, + width: 20.0, + height: 10.0 + ) + ), + ]) + ); - tester.pumpFrame( - new Stack([ - new Positioned( - top: 100.0, - left: 100.0, - child: new SizedBox( - key: keyA, - width: 10.0, - height: 10.0 - ) - ), - new Positioned( - left: 100.0, - top: 200.0, - child: new SizedBox( - key: keyB, - width: 20.0, - height: 10.0 - ) - ), - ]) - ); + expect((tester.findElementByKey(keyA).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)), + equals(const Point(100.0, 100.0))); - expect((tester.findElementByKey(keyA).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)), - equals(const Point(100.0, 100.0))); + expect((tester.findElementByKey(keyB).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)), + equals(const Point(100.0, 200.0))); - expect((tester.findElementByKey(keyB).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)), - equals(const Point(100.0, 200.0))); - - expect((tester.findElementByKey(keyB).renderObject as RenderBox).globalToLocal(const Point(110.0, 205.0)), - equals(const Point(10.0, 5.0))); + expect((tester.findElementByKey(keyB).renderObject as RenderBox).globalToLocal(const Point(110.0, 205.0)), + equals(const Point(10.0, 5.0))); + }); }); } diff --git a/sky/unit/test/widget/date_picker_test.dart b/sky/unit/test/widget/date_picker_test.dart index c0281e8a097..e3892137f8c 100644 --- a/sky/unit/test/widget/date_picker_test.dart +++ b/sky/unit/test/widget/date_picker_test.dart @@ -5,30 +5,30 @@ import 'widget_tester.dart'; void main() { test('Can select a day', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + DateTime currentValue; - DateTime currentValue; + Widget widget = new Block([ + new DatePicker( + selectedDate: new DateTime.utc(2015, 6, 9, 7, 12), + firstDate: new DateTime.utc(2013), + lastDate: new DateTime.utc(2018), + onChanged: (DateTime dateTime) { + currentValue = dateTime; + } + ) + ]); - Widget widget = new Block([ - new DatePicker( - selectedDate: new DateTime.utc(2015, 6, 9, 7, 12), - firstDate: new DateTime.utc(2013), - lastDate: new DateTime.utc(2018), - onChanged: (DateTime dateTime) { - currentValue = dateTime; - } - ) - ]); + tester.pumpWidget(widget); - tester.pumpFrame(widget); - - expect(currentValue, isNull); - tester.tap(tester.findText('2015')); - tester.pumpFrame(widget); - tester.tap(tester.findText('2014')); - tester.pumpFrame(widget); - expect(currentValue, equals(new DateTime(2014, 6, 9))); - tester.tap(tester.findText('30')); - expect(currentValue, equals(new DateTime(2013, 1, 30))); + expect(currentValue, isNull); + tester.tap(tester.findText('2015')); + tester.pumpWidget(widget); + tester.tap(tester.findText('2014')); + tester.pumpWidget(widget); + expect(currentValue, equals(new DateTime(2014, 6, 9))); + tester.tap(tester.findText('30')); + expect(currentValue, equals(new DateTime(2013, 1, 30))); + }); }); } diff --git a/sky/unit/test/widget/dismissable_test.dart b/sky/unit/test/widget/dismissable_test.dart index bcf11e92c12..8d436dd1d20 100644 --- a/sky/unit/test/widget/dismissable_test.dart +++ b/sky/unit/test/widget/dismissable_test.dart @@ -1,4 +1,3 @@ -import 'package:quiver/testing/async.dart'; import 'package:sky/widgets.dart'; import 'package:test/test.dart'; @@ -86,147 +85,149 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect tester.dispatchEvent(pointer.move(upLocation), downLocation); tester.dispatchEvent(pointer.up(), downLocation); - double t0 = 0.0; - new FakeAsync().run((async) { - tester.pumpFrame(widgetBuilder(), t0); // start the resize animation - 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)); - }); + tester.pumpWidget(widgetBuilder()); // start the resize animation + tester.pumpWidget(widgetBuilder(), const Duration(seconds: 1)); // finish the resize animation + tester.pumpWidget(widgetBuilder(), const Duration(seconds: 1)); // dismiss } void main() { test('Horizontal drag triggers dismiss scrollDirection=vertical', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.vertical; - dismissDirection = DismissDirection.horizontal; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.vertical; + dismissDirection = DismissDirection.horizontal; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.right); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.right); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); - dismissItem(tester, 1, gestureDirection: DismissDirection.left); - expect(tester.findText('1'), isNull); - expect(dismissedItems, equals([0, 1])); + dismissItem(tester, 1, gestureDirection: DismissDirection.left); + expect(tester.findText('1'), isNull); + expect(dismissedItems, equals([0, 1])); + }); }); test('Vertical drag triggers dismiss scrollDirection=horizontal', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.horizontal; - dismissDirection = DismissDirection.vertical; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.horizontal; + dismissDirection = DismissDirection.vertical; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.up); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.up); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); - dismissItem(tester, 1, gestureDirection: DismissDirection.down); - expect(tester.findText('1'), isNull); - expect(dismissedItems, equals([0, 1])); + dismissItem(tester, 1, gestureDirection: DismissDirection.down); + expect(tester.findText('1'), isNull); + expect(dismissedItems, equals([0, 1])); + }); }); test('drag-left with DismissDirection.left triggers dismiss', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.vertical; - dismissDirection = DismissDirection.left; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.vertical; + dismissDirection = DismissDirection.left; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.right); - expect(tester.findText('0'), isNotNull); - expect(dismissedItems, isEmpty); + dismissItem(tester, 0, gestureDirection: DismissDirection.right); + expect(tester.findText('0'), isNotNull); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.left); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.left); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); + }); }); test('drag-right with DismissDirection.right triggers dismiss', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.vertical; - dismissDirection = DismissDirection.right; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.vertical; + dismissDirection = DismissDirection.right; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.left); - expect(tester.findText('0'), isNotNull); - expect(dismissedItems, isEmpty); + dismissItem(tester, 0, gestureDirection: DismissDirection.left); + expect(tester.findText('0'), isNotNull); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.right); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.right); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); + }); }); test('drag-up with DismissDirection.up triggers dismiss', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.horizontal; - dismissDirection = DismissDirection.up; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.horizontal; + dismissDirection = DismissDirection.up; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.down); - expect(tester.findText('0'), isNotNull); - expect(dismissedItems, isEmpty); + dismissItem(tester, 0, gestureDirection: DismissDirection.down); + expect(tester.findText('0'), isNotNull); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.up); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.up); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); + }); }); test('drag-down with DismissDirection.down triggers dismiss', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.horizontal; - dismissDirection = DismissDirection.down; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.horizontal; + dismissDirection = DismissDirection.down; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - expect(dismissedItems, isEmpty); + tester.pumpWidget(widgetBuilder()); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.up); - expect(tester.findText('0'), isNotNull); - expect(dismissedItems, isEmpty); + dismissItem(tester, 0, gestureDirection: DismissDirection.up); + expect(tester.findText('0'), isNotNull); + expect(dismissedItems, isEmpty); - dismissItem(tester, 0, gestureDirection: DismissDirection.down); - expect(tester.findText('0'), isNull); - expect(dismissedItems, equals([0])); + dismissItem(tester, 0, gestureDirection: DismissDirection.down); + expect(tester.findText('0'), isNull); + expect(dismissedItems, equals([0])); + }); }); // This is a regression test for // https://github.com/domokit/sky_engine/issues/1068 test('Verify that drag-move events do not assert', () { - WidgetTester tester = new WidgetTester(); - scrollDirection = ScrollDirection.horizontal; - dismissDirection = DismissDirection.down; - dismissedItems = []; + testWidgets((WidgetTester tester) { + scrollDirection = ScrollDirection.horizontal; + dismissDirection = DismissDirection.down; + dismissedItems = []; - tester.pumpFrame(widgetBuilder()); - Element itemElement = tester.findText('0'); + tester.pumpWidget(widgetBuilder()); + Element itemElement = tester.findText('0'); - TestPointer pointer = new TestPointer(5); - Point location = tester.getTopLeft(itemElement); - Offset offset = new Offset(0.0, 5.0); - tester.dispatchEvent(pointer.down(location), location); - tester.dispatchEvent(pointer.move(location + offset), location); - tester.pumpFrame(widgetBuilder()); - tester.dispatchEvent(pointer.move(location + (offset * 2.0)), location); - tester.pumpFrame(widgetBuilder()); - tester.dispatchEvent(pointer.move(location + (offset * 3.0)), location); - tester.pumpFrame(widgetBuilder()); - tester.dispatchEvent(pointer.move(location + (offset * 4.0)), location); - tester.pumpFrame(widgetBuilder()); + TestPointer pointer = new TestPointer(5); + Point location = tester.getTopLeft(itemElement); + Offset offset = new Offset(0.0, 5.0); + tester.dispatchEvent(pointer.down(location), location); + tester.dispatchEvent(pointer.move(location + offset), location); + tester.pumpWidget(widgetBuilder()); + tester.dispatchEvent(pointer.move(location + (offset * 2.0)), location); + tester.pumpWidget(widgetBuilder()); + tester.dispatchEvent(pointer.move(location + (offset * 3.0)), location); + tester.pumpWidget(widgetBuilder()); + tester.dispatchEvent(pointer.move(location + (offset * 4.0)), location); + tester.pumpWidget(widgetBuilder()); + }); }); } diff --git a/sky/unit/test/widget/draggable_test.dart b/sky/unit/test/widget/draggable_test.dart index 6c92ab92778..31120bc3764 100644 --- a/sky/unit/test/widget/draggable_test.dart +++ b/sky/unit/test/widget/draggable_test.dart @@ -6,66 +6,66 @@ import 'widget_tester.dart'; void main() { test('Drag and drop - control test', () { - WidgetTester tester = new WidgetTester(); - TestPointer pointer = new TestPointer(7); + testWidgets((WidgetTester tester) { + TestPointer pointer = new TestPointer(7); - List accepted = []; + List accepted = []; - tester.pumpFrame(new Navigator( - routes: { - '/': (NavigatorState navigator, Route route) { return new Column([ - new Draggable( - navigator: navigator, - data: 1, - child: new Text('Source'), - feedback: new Text('Dragging') - ), - new DragTarget( - builder: (context, data, rejects) { - return new Container( - height: 100.0, - child: new Text('Target') - ); - }, - onAccept: (data) { - accepted.add(data); - } - ), - ]); - }, - } - )); + tester.pumpWidget(new Navigator( + routes: { + '/': (NavigatorState navigator, Route route) { return new Column([ + new Draggable( + navigator: navigator, + data: 1, + child: new Text('Source'), + feedback: new Text('Dragging') + ), + new DragTarget( + builder: (context, data, rejects) { + return new Container( + height: 100.0, + child: new Text('Target') + ); + }, + onAccept: (data) { + accepted.add(data); + } + ), + ]); + }, + } + )); - expect(accepted, isEmpty); - expect(tester.findText('Source'), isNotNull); - expect(tester.findText('Dragging'), isNull); - expect(tester.findText('Target'), isNotNull); + expect(accepted, isEmpty); + expect(tester.findText('Source'), isNotNull); + expect(tester.findText('Dragging'), isNull); + expect(tester.findText('Target'), isNotNull); - Point firstLocation = tester.getCenter(tester.findText('Source')); - tester.dispatchEvent(pointer.down(firstLocation), firstLocation); - tester.pumpFrameWithoutChange(); + Point firstLocation = tester.getCenter(tester.findText('Source')); + tester.dispatchEvent(pointer.down(firstLocation), firstLocation); + tester.pump(); - expect(accepted, isEmpty); - expect(tester.findText('Source'), isNotNull); - expect(tester.findText('Dragging'), isNotNull); - expect(tester.findText('Target'), isNotNull); + expect(accepted, isEmpty); + expect(tester.findText('Source'), isNotNull); + expect(tester.findText('Dragging'), isNotNull); + expect(tester.findText('Target'), isNotNull); - Point secondLocation = tester.getCenter(tester.findText('Target')); - tester.dispatchEvent(pointer.move(secondLocation), firstLocation); - tester.pumpFrameWithoutChange(); + Point secondLocation = tester.getCenter(tester.findText('Target')); + tester.dispatchEvent(pointer.move(secondLocation), firstLocation); + tester.pump(); - expect(accepted, isEmpty); - expect(tester.findText('Source'), isNotNull); - expect(tester.findText('Dragging'), isNotNull); - expect(tester.findText('Target'), isNotNull); + expect(accepted, isEmpty); + expect(tester.findText('Source'), isNotNull); + expect(tester.findText('Dragging'), isNotNull); + expect(tester.findText('Target'), isNotNull); - tester.dispatchEvent(pointer.up(), firstLocation); - tester.pumpFrameWithoutChange(); + tester.dispatchEvent(pointer.up(), firstLocation); + tester.pump(); - expect(accepted, equals([1])); - expect(tester.findText('Source'), isNotNull); - expect(tester.findText('Dragging'), isNull); - expect(tester.findText('Target'), isNotNull); - + expect(accepted, equals([1])); + expect(tester.findText('Source'), isNotNull); + expect(tester.findText('Dragging'), isNull); + expect(tester.findText('Target'), isNotNull); + }); }); } diff --git a/sky/unit/test/widget/duplicate_key_test.dart b/sky/unit/test/widget/duplicate_key_test.dart index b0d497f3432..39ce16ed821 100644 --- a/sky/unit/test/widget/duplicate_key_test.dart +++ b/sky/unit/test/widget/duplicate_key_test.dart @@ -42,14 +42,15 @@ Widget builder() { void main() { test('duplicate key smoke test', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(builder()); - StatefulLeafState leaf = tester.findStateOfType(StatefulLeafState); - leaf.test(); - tester.pumpFrameWithoutChange(); - Item lastItem = items[1]; - items.remove(lastItem); - items.insert(0, lastItem); - tester.pumpFrame(builder()); // this marks the app dirty and rebuilds it + testWidgets((WidgetTester tester) { + tester.pumpWidget(builder()); + StatefulLeafState leaf = tester.findStateOfType(StatefulLeafState); + leaf.test(); + tester.pump(); + Item lastItem = items[1]; + items.remove(lastItem); + items.insert(0, lastItem); + tester.pumpWidget(builder()); // this marks the app dirty and rebuilds it + }); }); } diff --git a/sky/unit/test/widget/flex_test.dart b/sky/unit/test/widget/flex_test.dart index ea4a0335fb7..2b6044ce579 100644 --- a/sky/unit/test/widget/flex_test.dart +++ b/sky/unit/test/widget/flex_test.dart @@ -5,41 +5,41 @@ import 'widget_tester.dart'; void main() { test('Can hit test flex children of stacks', () { - WidgetTester tester = new WidgetTester(); - - bool didReceiveTap = false; - tester.pumpFrame( - new Container( - decoration: const BoxDecoration( - backgroundColor: const Color(0xFF00FF00) - ), - child: new Stack([ - new Positioned( - top: 10.0, - left: 10.0, - child: new Column([ - new GestureDetector( - onTap: () { - didReceiveTap = true; - }, - child: new Container( - decoration: const BoxDecoration( - backgroundColor: const Color(0xFF0000FF) - ), - width: 100.0, - height: 100.0, - child: new Center( - child: new Text('X') + testWidgets((WidgetTester tester) { + bool didReceiveTap = false; + tester.pumpWidget( + new Container( + decoration: const BoxDecoration( + backgroundColor: const Color(0xFF00FF00) + ), + child: new Stack([ + new Positioned( + top: 10.0, + left: 10.0, + child: new Column([ + new GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: new Container( + decoration: const BoxDecoration( + backgroundColor: const Color(0xFF0000FF) + ), + width: 100.0, + height: 100.0, + child: new Center( + child: new Text('X') + ) ) ) - ) - ]) - ) - ]) - ) - ); + ]) + ) + ]) + ) + ); - tester.tap(tester.findText('X')); - expect(didReceiveTap, isTrue); + tester.tap(tester.findText('X')); + expect(didReceiveTap, isTrue); + }); }); } diff --git a/sky/unit/test/widget/gesture_detector_test.dart b/sky/unit/test/widget/gesture_detector_test.dart index 93d0c643c64..26d45ecc08a 100644 --- a/sky/unit/test/widget/gesture_detector_test.dart +++ b/sky/unit/test/widget/gesture_detector_test.dart @@ -6,84 +6,86 @@ import 'widget_tester.dart'; void main() { test('Uncontested scrolls start immediately', () { - WidgetTester tester = new WidgetTester(); - TestPointer pointer = new TestPointer(7); + testWidgets((WidgetTester tester) { + TestPointer pointer = new TestPointer(7); - bool didStartDrag = false; - double updatedDragDelta; - bool didEndDrag = false; + bool didStartDrag = false; + double updatedDragDelta; + bool didEndDrag = false; - Widget widget = new GestureDetector( - onVerticalDragStart: () { - didStartDrag = true; - }, - onVerticalDragUpdate: (double scrollDelta) { - updatedDragDelta = scrollDelta; - }, - onVerticalDragEnd: (Offset velocity) { - didEndDrag = true; - }, - child: new Container() - ); + Widget widget = new GestureDetector( + onVerticalDragStart: () { + didStartDrag = true; + }, + onVerticalDragUpdate: (double scrollDelta) { + updatedDragDelta = scrollDelta; + }, + onVerticalDragEnd: (Offset velocity) { + didEndDrag = true; + }, + child: new Container() + ); - tester.pumpFrame(widget); - expect(didStartDrag, isFalse); - expect(updatedDragDelta, isNull); - expect(didEndDrag, isFalse); + tester.pumpWidget(widget); + expect(didStartDrag, isFalse); + expect(updatedDragDelta, isNull); + expect(didEndDrag, isFalse); - Point firstLocation = new Point(10.0, 10.0); - tester.dispatchEvent(pointer.down(firstLocation), firstLocation); - expect(didStartDrag, isTrue); - didStartDrag = false; - expect(updatedDragDelta, isNull); - expect(didEndDrag, isFalse); + Point firstLocation = new Point(10.0, 10.0); + tester.dispatchEvent(pointer.down(firstLocation), firstLocation); + expect(didStartDrag, isTrue); + didStartDrag = false; + expect(updatedDragDelta, isNull); + expect(didEndDrag, isFalse); - Point secondLocation = new Point(10.0, 9.0); - tester.dispatchEvent(pointer.move(secondLocation), firstLocation); - expect(didStartDrag, isFalse); - expect(updatedDragDelta, -1.0); - updatedDragDelta = null; - expect(didEndDrag, isFalse); + Point secondLocation = new Point(10.0, 9.0); + tester.dispatchEvent(pointer.move(secondLocation), firstLocation); + expect(didStartDrag, isFalse); + expect(updatedDragDelta, -1.0); + updatedDragDelta = null; + expect(didEndDrag, isFalse); - tester.dispatchEvent(pointer.up(), firstLocation); - expect(didStartDrag, isFalse); - expect(updatedDragDelta, isNull); - expect(didEndDrag, isTrue); - didEndDrag = false; + tester.dispatchEvent(pointer.up(), firstLocation); + expect(didStartDrag, isFalse); + expect(updatedDragDelta, isNull); + expect(didEndDrag, isTrue); + didEndDrag = false; - tester.pumpFrame(new Container()); + tester.pumpWidget(new Container()); + }); }); test('Match two scroll gestures in succession', () { - WidgetTester tester = new WidgetTester(); - TestPointer pointer = new TestPointer(7); + testWidgets((WidgetTester tester) { + TestPointer pointer = new TestPointer(7); - int gestureCount = 0; - double dragDistance = 0.0; + int gestureCount = 0; + double dragDistance = 0.0; - Point downLocation = new Point(10.0, 10.0); - Point upLocation = new Point(10.0, 20.0); + Point downLocation = new Point(10.0, 10.0); + Point upLocation = new Point(10.0, 20.0); - Widget widget = new GestureDetector( - onVerticalDragUpdate: (double delta) { dragDistance += delta; }, - onVerticalDragEnd: (Offset velocity) { gestureCount += 1; }, - onHorizontalDragUpdate: (_) { fail("gesture should not match"); }, - onHorizontalDragEnd: (Offset velocity) { fail("gesture should not match"); }, - child: new Container() - ); - tester.pumpFrame(widget); + Widget widget = new GestureDetector( + onVerticalDragUpdate: (double delta) { dragDistance += delta; }, + onVerticalDragEnd: (Offset velocity) { gestureCount += 1; }, + onHorizontalDragUpdate: (_) { fail("gesture should not match"); }, + onHorizontalDragEnd: (Offset velocity) { fail("gesture should not match"); }, + child: new Container() + ); + tester.pumpWidget(widget); - tester.dispatchEvent(pointer.down(downLocation), downLocation); - tester.dispatchEvent(pointer.move(upLocation), downLocation); - tester.dispatchEvent(pointer.up(), downLocation); + tester.dispatchEvent(pointer.down(downLocation), downLocation); + tester.dispatchEvent(pointer.move(upLocation), downLocation); + tester.dispatchEvent(pointer.up(), downLocation); - tester.dispatchEvent(pointer.down(downLocation), downLocation); - tester.dispatchEvent(pointer.move(upLocation), downLocation); - tester.dispatchEvent(pointer.up(), downLocation); + tester.dispatchEvent(pointer.down(downLocation), downLocation); + tester.dispatchEvent(pointer.move(upLocation), downLocation); + tester.dispatchEvent(pointer.up(), downLocation); - expect(gestureCount, 2); - expect(dragDistance, 20.0); + expect(gestureCount, 2); + expect(dragDistance, 20.0); - tester.pumpFrame(new Container()); + tester.pumpWidget(new Container()); + }); }); } diff --git a/sky/unit/test/widget/homogeneous_viewport_test.dart b/sky/unit/test/widget/homogeneous_viewport_test.dart index 5e90ca84bf0..3b428182165 100644 --- a/sky/unit/test/widget/homogeneous_viewport_test.dart +++ b/sky/unit/test/widget/homogeneous_viewport_test.dart @@ -6,159 +6,159 @@ import 'test_widgets.dart'; void main() { test('HomogeneousViewport mount/dismount smoke test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 100 pixels tall, it should fit exactly 6 times. - // the root view is 800x600 in the test environment - // so if our widget is 100 pixels tall, it should fit exactly 6 times. + Widget builder() { + return new FlipComponent( + left: new HomogeneousViewport( + builder: (BuildContext context, int start, int count) { + List result = []; + for (int index = start; index < start + count; index += 1) { + callbackTracker.add(index); + result.add(new Container( + key: new ValueKey(index), + height: 100.0, + child: new Text("$index") + )); + } + return result; + }, + startOffset: 0.0, + itemExtent: 100.0 + ), + right: new Text('Not Today') + ); + } - Widget builder() { - return new FlipComponent( - left: new HomogeneousViewport( - builder: (BuildContext context, int start, int count) { - List result = []; - for (int index = start; index < start + count; index += 1) { - callbackTracker.add(index); - result.add(new Container( - key: new ValueKey(index), - height: 100.0, - child: new Text("$index") - )); - } - return result; - }, - startOffset: 0.0, - itemExtent: 100.0 - ), - right: new Text('Not Today') - ); - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); + FlipComponentState testComponent = element.state; - StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); - FlipComponentState testComponent = element.state; + expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); - expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + callbackTracker.clear(); + testComponent.flip(); + tester.pump(); - callbackTracker.clear(); - testComponent.flip(); - tester.pumpFrameWithoutChange(); + expect(callbackTracker, equals([])); - expect(callbackTracker, equals([])); + callbackTracker.clear(); + testComponent.flip(); + tester.pump(); - callbackTracker.clear(); - testComponent.flip(); - tester.pumpFrameWithoutChange(); - - expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + }); }); test('HomogeneousViewport vertical', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 200 pixels tall, it should fit exactly 3 times. + // but if we are offset by 300 pixels, there will be 4, numbered 1-4. - // the root view is 800x600 in the test environment - // so if our widget is 200 pixels tall, it should fit exactly 3 times. - // but if we are offset by 300 pixels, there will be 4, numbered 1-4. + double offset = 300.0; - double offset = 300.0; + ListBuilder itemBuilder = (BuildContext context, int start, int count) { + List result = []; + for (int index = start; index < start + count; index += 1) { + callbackTracker.add(index); + result.add(new Container( + key: new ValueKey(index), + width: 500.0, // this should be ignored + height: 400.0, // should be overridden by itemExtent + child: new Text("$index") + )); + } + return result; + }; - ListBuilder itemBuilder = (BuildContext context, int start, int count) { - List result = []; - for (int index = start; index < start + count; index += 1) { - callbackTracker.add(index); - result.add(new Container( - key: new ValueKey(index), - width: 500.0, // this should be ignored - height: 400.0, // should be overridden by itemExtent - child: new Text("$index") - )); + FlipComponent testComponent; + Widget builder() { + testComponent = new FlipComponent( + left: new HomogeneousViewport( + builder: itemBuilder, + startOffset: offset, + itemExtent: 200.0 + ), + right: new Text('Not Today') + ); + return testComponent; } - return result; - }; - FlipComponent testComponent; - Widget builder() { - testComponent = new FlipComponent( - left: new HomogeneousViewport( - builder: itemBuilder, - startOffset: offset, - itemExtent: 200.0 - ), - right: new Text('Not Today') - ); - return testComponent; - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + expect(callbackTracker, equals([1, 2, 3, 4])); - expect(callbackTracker, equals([1, 2, 3, 4])); + callbackTracker.clear(); - callbackTracker.clear(); + offset = 400.0; // now only 3 should fit, numbered 2-4. - offset = 400.0; // now only 3 should fit, numbered 2-4. + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + expect(callbackTracker, equals([2, 3, 4])); - expect(callbackTracker, equals([2, 3, 4])); - - callbackTracker.clear(); + callbackTracker.clear(); + }); }); test('HomogeneousViewport horizontal', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 200 pixels wide, it should fit exactly 4 times. + // but if we are offset by 300 pixels, there will be 5, numbered 1-5. - // the root view is 800x600 in the test environment - // so if our widget is 200 pixels wide, it should fit exactly 4 times. - // but if we are offset by 300 pixels, there will be 5, numbered 1-5. + double offset = 300.0; - double offset = 300.0; + ListBuilder itemBuilder = (BuildContext context, int start, int count) { + List result = []; + for (int index = start; index < start + count; index += 1) { + callbackTracker.add(index); + result.add(new Container( + key: new ValueKey(index), + width: 400.0, // this should be overridden by itemExtent + height: 500.0, // this should be ignored + child: new Text("$index") + )); + } + return result; + }; - ListBuilder itemBuilder = (BuildContext context, int start, int count) { - List result = []; - for (int index = start; index < start + count; index += 1) { - callbackTracker.add(index); - result.add(new Container( - key: new ValueKey(index), - width: 400.0, // this should be overridden by itemExtent - height: 500.0, // this should be ignored - child: new Text("$index") - )); + FlipComponent testComponent; + Widget builder() { + testComponent = new FlipComponent( + left: new HomogeneousViewport( + builder: itemBuilder, + startOffset: offset, + itemExtent: 200.0, + direction: ScrollDirection.horizontal + ), + right: new Text('Not Today') + ); + return testComponent; } - return result; - }; - FlipComponent testComponent; - Widget builder() { - testComponent = new FlipComponent( - left: new HomogeneousViewport( - builder: itemBuilder, - startOffset: offset, - itemExtent: 200.0, - direction: ScrollDirection.horizontal - ), - right: new Text('Not Today') - ); - return testComponent; - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + expect(callbackTracker, equals([1, 2, 3, 4, 5])); - expect(callbackTracker, equals([1, 2, 3, 4, 5])); + callbackTracker.clear(); - callbackTracker.clear(); + offset = 400.0; // now only 4 should fit, numbered 2-5. - offset = 400.0; // now only 4 should fit, numbered 2-5. + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + expect(callbackTracker, equals([2, 3, 4, 5])); - expect(callbackTracker, equals([2, 3, 4, 5])); - - callbackTracker.clear(); + callbackTracker.clear(); + }); }); } diff --git a/sky/unit/test/widget/input_test.dart b/sky/unit/test/widget/input_test.dart index ce8776f0b8e..01670d5ec06 100644 --- a/sky/unit/test/widget/input_test.dart +++ b/sky/unit/test/widget/input_test.dart @@ -1,5 +1,4 @@ import 'package:mojo_services/keyboard/keyboard.mojom.dart'; -import 'package:quiver/testing/async.dart'; import 'package:sky/rendering.dart'; import 'package:sky/services.dart'; import 'package:sky/widgets.dart'; @@ -25,65 +24,63 @@ void main() { serviceMocker.registerMockService(KeyboardServiceName, mockKeyboard); test('Editable text has consistent width', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + GlobalKey inputKey = new GlobalKey(); + String inputValue; - GlobalKey inputKey = new GlobalKey(); - String inputValue; + Widget builder() { + return new Center( + child: new Input( + key: inputKey, + placeholder: 'Placeholder', + onChanged: (value) { inputValue = value; } + ) + ); + } - Widget builder() { - return new Center( - child: new Input( - key: inputKey, - placeholder: 'Placeholder', - onChanged: (value) { inputValue = value; } - ) - ); - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + Element input = tester.findElementByKey(inputKey); + Size emptyInputSize = (input.renderObject as RenderBox).size; - Element input = tester.findElementByKey(inputKey); - Size emptyInputSize = (input.renderObject as RenderBox).size; + // Simulate entry of text through the keyboard. + expect(mockKeyboard.client, isNotNull); + const String testValue = 'Test'; + mockKeyboard.client.setComposingText(testValue, testValue.length); - // Simulate entry of text through the keyboard. - expect(mockKeyboard.client, isNotNull); - const String testValue = 'Test'; - mockKeyboard.client.setComposingText(testValue, testValue.length); + // Check that the onChanged event handler fired. + expect(inputValue, equals(testValue)); - // Check that the onChanged event handler fired. - expect(inputValue, equals(testValue)); + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); - - // Check that the Input with text has the same size as the empty Input. - expect((input.renderObject as RenderBox).size, equals(emptyInputSize)); + // Check that the Input with text has the same size as the empty Input. + expect((input.renderObject as RenderBox).size, equals(emptyInputSize)); + }); }); test('Cursor blinks', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + GlobalKey inputKey = new GlobalKey(); - GlobalKey inputKey = new GlobalKey(); + Widget builder() { + return new Center( + child: new Input( + key: inputKey, + placeholder: 'Placeholder' + ) + ); + } - Widget builder() { - return new Center( - child: new Input( - key: inputKey, - placeholder: 'Placeholder' - ) - ); - } - - new FakeAsync().run((async) { - tester.pumpFrame(builder()); + tester.pumpWidget(builder()); EditableTextState editableText = tester.findStateOfType(EditableTextState); // Check that the cursor visibility toggles after each blink interval. void checkCursorToggle() { bool initialShowCursor = editableText.test_showCursor; - async.elapse(editableText.test_cursorBlinkPeriod); + tester.async.elapse(editableText.test_cursorBlinkPeriod); expect(editableText.test_showCursor, equals(!initialShowCursor)); - async.elapse(editableText.test_cursorBlinkPeriod); + tester.async.elapse(editableText.test_cursorBlinkPeriod); expect(editableText.test_showCursor, equals(initialShowCursor)); } diff --git a/sky/unit/test/widget/listener_test.dart b/sky/unit/test/widget/listener_test.dart index c3e53916cc7..bdd7a8002ae 100644 --- a/sky/unit/test/widget/listener_test.dart +++ b/sky/unit/test/widget/listener_test.dart @@ -5,38 +5,38 @@ import 'widget_tester.dart'; void main() { test('Events bubble up the tree', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List log = new List(); - List log = new List(); - - tester.pumpFrame( - new Listener( - onPointerDown: (_) { - log.add('top'); - }, - child: new Listener( + tester.pumpWidget( + new Listener( onPointerDown: (_) { - log.add('middle'); + log.add('top'); }, - child: new DecoratedBox( - decoration: const BoxDecoration(), - child: new Listener( - onPointerDown: (_) { - log.add('bottom'); - }, - child: new Text('X') + child: new Listener( + onPointerDown: (_) { + log.add('middle'); + }, + child: new DecoratedBox( + decoration: const BoxDecoration(), + child: new Listener( + onPointerDown: (_) { + log.add('bottom'); + }, + child: new Text('X') + ) ) ) ) - ) - ); + ); - tester.tap(tester.findText('X')); + tester.tap(tester.findText('X')); - expect(log, equals([ - 'bottom', - 'middle', - 'top', - ])); + expect(log, equals([ + 'bottom', + 'middle', + 'top', + ])); + }); }); } diff --git a/sky/unit/test/widget/mixed_viewport_test.dart b/sky/unit/test/widget/mixed_viewport_test.dart index 29ced2b7860..b72562e8305 100644 --- a/sky/unit/test/widget/mixed_viewport_test.dart +++ b/sky/unit/test/widget/mixed_viewport_test.dart @@ -6,147 +6,144 @@ import 'test_widgets.dart'; void main() { test('MixedViewport mount/dismount smoke test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 100 pixels tall, it should fit exactly 6 times. - // the root view is 800x600 in the test environment - // so if our widget is 100 pixels tall, it should fit exactly 6 times. + Widget builder() { + return new FlipComponent( + left: new MixedViewport( + builder: (BuildContext context, int i) { + callbackTracker.add(i); + return new Container( + key: new ValueKey(i), + height: 100.0, + child: new Text("$i") + ); + }, + startOffset: 0.0 + ), + right: new Text('Not Today') + ); + } - Widget builder() { - return new FlipComponent( - left: new MixedViewport( - builder: (BuildContext context, int i) { - callbackTracker.add(i); - return new Container( - key: new ValueKey(i), - height: 100.0, - child: new Text("$i") - ); - }, - startOffset: 0.0 - ), - right: new Text('Not Today') - ); - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); + FlipComponentState testComponent = element.state; - StatefulComponentElement element = tester.findElement((element) => element.widget is FlipComponent); - FlipComponentState testComponent = element.state; + expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); - expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + callbackTracker.clear(); + testComponent.flip(); + tester.pump(); - callbackTracker.clear(); - testComponent.flip(); - tester.pumpFrameWithoutChange(); + expect(callbackTracker, equals([])); - expect(callbackTracker, equals([])); - - callbackTracker.clear(); - testComponent.flip(); - tester.pumpFrameWithoutChange(); - - expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + callbackTracker.clear(); + testComponent.flip(); + tester.pump(); + expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + }); }); test('MixedViewport vertical', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 200 pixels tall, it should fit exactly 3 times. + // but if we are offset by 300 pixels, there will be 4, numbered 1-4. - // the root view is 800x600 in the test environment - // so if our widget is 200 pixels tall, it should fit exactly 3 times. - // but if we are offset by 300 pixels, there will be 4, numbered 1-4. + double offset = 300.0; - double offset = 300.0; + IndexedBuilder itemBuilder = (BuildContext context, int i) { + callbackTracker.add(i); + return new Container( + key: new ValueKey(i), + width: 500.0, // this should be ignored + height: 200.0, + child: new Text("$i") + ); + }; - IndexedBuilder itemBuilder = (BuildContext context, int i) { - callbackTracker.add(i); - return new Container( - key: new ValueKey(i), - width: 500.0, // this should be ignored - height: 200.0, - child: new Text("$i") - ); - }; + Widget builder() { + return new FlipComponent( + left: new MixedViewport( + builder: itemBuilder, + startOffset: offset + ), + right: new Text('Not Today') + ); + } - Widget builder() { - return new FlipComponent( - left: new MixedViewport( - builder: itemBuilder, - startOffset: offset - ), - right: new Text('Not Today') - ); - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + // 0 is built to find its width + expect(callbackTracker, equals([0, 1, 2, 3, 4])); - // 0 is built to find its width - expect(callbackTracker, equals([0, 1, 2, 3, 4])); + callbackTracker.clear(); - callbackTracker.clear(); + offset = 400.0; // now only 3 should fit, numbered 2-4. - offset = 400.0; // now only 3 should fit, numbered 2-4. + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); - - // 0 and 1 aren't built, we know their size and nothing else changed - expect(callbackTracker, equals([2, 3, 4])); - - callbackTracker.clear(); + // 0 and 1 aren't built, we know their size and nothing else changed + expect(callbackTracker, equals([2, 3, 4])); + callbackTracker.clear(); + }); }); test('MixedViewport horizontal', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + List callbackTracker = []; - List callbackTracker = []; + // the root view is 800x600 in the test environment + // so if our widget is 200 pixels wide, it should fit exactly 4 times. + // but if we are offset by 300 pixels, there will be 5, numbered 1-5. - // the root view is 800x600 in the test environment - // so if our widget is 200 pixels wide, it should fit exactly 4 times. - // but if we are offset by 300 pixels, there will be 5, numbered 1-5. + double offset = 300.0; - double offset = 300.0; + IndexedBuilder itemBuilder = (BuildContext context, int i) { + callbackTracker.add(i); + return new Container( + key: new ValueKey(i), + height: 500.0, // this should be ignored + width: 200.0, + child: new Text("$i") + ); + }; - IndexedBuilder itemBuilder = (BuildContext context, int i) { - callbackTracker.add(i); - return new Container( - key: new ValueKey(i), - height: 500.0, // this should be ignored - width: 200.0, - child: new Text("$i") - ); - }; + Widget builder() { + return new FlipComponent( + left: new MixedViewport( + builder: itemBuilder, + startOffset: offset, + direction: ScrollDirection.horizontal + ), + right: new Text('Not Today') + ); + } - Widget builder() { - return new FlipComponent( - left: new MixedViewport( - builder: itemBuilder, - startOffset: offset, - direction: ScrollDirection.horizontal - ), - right: new Text('Not Today') - ); - } + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); + // 0 is built to find its width + expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); - // 0 is built to find its width - expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); + callbackTracker.clear(); - callbackTracker.clear(); + offset = 400.0; // now only 4 should fit, numbered 2-5. - offset = 400.0; // now only 4 should fit, numbered 2-5. + tester.pumpWidget(builder()); - tester.pumpFrame(builder()); - - // 0 and 1 aren't built, we know their size and nothing else changed - expect(callbackTracker, equals([2, 3, 4, 5])); - - callbackTracker.clear(); + // 0 and 1 aren't built, we know their size and nothing else changed + expect(callbackTracker, equals([2, 3, 4, 5])); + callbackTracker.clear(); + }); }); } diff --git a/sky/unit/test/widget/multichild_test.dart b/sky/unit/test/widget/multichild_test.dart index 6dfaef06953..0a87970e1b7 100644 --- a/sky/unit/test/widget/multichild_test.dart +++ b/sky/unit/test/widget/multichild_test.dart @@ -28,263 +28,265 @@ void checkTree(WidgetTester tester, List expectedDecorations) { void main() { test('MultiChildRenderObjectElement control test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new DecoratedBox(decoration: kBoxDecorationB), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new DecoratedBox(decoration: kBoxDecorationB), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), - new DecoratedBox(decoration: kBoxDecorationC), - new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), + new DecoratedBox(decoration: kBoxDecorationC), + new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA), + ]) + ); - checkTree(tester, [kBoxDecorationB, kBoxDecorationC, kBoxDecorationA]); + checkTree(tester, [kBoxDecorationB, kBoxDecorationC, kBoxDecorationA]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA), - new DecoratedBox(decoration: kBoxDecorationC), - new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(key: new Key('a'), decoration: kBoxDecorationA), + new DecoratedBox(decoration: kBoxDecorationC), + new DecoratedBox(key: new Key('b'), decoration: kBoxDecorationB), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationC, kBoxDecorationB]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationC, kBoxDecorationB]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationC]); + checkTree(tester, [kBoxDecorationC]); - tester.pumpFrame( - new Stack([]) - ); + tester.pumpWidget( + new Stack([]) + ); - checkTree(tester, []); + checkTree(tester, []); + + }); }); test('MultiChildRenderObjectElement with stateless components', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new DecoratedBox(decoration: kBoxDecorationB), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new DecoratedBox(decoration: kBoxDecorationB), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new Container( - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); - - checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); - - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new Container( - child: new Container( + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new Container( child: new DecoratedBox(decoration: kBoxDecorationB) - ) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new Container( - child: new Container( + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new Container( + child: new Container( + child: new DecoratedBox(decoration: kBoxDecorationB) + ) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); + + checkTree(tester, [kBoxDecorationA, kBoxDecorationB, kBoxDecorationC]); + + tester.pumpWidget( + new Stack([ + new Container( + child: new Container( + child: new DecoratedBox(decoration: kBoxDecorationB) + ) + ), + new Container( + child: new DecoratedBox(decoration: kBoxDecorationA) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); + + checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); + + tester.pumpWidget( + new Stack([ + new Container( child: new DecoratedBox(decoration: kBoxDecorationB) - ) - ), - new Container( - child: new DecoratedBox(decoration: kBoxDecorationA) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + ), + new Container( + child: new DecoratedBox(decoration: kBoxDecorationA) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); - tester.pumpFrame( - new Stack([ - new Container( - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - new Container( - child: new DecoratedBox(decoration: kBoxDecorationA) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new Container( + key: new Key('b'), + child: new DecoratedBox(decoration: kBoxDecorationB) + ), + new Container( + key: new Key('a'), + child: new DecoratedBox(decoration: kBoxDecorationA) + ), + ]) + ); - checkTree(tester, [kBoxDecorationB, kBoxDecorationA, kBoxDecorationC]); + checkTree(tester, [kBoxDecorationB, kBoxDecorationA]); - tester.pumpFrame( - new Stack([ - new Container( - key: new Key('b'), - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - new Container( - key: new Key('a'), - child: new DecoratedBox(decoration: kBoxDecorationA) - ), - ]) - ); + tester.pumpWidget( + new Stack([ + new Container( + key: new Key('a'), + child: new DecoratedBox(decoration: kBoxDecorationA) + ), + new Container( + key: new Key('b'), + child: new DecoratedBox(decoration: kBoxDecorationB) + ), + ]) + ); - checkTree(tester, [kBoxDecorationB, kBoxDecorationA]); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); - tester.pumpFrame( - new Stack([ - new Container( - key: new Key('a'), - child: new DecoratedBox(decoration: kBoxDecorationA) - ), - new Container( - key: new Key('b'), - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - ]) - ); + tester.pumpWidget( + new Stack([ ]) + ); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); - - tester.pumpFrame( - new Stack([ ]) - ); - - checkTree(tester, []); + checkTree(tester, []); + }); }); test('MultiChildRenderObjectElement with stateful components', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new DecoratedBox(decoration: kBoxDecorationB), + ]) + ); - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new DecoratedBox(decoration: kBoxDecorationB), - ]) - ); + checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); - checkTree(tester, [kBoxDecorationA, kBoxDecorationB]); + tester.pumpWidget( + new Stack([ + new FlipComponent( + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - tester.pumpFrame( - new Stack([ - new FlipComponent( - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); - checkTree(tester, [kBoxDecorationA, kBoxDecorationC]); + flipStatefulComponent(tester); + tester.pump(); - flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); - checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); + tester.pumpWidget( + new Stack([ + new FlipComponent( + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ), + ]) + ); - tester.pumpFrame( - new Stack([ - new FlipComponent( - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ), - ]) - ); + checkTree(tester, [kBoxDecorationB]); - checkTree(tester, [kBoxDecorationB]); + flipStatefulComponent(tester); + tester.pump(); - flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + checkTree(tester, [kBoxDecorationA]); - checkTree(tester, [kBoxDecorationA]); + tester.pumpWidget( + new Stack([ + new FlipComponent( + key: new Key('flip'), + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ), + ]) + ); - tester.pumpFrame( - new Stack([ - new FlipComponent( - key: new Key('flip'), - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC), + new FlipComponent( + key: new Key('flip'), + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ), + ]) + ); - tester.pumpFrame( - new Stack([ - new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC), - new FlipComponent( - key: new Key('flip'), - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ), - ]) - ); + checkTree(tester, [kBoxDecorationC, kBoxDecorationA]); - checkTree(tester, [kBoxDecorationC, kBoxDecorationA]); + flipStatefulComponent(tester); + tester.pump(); - flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + checkTree(tester, [kBoxDecorationC, kBoxDecorationB]); - checkTree(tester, [kBoxDecorationC, kBoxDecorationB]); - - tester.pumpFrame( - new Stack([ - new FlipComponent( - key: new Key('flip'), - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ), - new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC), - ]) - ); - - checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); + tester.pumpWidget( + new Stack([ + new FlipComponent( + key: new Key('flip'), + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ), + new DecoratedBox(key: new Key('c'), decoration: kBoxDecorationC), + ]) + ); + checkTree(tester, [kBoxDecorationB, kBoxDecorationC]); + }); }); } diff --git a/sky/unit/test/widget/navigator_test.dart b/sky/unit/test/widget/navigator_test.dart index 1e3f06bda97..5da23d03ef7 100644 --- a/sky/unit/test/widget/navigator_test.dart +++ b/sky/unit/test/widget/navigator_test.dart @@ -1,4 +1,3 @@ -import 'package:sky/animation.dart'; import 'package:sky/widgets.dart'; import 'package:test/test.dart'; @@ -48,36 +47,35 @@ class SecondComponentState extends State { void main() { test('Can navigator navigate to and from a stateful component', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + final Map routes = { + '/': (navigator, route) => new FirstComponent(navigator), + '/second': (navigator, route) => new SecondComponent(navigator), + }; - final Map routes = { - '/': (navigator, route) => new FirstComponent(navigator), - '/second': (navigator, route) => new SecondComponent(navigator), - }; + tester.pumpWidget(new Navigator(routes: routes)); - tester.pumpFrame(new Navigator(routes: routes)); + expect(tester.findText('X'), isNotNull); + expect(tester.findText('Y'), isNull); - expect(tester.findText('X'), isNotNull); - expect(tester.findText('Y'), isNull); + tester.tap(tester.findText('X')); + tester.pump(const Duration(milliseconds: 10)); - tester.tap(tester.findText('X')); - scheduler.beginFrame(10.0); + expect(tester.findText('X'), isNotNull); + expect(tester.findText('Y'), isNotNull); - expect(tester.findText('X'), isNotNull); - expect(tester.findText('Y'), isNotNull); + tester.pump(const Duration(milliseconds: 10)); + tester.pump(const Duration(milliseconds: 10)); + tester.pump(const Duration(seconds: 1)); - scheduler.beginFrame(20.0); - scheduler.beginFrame(30.0); - scheduler.beginFrame(1000.0); - - tester.tap(tester.findText('Y')); - scheduler.beginFrame(1010.0); - scheduler.beginFrame(1020.0); - scheduler.beginFrame(1030.0); - scheduler.beginFrame(2000.0); - - expect(tester.findText('X'), isNotNull); - expect(tester.findText('Y'), isNull); + tester.tap(tester.findText('Y')); + tester.pump(const Duration(milliseconds: 10)); + tester.pump(const Duration(milliseconds: 10)); + tester.pump(const Duration(milliseconds: 10)); + tester.pump(const Duration(seconds: 1)); + expect(tester.findText('X'), isNotNull); + expect(tester.findText('Y'), isNull); + }); }); } diff --git a/sky/unit/test/widget/pageable_list_test.dart b/sky/unit/test/widget/pageable_list_test.dart index 820eb3f64cf..e282e69ef67 100644 --- a/sky/unit/test/widget/pageable_list_test.dart +++ b/sky/unit/test/widget/pageable_list_test.dart @@ -1,4 +1,3 @@ -import 'package:quiver/testing/async.dart'; import 'package:sky/widgets.dart'; import 'package:test/test.dart'; @@ -33,13 +32,10 @@ Widget buildFrame() { void page(WidgetTester tester, Offset offset) { String itemText = currentPage != null ? currentPage.toString() : '0'; - new FakeAsync().run((async) { - tester.scroll(tester.findText(itemText), offset); - // One frame to start the animation, a second to complete it. - tester.pumpFrameWithoutChange(); - tester.pumpFrameWithoutChange(1000.0); - async.elapse(new Duration(seconds: 1)); - }); + tester.scroll(tester.findText(itemText), offset); + // One frame to start the animation, a second to complete it. + tester.pump(); + tester.pump(const Duration(seconds: 1)); } void pageLeft(WidgetTester tester) { @@ -54,59 +50,65 @@ void main() { // PageableList with itemsWrap: false test('Scroll left from page 0 to page 1', () { - WidgetTester tester = new WidgetTester(); - currentPage = null; - itemsWrap = false; - tester.pumpFrame(buildFrame()); - expect(currentPage, isNull); - pageLeft(tester); - expect(currentPage, equals(1)); + testWidgets((WidgetTester tester) { + currentPage = null; + itemsWrap = false; + tester.pumpWidget(buildFrame()); + expect(currentPage, isNull); + pageLeft(tester); + expect(currentPage, equals(1)); + }); }); test('Scroll right from page 1 to page 0', () { - WidgetTester tester = new WidgetTester(); - itemsWrap = false; - tester.pumpFrame(buildFrame()); - expect(currentPage, equals(1)); - pageRight(tester); - expect(currentPage, equals(0)); + testWidgets((WidgetTester tester) { + itemsWrap = false; + tester.pumpWidget(buildFrame()); + expect(currentPage, equals(1)); + pageRight(tester); + expect(currentPage, equals(0)); + }); }); test('Scroll right from page 0 does nothing (underscroll)', () { - WidgetTester tester = new WidgetTester(); - itemsWrap = false; - tester.pumpFrame(buildFrame()); - expect(currentPage, equals(0)); - pageRight(tester); - expect(currentPage, equals(0)); + testWidgets((WidgetTester tester) { + itemsWrap = false; + tester.pumpWidget(buildFrame()); + expect(currentPage, equals(0)); + pageRight(tester); + expect(currentPage, equals(0)); + }); }); // PageableList with itemsWrap: true test('Scroll left page 0 to page 1, itemsWrap: true', () { - WidgetTester tester = new WidgetTester(); - tester.reset(); - currentPage = null; - itemsWrap = true; - tester.pumpFrame(buildFrame()); - expect(currentPage, isNull); - pageLeft(tester); - expect(currentPage, equals(1)); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Container()); + currentPage = null; + itemsWrap = true; + tester.pumpWidget(buildFrame()); + expect(currentPage, isNull); + pageLeft(tester); + expect(currentPage, equals(1)); + }); }); test('Scroll right from page 1 to page 0, itemsWrap: true', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(buildFrame()); - expect(currentPage, equals(1)); - pageRight(tester); - expect(currentPage, equals(0)); + testWidgets((WidgetTester tester) { + tester.pumpWidget(buildFrame()); + expect(currentPage, equals(1)); + pageRight(tester); + expect(currentPage, equals(0)); + }); }); test('Scroll right from page 0 to page 5, itemsWrap: true (underscroll)', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(buildFrame()); - expect(currentPage, equals(0)); - pageRight(tester); - expect(currentPage, equals(5)); + testWidgets((WidgetTester tester) { + tester.pumpWidget(buildFrame()); + expect(currentPage, equals(0)); + pageRight(tester); + expect(currentPage, equals(5)); + }); }); } diff --git a/sky/unit/test/widget/parent_data_test.dart b/sky/unit/test/widget/parent_data_test.dart index ba3394e4cf9..f4892185962 100644 --- a/sky/unit/test/widget/parent_data_test.dart +++ b/sky/unit/test/widget/parent_data_test.dart @@ -58,230 +58,230 @@ void main() { }); test('ParentDataWidget control test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - tester.pumpFrame( - new Stack([ - new DecoratedBox(decoration: kBoxDecorationA), - new Positioned( - top: 10.0, - left: 10.0, - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new DecoratedBox(decoration: kBoxDecorationA), + new Positioned( + top: 10.0, + left: 10.0, + child: new DecoratedBox(decoration: kBoxDecorationB) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [ - kNonPositioned, - new TestParentData(top: 10.0, left: 10.0), - kNonPositioned, - ]); + checkTree(tester, [ + kNonPositioned, + new TestParentData(top: 10.0, left: 10.0), + kNonPositioned, + ]); - tester.pumpFrame( - new Stack([ - new Positioned( - bottom: 5.0, - right: 7.0, - child: new DecoratedBox(decoration: kBoxDecorationA) - ), - new Positioned( - top: 10.0, - left: 10.0, - child: new DecoratedBox(decoration: kBoxDecorationB) - ), - new DecoratedBox(decoration: kBoxDecorationC), - ]) - ); + tester.pumpWidget( + new Stack([ + new Positioned( + bottom: 5.0, + right: 7.0, + child: new DecoratedBox(decoration: kBoxDecorationA) + ), + new Positioned( + top: 10.0, + left: 10.0, + child: new DecoratedBox(decoration: kBoxDecorationB) + ), + new DecoratedBox(decoration: kBoxDecorationC), + ]) + ); - checkTree(tester, [ - new TestParentData(bottom: 5.0, right: 7.0), - new TestParentData(top: 10.0, left: 10.0), - kNonPositioned, - ]); + checkTree(tester, [ + new TestParentData(bottom: 5.0, right: 7.0), + new TestParentData(top: 10.0, left: 10.0), + kNonPositioned, + ]); - DecoratedBox kDecoratedBoxA = new DecoratedBox(decoration: kBoxDecorationA); - DecoratedBox kDecoratedBoxB = new DecoratedBox(decoration: kBoxDecorationB); - DecoratedBox kDecoratedBoxC = new DecoratedBox(decoration: kBoxDecorationC); + DecoratedBox kDecoratedBoxA = new DecoratedBox(decoration: kBoxDecorationA); + DecoratedBox kDecoratedBoxB = new DecoratedBox(decoration: kBoxDecorationB); + DecoratedBox kDecoratedBoxC = new DecoratedBox(decoration: kBoxDecorationC); - tester.pumpFrame( - new Stack([ - new Positioned( - bottom: 5.0, - right: 7.0, - child: kDecoratedBoxA - ), - new Positioned( - top: 10.0, - left: 10.0, - child: kDecoratedBoxB - ), - kDecoratedBoxC, - ]) - ); + tester.pumpWidget( + new Stack([ + new Positioned( + bottom: 5.0, + right: 7.0, + child: kDecoratedBoxA + ), + new Positioned( + top: 10.0, + left: 10.0, + child: kDecoratedBoxB + ), + kDecoratedBoxC, + ]) + ); - checkTree(tester, [ - new TestParentData(bottom: 5.0, right: 7.0), - new TestParentData(top: 10.0, left: 10.0), - kNonPositioned, - ]); + checkTree(tester, [ + new TestParentData(bottom: 5.0, right: 7.0), + new TestParentData(top: 10.0, left: 10.0), + kNonPositioned, + ]); - tester.pumpFrame( - new Stack([ - new Positioned( - bottom: 6.0, - right: 8.0, - child: kDecoratedBoxA - ), - new Positioned( - left: 10.0, - right: 10.0, - child: kDecoratedBoxB - ), - kDecoratedBoxC, - ]) - ); + tester.pumpWidget( + new Stack([ + new Positioned( + bottom: 6.0, + right: 8.0, + child: kDecoratedBoxA + ), + new Positioned( + left: 10.0, + right: 10.0, + child: kDecoratedBoxB + ), + kDecoratedBoxC, + ]) + ); - checkTree(tester, [ - new TestParentData(bottom: 6.0, right: 8.0), - new TestParentData(left: 10.0, right: 10.0), - kNonPositioned, - ]); + checkTree(tester, [ + new TestParentData(bottom: 6.0, right: 8.0), + new TestParentData(left: 10.0, right: 10.0), + kNonPositioned, + ]); - tester.pumpFrame( - new Stack([ - kDecoratedBoxA, - new Positioned( - left: 11.0, - right: 12.0, - child: new Container(child: kDecoratedBoxB) - ), - kDecoratedBoxC, - ]) - ); + tester.pumpWidget( + new Stack([ + kDecoratedBoxA, + new Positioned( + left: 11.0, + right: 12.0, + child: new Container(child: kDecoratedBoxB) + ), + kDecoratedBoxC, + ]) + ); - checkTree(tester, [ - kNonPositioned, - new TestParentData(left: 11.0, right: 12.0), - kNonPositioned, - ]); + checkTree(tester, [ + kNonPositioned, + new TestParentData(left: 11.0, right: 12.0), + kNonPositioned, + ]); - tester.pumpFrame( - new Stack([ - kDecoratedBoxA, - new Positioned( - right: 10.0, - child: new Container(child: kDecoratedBoxB) - ), - new Container( - child: new Positioned( - top: 8.0, - child: kDecoratedBoxC + tester.pumpWidget( + new Stack([ + kDecoratedBoxA, + new Positioned( + right: 10.0, + child: new Container(child: kDecoratedBoxB) + ), + new Container( + child: new Positioned( + top: 8.0, + child: kDecoratedBoxC + ) ) - ) - ]) - ); + ]) + ); - checkTree(tester, [ - kNonPositioned, - new TestParentData(right: 10.0), - new TestParentData(top: 8.0), - ]); + checkTree(tester, [ + kNonPositioned, + new TestParentData(right: 10.0), + new TestParentData(top: 8.0), + ]); - tester.pumpFrame( - new Stack([ - new Positioned( - right: 10.0, - child: new FlipComponent(left: kDecoratedBoxA, right: kDecoratedBoxB) - ), - ]) - ); + tester.pumpWidget( + new Stack([ + new Positioned( + right: 10.0, + child: new FlipComponent(left: kDecoratedBoxA, right: kDecoratedBoxB) + ), + ]) + ); - checkTree(tester, [ - new TestParentData(right: 10.0), - ]); + checkTree(tester, [ + new TestParentData(right: 10.0), + ]); - flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + flipStatefulComponent(tester); + tester.pump(); - checkTree(tester, [ - new TestParentData(right: 10.0), - ]); + checkTree(tester, [ + new TestParentData(right: 10.0), + ]); - tester.pumpFrame( - new Stack([ - new Positioned( - top: 7.0, - child: new FlipComponent(left: kDecoratedBoxA, right: kDecoratedBoxB) - ), - ]) - ); + tester.pumpWidget( + new Stack([ + new Positioned( + top: 7.0, + child: new FlipComponent(left: kDecoratedBoxA, right: kDecoratedBoxB) + ), + ]) + ); - checkTree(tester, [ - new TestParentData(top: 7.0), - ]); + checkTree(tester, [ + new TestParentData(top: 7.0), + ]); - flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + flipStatefulComponent(tester); + tester.pump(); - checkTree(tester, [ - new TestParentData(top: 7.0), - ]); + checkTree(tester, [ + new TestParentData(top: 7.0), + ]); - tester.pumpFrame( - new Stack([]) - ); + tester.pumpWidget( + new Stack([]) + ); - checkTree(tester, []); + checkTree(tester, []); + }); }); test('ParentDataWidget conflicting data', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + expect(cachedException, isNull); - expect(cachedException, isNull); - - tester.pumpFrame( - new Stack([ - new Positioned( - top: 5.0, - bottom: 8.0, - child: new Positioned( - top: 6.0, - left: 7.0, - child: new DecoratedBox(decoration: kBoxDecorationB) - ) - ) - ]) - ); - - expect(cachedException, isNotNull); - cachedException = null; - - tester.pumpFrame(new Stack([])); - - checkTree(tester, []); - expect(cachedException, isNull); - - tester.pumpFrame( - new Container( - child: new Flex([ + tester.pumpWidget( + new Stack([ new Positioned( - top: 6.0, - left: 7.0, - child: new DecoratedBox(decoration: kBoxDecorationB) + top: 5.0, + bottom: 8.0, + child: new Positioned( + top: 6.0, + left: 7.0, + child: new DecoratedBox(decoration: kBoxDecorationB) + ) ) ]) - ) - ); + ); - expect(cachedException, isNotNull); - cachedException = null; + expect(cachedException, isNotNull); + cachedException = null; - tester.pumpFrame( - new Stack([]) - ); + tester.pumpWidget(new Stack([])); - checkTree(tester, []); + checkTree(tester, []); + expect(cachedException, isNull); + + tester.pumpWidget( + new Container( + child: new Flex([ + new Positioned( + top: 6.0, + left: 7.0, + child: new DecoratedBox(decoration: kBoxDecorationB) + ) + ]) + ) + ); + + expect(cachedException, isNotNull); + cachedException = null; + + tester.pumpWidget( + new Stack([]) + ); + + checkTree(tester, []); + }); }); - } diff --git a/sky/unit/test/widget/progress_indicator_test.dart b/sky/unit/test/widget/progress_indicator_test.dart index 3d36feb78f4..83389335de6 100644 --- a/sky/unit/test/widget/progress_indicator_test.dart +++ b/sky/unit/test/widget/progress_indicator_test.dart @@ -7,15 +7,15 @@ import 'widget_tester.dart'; void main() { 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 layers1 = tester.layers; - List layers1 = tester.layers; + tester.pumpWidget(new Block([new LinearProgressIndicator(value: 0.5)])); - tester.pumpFrame(new Block([new LinearProgressIndicator(value: 0.5)])); - - List layers2 = tester.layers; - expect(layers1, isNot(equals(layers2))); + List layers2 = tester.layers; + expect(layers1, isNot(equals(layers2))); + }); }); } diff --git a/sky/unit/test/widget/render_object_widget_test.dart b/sky/unit/test/widget/render_object_widget_test.dart index 6fbc196cc7b..57335b57d80 100644 --- a/sky/unit/test/widget/render_object_widget_test.dart +++ b/sky/unit/test/widget/render_object_widget_test.dart @@ -16,151 +16,153 @@ class TestComponent extends StatelessComponent { void main() { test('RenderObjectWidget smoke test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new DecoratedBox(decoration: kBoxDecorationA)); + OneChildRenderObjectElement element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element, isNotNull); + expect(element.renderObject is RenderDecoratedBox, isTrue); + RenderDecoratedBox renderObject = element.renderObject; + expect(renderObject.decoration, equals(kBoxDecorationA)); + expect(renderObject.position, equals(BoxDecorationPosition.background)); - tester.pumpFrame(new DecoratedBox(decoration: kBoxDecorationA)); - OneChildRenderObjectElement element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element, isNotNull); - expect(element.renderObject is RenderDecoratedBox, isTrue); - RenderDecoratedBox renderObject = element.renderObject; - expect(renderObject.decoration, equals(kBoxDecorationA)); - expect(renderObject.position, equals(BoxDecorationPosition.background)); - - tester.pumpFrame(new DecoratedBox(decoration: kBoxDecorationB)); - element = tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element, isNotNull); - expect(element.renderObject is RenderDecoratedBox, isTrue); - renderObject = element.renderObject; - expect(renderObject.decoration, equals(kBoxDecorationB)); - expect(renderObject.position, equals(BoxDecorationPosition.background)); + tester.pumpWidget(new DecoratedBox(decoration: kBoxDecorationB)); + element = tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element, isNotNull); + expect(element.renderObject is RenderDecoratedBox, isTrue); + renderObject = element.renderObject; + expect(renderObject.decoration, equals(kBoxDecorationB)); + expect(renderObject.position, equals(BoxDecorationPosition.background)); + }); }); test('RenderObjectWidget can add and remove children', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - void checkFullTree() { - OneChildRenderObjectElement element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element, isNotNull); - expect(element.renderObject is RenderDecoratedBox, isTrue); - RenderDecoratedBox renderObject = element.renderObject; - expect(renderObject.decoration, equals(kBoxDecorationA)); - expect(renderObject.position, equals(BoxDecorationPosition.background)); - expect(renderObject.child, isNotNull); - expect(renderObject.child is RenderDecoratedBox, isTrue); - RenderDecoratedBox child = renderObject.child; - expect(child.decoration, equals(kBoxDecorationB)); - expect(child.position, equals(BoxDecorationPosition.background)); - expect(child.child, isNull); - } + void checkFullTree() { + OneChildRenderObjectElement element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element, isNotNull); + expect(element.renderObject is RenderDecoratedBox, isTrue); + RenderDecoratedBox renderObject = element.renderObject; + expect(renderObject.decoration, equals(kBoxDecorationA)); + expect(renderObject.position, equals(BoxDecorationPosition.background)); + expect(renderObject.child, isNotNull); + expect(renderObject.child is RenderDecoratedBox, isTrue); + RenderDecoratedBox child = renderObject.child; + expect(child.decoration, equals(kBoxDecorationB)); + expect(child.position, equals(BoxDecorationPosition.background)); + expect(child.child, isNull); + } - void childBareTree() { - OneChildRenderObjectElement element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element, isNotNull); - expect(element.renderObject is RenderDecoratedBox, isTrue); - RenderDecoratedBox renderObject = element.renderObject; - expect(renderObject.decoration, equals(kBoxDecorationA)); - expect(renderObject.position, equals(BoxDecorationPosition.background)); - expect(renderObject.child, isNull); - } + void childBareTree() { + OneChildRenderObjectElement element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element, isNotNull); + expect(element.renderObject is RenderDecoratedBox, isTrue); + RenderDecoratedBox renderObject = element.renderObject; + expect(renderObject.decoration, equals(kBoxDecorationA)); + expect(renderObject.position, equals(BoxDecorationPosition.background)); + expect(renderObject.child, isNull); + } - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA, - child: new DecoratedBox( - decoration: kBoxDecorationB - ) - )); - - checkFullTree(); - - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA, - child: new TestComponent( + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA, child: new DecoratedBox( decoration: kBoxDecorationB ) - ) - )); + )); - checkFullTree(); + checkFullTree(); - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA, - child: new DecoratedBox( - decoration: kBoxDecorationB - ) - )); - - checkFullTree(); - - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA - )); - - childBareTree(); - - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA, - child: new TestComponent( + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA, child: new TestComponent( child: new DecoratedBox( decoration: kBoxDecorationB ) ) - ) - )); + )); - checkFullTree(); + checkFullTree(); - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA - )); + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA, + child: new DecoratedBox( + decoration: kBoxDecorationB + ) + )); - childBareTree(); + checkFullTree(); + + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA + )); + + childBareTree(); + + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA, + child: new TestComponent( + child: new TestComponent( + child: new DecoratedBox( + decoration: kBoxDecorationB + ) + ) + ) + )); + + checkFullTree(); + + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA + )); + + childBareTree(); + }); }); test('Detached render tree is intact', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA, - child: new DecoratedBox( - decoration: kBoxDecorationB, + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA, child: new DecoratedBox( - decoration: kBoxDecorationC + decoration: kBoxDecorationB, + child: new DecoratedBox( + decoration: kBoxDecorationC + ) ) - ) - )); + )); - OneChildRenderObjectElement element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element.renderObject is RenderDecoratedBox, isTrue); - RenderDecoratedBox parent = element.renderObject; - expect(parent.child is RenderDecoratedBox, isTrue); - RenderDecoratedBox child = parent.child; - expect(child.decoration, equals(kBoxDecorationB)); - expect(child.child is RenderDecoratedBox, isTrue); - RenderDecoratedBox grandChild = child.child; - expect(grandChild.decoration, equals(kBoxDecorationC)); - expect(grandChild.child, isNull); + OneChildRenderObjectElement element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element.renderObject is RenderDecoratedBox, isTrue); + RenderDecoratedBox parent = element.renderObject; + expect(parent.child is RenderDecoratedBox, isTrue); + RenderDecoratedBox child = parent.child; + expect(child.decoration, equals(kBoxDecorationB)); + expect(child.child is RenderDecoratedBox, isTrue); + RenderDecoratedBox grandChild = child.child; + expect(grandChild.decoration, equals(kBoxDecorationC)); + expect(grandChild.child, isNull); - tester.pumpFrame(new DecoratedBox( - decoration: kBoxDecorationA - )); + tester.pumpWidget(new DecoratedBox( + decoration: kBoxDecorationA + )); - element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element.renderObject is RenderDecoratedBox, isTrue); - expect(element.renderObject, equals(parent)); - expect(parent.child, isNull); + element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element.renderObject is RenderDecoratedBox, isTrue); + expect(element.renderObject, equals(parent)); + expect(parent.child, isNull); - expect(child.parent, isNull); - expect(child.decoration, equals(kBoxDecorationB)); - expect(child.child, equals(grandChild)); - expect(grandChild.parent, equals(child)); - expect(grandChild.decoration, equals(kBoxDecorationC)); - expect(grandChild.child, isNull); + expect(child.parent, isNull); + expect(child.decoration, equals(kBoxDecorationB)); + expect(child.child, equals(grandChild)); + expect(grandChild.parent, equals(child)); + expect(grandChild.decoration, equals(kBoxDecorationC)); + expect(grandChild.child, isNull); + }); }); } diff --git a/sky/unit/test/widget/scrollable_list_hit_testing_test.dart b/sky/unit/test/widget/scrollable_list_hit_testing_test.dart index b8c9a1a361f..32073bea3b0 100644 --- a/sky/unit/test/widget/scrollable_list_hit_testing_test.dart +++ b/sky/unit/test/widget/scrollable_list_hit_testing_test.dart @@ -8,87 +8,89 @@ const List items = const [0, 1, 2, 3, 4, 5]; List tapped = []; void main() { - double t = 0.0; - WidgetTester tester = new WidgetTester(); - test('Tap item after scroll - horizontal', () { - tester.pumpFrame(new Center( - child: new Container( - height: 50.0, - child: new ScrollableList( - key: new GlobalKey(), - items: items, - itemBuilder: (BuildContext context, int item) { - return new Container( - key: new ValueKey(item), - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item') - ) - ); - }, - itemExtent: 290.0, - scrollDirection: ScrollDirection.horizontal + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Container()); + tester.pumpWidget(new Center( + child: new Container( + height: 50.0, + child: new ScrollableList( + key: new GlobalKey(), + items: items, + itemBuilder: (BuildContext context, int item) { + return new Container( + key: new ValueKey(item), + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item') + ) + ); + }, + itemExtent: 290.0, + scrollDirection: ScrollDirection.horizontal + ) ) - ) - ), t); - tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -280..10 = 0 - // 10..300 = 1 - // 300..590 = 2 - // 590..880 = 3 - expect(tester.findText('0'), isNotNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNull); - expect(tester.findText('5'), isNull); - expect(tapped, equals([])); - tester.tap(tester.findText('2')); - expect(tapped, equals([2])); + )); + tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -280..10 = 0 + // 10..300 = 1 + // 300..590 = 2 + // 590..880 = 3 + expect(tester.findText('0'), isNotNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNull); + expect(tester.findText('5'), isNull); + expect(tapped, equals([])); + tester.tap(tester.findText('2')); + expect(tapped, equals([2])); + }); }); test('Tap item after scroll - vertical', () { - tester.pumpFrame(new Center( - child: new Container( - width: 50.0, - child: new ScrollableList( - key: new GlobalKey(), - items: items, - itemBuilder: (BuildContext context, int item) { - return new Container( - key: new ValueKey(item), - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item') - ) - ); - }, - itemExtent: 290.0, - scrollDirection: ScrollDirection.vertical + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Container()); + tester.pumpWidget(new Center( + child: new Container( + width: 50.0, + child: new ScrollableList( + key: new GlobalKey(), + items: items, + itemBuilder: (BuildContext context, int item) { + return new Container( + key: new ValueKey(item), + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item') + ) + ); + }, + itemExtent: 290.0, + scrollDirection: ScrollDirection.vertical + ) ) - ) - ), t); - tester.scroll(tester.findText('1'), const Offset(0.0, -280.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 600px tall, and has the following items: - // -280..10 = 0 - // 10..300 = 1 - // 300..590 = 2 - // 590..880 = 3 - expect(tester.findText('0'), isNotNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNull); - expect(tester.findText('5'), isNull); - expect(tapped, equals([2])); - tester.tap(tester.findText('1')); - expect(tapped, equals([2, 1])); - 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 + )); + tester.scroll(tester.findText('1'), const Offset(0.0, -280.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 600px tall, and has the following items: + // -280..10 = 0 + // 10..300 = 1 + // 300..590 = 2 + // 590..880 = 3 + expect(tester.findText('0'), isNotNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNull); + expect(tester.findText('5'), isNull); + expect(tapped, equals([2])); + tester.tap(tester.findText('1')); + expect(tapped, equals([2, 1])); + 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 + }); }); - } diff --git a/sky/unit/test/widget/scrollable_list_horizontal_test.dart b/sky/unit/test/widget/scrollable_list_horizontal_test.dart index b8ff44b37b0..506bf58bb22 100644 --- a/sky/unit/test/widget/scrollable_list_horizontal_test.dart +++ b/sky/unit/test/widget/scrollable_list_horizontal_test.dart @@ -26,135 +26,124 @@ Widget buildFrame() { } void main() { - double t = 0.0; - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(buildFrame()); + test('Drag horizontally', () { + testWidgets((WidgetTester tester) { + tester.pumpWidget(buildFrame()); - test('Drag to the left using item 1', () { - tester.pumpFrameWithoutChange(t += 1000.0); - tester.scroll(tester.findText('1'), const Offset(-300.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -10..280 = 1 - // 280..570 = 2 - // 570..860 = 3 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNull); - expect(tester.findText('5'), isNull); + tester.pump(const Duration(seconds: 1)); + tester.scroll(tester.findText('1'), const Offset(-300.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -10..280 = 1 + // 280..570 = 2 + // 570..860 = 3 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNull); + expect(tester.findText('5'), isNull); + + // 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, + // because it wouldn't be hit tested when scrolling from its center, as scroll() does. + tester.pump(const Duration(seconds: 1)); + tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -10..280 = 2 + // 280..570 = 3 + // 570..860 = 4 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNull); + + tester.pump(const Duration(seconds: 1)); + tester.scroll(tester.findText('3'), const Offset(0.0, -290.0)); + tester.pump(const Duration(seconds: 1)); + // unchanged + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNull); + + tester.pump(const Duration(seconds: 1)); + tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -10..280 = 3 + // 280..570 = 4 + // 570..860 = 5 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNotNull); + + tester.pump(const Duration(seconds: 1)); + // 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 + // to move item 3 entirely off screen therefore takes: + // 60 + (290-60)*2 = 520 pixels + // plus a couple more to be sure + tester.scroll(tester.findText('3'), const Offset(-522.0, 0.0)); + tester.pump(); // just after release + // screen is 800px wide, and has the following items: + // -11..279 = 4 + // 279..569 = 5 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNull); + expect(tester.findText('3'), isNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNotNull); + tester.pump(const Duration(seconds: 1)); // a second after release + // screen is 800px wide, and has the following items: + // -70..220 = 3 + // 220..510 = 4 + // 510..800 = 5 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNotNull); + + tester.pumpWidget(new Container()); + tester.pumpWidget(buildFrame(), const Duration(seconds: 1)); + tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -280..10 = 0 + // 10..300 = 1 + // 300..590 = 2 + // 590..880 = 3 + expect(tester.findText('0'), isNotNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNull); + expect(tester.findText('5'), isNull); + tester.pump(const Duration(seconds: 1)); + tester.scroll(tester.findText('2'), const Offset(-290.0, 0.0)); + tester.pump(const Duration(seconds: 1)); + // screen is 800px wide, and has the following items: + // -280..10 = 1 + // 10..300 = 2 + // 300..590 = 3 + // 590..880 = 4 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNull); + }); }); - - test('Drag to the left using item 3', () { - // 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, - // because it wouldn't be hit tested when scrolling from its center, as scroll() does. - tester.pumpFrameWithoutChange(t += 1000.0); - tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -10..280 = 2 - // 280..570 = 3 - // 570..860 = 4 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNull); - }); - - test('Drag up using item 3', () { - tester.pumpFrameWithoutChange(t += 1000.0); - tester.scroll(tester.findText('3'), const Offset(0.0, -290.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // unchanged - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNull); - }); - - test('Drag to the left using item 3 again', () { - tester.pumpFrameWithoutChange(t += 1000.0); - tester.scroll(tester.findText('3'), const Offset(-290.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -10..280 = 3 - // 280..570 = 4 - // 570..860 = 5 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNotNull); - }); - - test('Drag to the left using item 3 again again (past the end of the list)', () { - tester.pumpFrameWithoutChange(t += 1000.0); - // 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 - // to move item 3 entirely off screen therefore takes: - // 60 + (290-60)*2 = 520 pixels - // plus a couple more to be sure - tester.scroll(tester.findText('3'), const Offset(-522.0, 0.0)); - tester.pumpFrameWithoutChange(t += 0.0); // just after release - // screen is 800px wide, and has the following items: - // -11..279 = 4 - // 279..569 = 5 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNull); - expect(tester.findText('3'), isNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNotNull); - tester.pumpFrameWithoutChange(t += 1000.0); // a second after release - // screen is 800px wide, and has the following items: - // -70..220 = 3 - // 220..510 = 4 - // 510..800 = 5 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNotNull); - }); - - test('Drag to the left using item 2 when the scroll offset is big', () { - tester.reset(); - tester.pumpFrame(buildFrame(), t += 1000.0); - tester.scroll(tester.findText('2'), const Offset(-280.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -280..10 = 0 - // 10..300 = 1 - // 300..590 = 2 - // 590..880 = 3 - expect(tester.findText('0'), isNotNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNull); - expect(tester.findText('5'), isNull); - tester.pumpFrameWithoutChange(t += 1000.0); - tester.scroll(tester.findText('2'), const Offset(-290.0, 0.0)); - tester.pumpFrameWithoutChange(t += 1000.0); - // screen is 800px wide, and has the following items: - // -280..10 = 1 - // 10..300 = 2 - // 300..590 = 3 - // 590..880 = 4 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNull); - }); - } diff --git a/sky/unit/test/widget/scrollable_list_vertical_test.dart b/sky/unit/test/widget/scrollable_list_vertical_test.dart index 84282701b3c..8effa156840 100644 --- a/sky/unit/test/widget/scrollable_list_vertical_test.dart +++ b/sky/unit/test/widget/scrollable_list_vertical_test.dart @@ -20,52 +20,48 @@ Widget buildFrame() { } void main() { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(buildFrame()); + test('Drag vertically', () { + testWidgets((WidgetTester tester) { + tester.pumpWidget(buildFrame()); - test('Drag up using item 1', () { - tester.pumpFrameWithoutChange(); - tester.scroll(tester.findText('1'), const Offset(0.0, -300.0)); - tester.pumpFrameWithoutChange(); - // screen is 600px high, and has the following items: - // -10..280 = 1 - // 280..570 = 2 - // 570..860 = 3 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNotNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNull); - expect(tester.findText('5'), isNull); + tester.pump(); + tester.scroll(tester.findText('1'), const Offset(0.0, -300.0)); + tester.pump(); + // screen is 600px high, and has the following items: + // -10..280 = 1 + // 280..570 = 2 + // 570..860 = 3 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNotNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNull); + expect(tester.findText('5'), isNull); + + tester.pump(); + tester.scroll(tester.findText('2'), const Offset(0.0, -290.0)); + tester.pump(); + // screen is 600px high, and has the following items: + // -10..280 = 2 + // 280..570 = 3 + // 570..860 = 4 + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNull); + + tester.pump(); + tester.scroll(tester.findText('3'), const Offset(-300.0, 0.0)); + tester.pump(); + // nothing should have changed + expect(tester.findText('0'), isNull); + expect(tester.findText('1'), isNull); + expect(tester.findText('2'), isNotNull); + expect(tester.findText('3'), isNotNull); + expect(tester.findText('4'), isNotNull); + expect(tester.findText('5'), isNull); + }); }); - - test('Drag up using item 2', () { - tester.pumpFrameWithoutChange(); - tester.scroll(tester.findText('2'), const Offset(0.0, -290.0)); - tester.pumpFrameWithoutChange(); - // screen is 600px high, and has the following items: - // -10..280 = 2 - // 280..570 = 3 - // 570..860 = 4 - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNull); - }); - - test('Drag to the left using item 3', () { - tester.pumpFrameWithoutChange(); - tester.scroll(tester.findText('3'), const Offset(-300.0, 0.0)); - tester.pumpFrameWithoutChange(); - // nothing should have changed - expect(tester.findText('0'), isNull); - expect(tester.findText('1'), isNull); - expect(tester.findText('2'), isNotNull); - expect(tester.findText('3'), isNotNull); - expect(tester.findText('4'), isNotNull); - expect(tester.findText('5'), isNull); - }); - } diff --git a/sky/unit/test/widget/set_state_3_test.dart b/sky/unit/test/widget/set_state_3_test.dart index f4f0a8eb046..b78ab070eb0 100644 --- a/sky/unit/test/widget/set_state_3_test.dart +++ b/sky/unit/test/widget/set_state_3_test.dart @@ -48,10 +48,11 @@ class LeafState extends State { void main() { test('three-way setState() smoke test', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(new Changer(new Wrapper(new Leaf()))); - tester.pumpFrame(new Changer(new Wrapper(new Leaf()))); - changer.test(); - tester.pumpFrameWithoutChange(); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Changer(new Wrapper(new Leaf()))); + tester.pumpWidget(new Changer(new Wrapper(new Leaf()))); + changer.test(); + tester.pump(); + }); }); } diff --git a/sky/unit/test/widget/set_state_test.dart b/sky/unit/test/widget/set_state_test.dart index 43bb81aa149..adb9239b0e0 100644 --- a/sky/unit/test/widget/set_state_test.dart +++ b/sky/unit/test/widget/set_state_test.dart @@ -54,13 +54,14 @@ class OutsideState extends State { void main() { test('setState() smoke test', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(new Outside()); - TestPointer pointer = new TestPointer(1); - Point location = tester.getCenter(tester.findText('INSIDE')); - tester.dispatchEvent(pointer.down(location), location); - tester.pumpFrameWithoutChange(); - tester.dispatchEvent(pointer.up(), location); - tester.pumpFrameWithoutChange(); + testWidgets((WidgetTester tester) { + tester.pumpWidget(new Outside()); + TestPointer pointer = new TestPointer(1); + Point location = tester.getCenter(tester.findText('INSIDE')); + tester.dispatchEvent(pointer.down(location), location); + tester.pump(); + tester.dispatchEvent(pointer.up(), location); + tester.pump(); + }); }); } diff --git a/sky/unit/test/widget/snap_scrolling_test.dart b/sky/unit/test/widget/snap_scrolling_test.dart index 871473bedd8..c5c0bb66078 100644 --- a/sky/unit/test/widget/snap_scrolling_test.dart +++ b/sky/unit/test/widget/snap_scrolling_test.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:quiver/testing/async.dart'; import 'package:sky/widgets.dart'; import 'package:test/test.dart'; @@ -59,91 +58,60 @@ Future fling(double velocity) { } void main() { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame(buildFrame()); - test('ScrollableList snap scrolling, fling(-800)', () { - scrollOffset = 0.0; - tester.pumpFrameWithoutChange(); - expect(scrollOffset, 0.0); + testWidgets((WidgetTester tester) { + tester.pumpWidget(buildFrame()); + + scrollOffset = 0.0; + tester.pump(); + expect(scrollOffset, 0.0); + + Duration dt = const Duration(seconds: 2); - double t0 = 0.0; - int dt = 2000; - new FakeAsync().run((async) { fling(-800.0); - tester.pumpFrameWithoutChange(t0); // Start the scheduler at 0.0 - tester.pumpFrameWithoutChange(t0 + dt); - async.elapse(new Duration(milliseconds: dt)); + tester.pump(); // Start the scheduler at 0.0 + tester.pump(dt); expect(scrollOffset, closeTo(200.0, 1.0)); - }); - }); - test('ScrollableList snap scrolling, fling(-2000)', () { - scrollOffset = 0.0; - tester.pumpFrameWithoutChange(); - expect(scrollOffset, 0.0); + scrollOffset = 0.0; + tester.pump(); + expect(scrollOffset, 0.0); - double t0 = 0.0; - int dt = 2000; - new FakeAsync().run((async) { fling(-2000.0); - tester.pumpFrameWithoutChange(t0); - tester.pumpFrameWithoutChange(t0 + dt); - async.elapse(new Duration(milliseconds: dt)); + tester.pump(); + tester.pump(dt); expect(scrollOffset, closeTo(400.0, 1.0)); - }); - }); - test('ScrollableList snap scrolling, fling(800)', () { - scrollOffset = 400.0; - tester.pumpFrameWithoutChange(); - expect(scrollOffset, 400.0); + scrollOffset = 400.0; + tester.pump(); + expect(scrollOffset, 400.0); - double t0 = 0.0; - int dt = 2000; - new FakeAsync().run((async) { fling(800.0); - tester.pumpFrameWithoutChange(t0); - tester.pumpFrameWithoutChange(t0 + dt); - async.elapse(new Duration(milliseconds: dt)); + tester.pump(); + tester.pump(dt); expect(scrollOffset, closeTo(0.0, 1.0)); - }); - }); - test('ScrollableList snap scrolling, fling(2000)', () { - scrollOffset = 800.0; - tester.pumpFrameWithoutChange(); - expect(scrollOffset, 800.0); + scrollOffset = 800.0; + tester.pump(); + expect(scrollOffset, 800.0); - double t0 = 0.0; - int dt = 2000; - new FakeAsync().run((async) { fling(2000.0); - tester.pumpFrameWithoutChange(t0); - tester.pumpFrameWithoutChange(t0 + dt); - async.elapse(new Duration(milliseconds: dt)); + tester.pump(); + tester.pump(dt); expect(scrollOffset, closeTo(200.0, 1.0)); - }); - }); - test('ScrollableList snap scrolling, fling(2000).then()', () { - scrollOffset = 800.0; - tester.pumpFrameWithoutChange(); - expect(scrollOffset, 800.0); + scrollOffset = 800.0; + tester.pump(); + expect(scrollOffset, 800.0); - double t0 = 0.0; - int dt = 2000; - bool completed = false; - new FakeAsync().run((async) { + bool completed = false; fling(2000.0).then((_) { completed = true; expect(scrollOffset, closeTo(200.0, 1.0)); }); - tester.pumpFrameWithoutChange(t0); - tester.pumpFrameWithoutChange(t0 + dt); - async.elapse(new Duration(milliseconds: dt)); + tester.pump(); + tester.pump(dt); expect(completed, true); }); }); - } diff --git a/sky/unit/test/widget/stack_test.dart b/sky/unit/test/widget/stack_test.dart index 405b398bb70..1866bd64364 100644 --- a/sky/unit/test/widget/stack_test.dart +++ b/sky/unit/test/widget/stack_test.dart @@ -5,70 +5,69 @@ import 'widget_tester.dart'; void main() { test('Can change position data', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + Key key = new Key('container'); - Key key = new Key('container'); - - tester.pumpFrame( - new Stack([ - new Positioned( - left: 10.0, - child: new Container( - key: key, - width: 10.0, - height: 10.0 + tester.pumpWidget( + new Stack([ + new Positioned( + left: 10.0, + child: new Container( + key: key, + width: 10.0, + height: 10.0 + ) ) - ) - ]) - ); + ]) + ); - Element container = tester.findElementByKey(key); - expect(container.renderObject.parentData.top, isNull); - expect(container.renderObject.parentData.right, isNull); - expect(container.renderObject.parentData.bottom, isNull); - expect(container.renderObject.parentData.left, equals(10.0)); + Element container = tester.findElementByKey(key); + expect(container.renderObject.parentData.top, isNull); + expect(container.renderObject.parentData.right, isNull); + expect(container.renderObject.parentData.bottom, isNull); + expect(container.renderObject.parentData.left, equals(10.0)); - tester.pumpFrame( - new Stack([ - new Positioned( - right: 10.0, - child: new Container( - key: key, - width: 10.0, - height: 10.0 + tester.pumpWidget( + new Stack([ + new Positioned( + right: 10.0, + child: new Container( + key: key, + width: 10.0, + height: 10.0 + ) ) - ) - ]) - ); + ]) + ); - container = tester.findElementByKey(key); - expect(container.renderObject.parentData.top, isNull); - expect(container.renderObject.parentData.right, equals(10.0)); - expect(container.renderObject.parentData.bottom, isNull); - expect(container.renderObject.parentData.left, isNull); + container = tester.findElementByKey(key); + expect(container.renderObject.parentData.top, isNull); + expect(container.renderObject.parentData.right, equals(10.0)); + expect(container.renderObject.parentData.bottom, isNull); + expect(container.renderObject.parentData.left, isNull); + }); }); test('Can remove parent data', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { + Key key = new Key('container'); + Container container = new Container(key: key, width: 10.0, height: 10.0); - Key key = new Key('container'); - Container container = new Container(key: key, width: 10.0, height: 10.0); + tester.pumpWidget(new Stack([ new Positioned(left: 10.0, child: container) ])); + Element containerElement = tester.findElementByKey(key); - tester.pumpFrame(new Stack([ new Positioned(left: 10.0, child: container) ])); - Element containerElement = tester.findElementByKey(key); + expect(containerElement.renderObject.parentData.top, isNull); + expect(containerElement.renderObject.parentData.right, isNull); + expect(containerElement.renderObject.parentData.bottom, isNull); + expect(containerElement.renderObject.parentData.left, equals(10.0)); - expect(containerElement.renderObject.parentData.top, isNull); - expect(containerElement.renderObject.parentData.right, isNull); - expect(containerElement.renderObject.parentData.bottom, isNull); - expect(containerElement.renderObject.parentData.left, equals(10.0)); + tester.pumpWidget(new Stack([ container ])); + containerElement = tester.findElementByKey(key); - tester.pumpFrame(new Stack([ container ])); - containerElement = tester.findElementByKey(key); - - expect(containerElement.renderObject.parentData.top, isNull); - expect(containerElement.renderObject.parentData.right, isNull); - expect(containerElement.renderObject.parentData.bottom, isNull); - expect(containerElement.renderObject.parentData.left, isNull); + expect(containerElement.renderObject.parentData.top, isNull); + expect(containerElement.renderObject.parentData.right, isNull); + expect(containerElement.renderObject.parentData.bottom, isNull); + expect(containerElement.renderObject.parentData.left, isNull); + }); }); - } diff --git a/sky/unit/test/widget/stateful_component_test.dart b/sky/unit/test/widget/stateful_component_test.dart index b8bc8499b9c..694e6613eba 100644 --- a/sky/unit/test/widget/stateful_component_test.dart +++ b/sky/unit/test/widget/stateful_component_test.dart @@ -7,68 +7,69 @@ import 'test_widgets.dart'; void main() { test('Stateful component smoke test', () { - WidgetTester tester = new WidgetTester(); + testWidgets((WidgetTester tester) { - void checkTree(BoxDecoration expectedDecoration) { - OneChildRenderObjectElement element = - tester.findElement((element) => element is OneChildRenderObjectElement); - expect(element, isNotNull); - expect(element.renderObject is RenderDecoratedBox, isTrue); - RenderDecoratedBox renderObject = element.renderObject; - expect(renderObject.decoration, equals(expectedDecoration)); - } + void checkTree(BoxDecoration expectedDecoration) { + OneChildRenderObjectElement element = + tester.findElement((element) => element is OneChildRenderObjectElement); + expect(element, isNotNull); + expect(element.renderObject is RenderDecoratedBox, isTrue); + RenderDecoratedBox renderObject = element.renderObject; + expect(renderObject.decoration, equals(expectedDecoration)); + } - tester.pumpFrame( - new FlipComponent( - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ) - ); + tester.pumpWidget( + new FlipComponent( + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ) + ); - checkTree(kBoxDecorationA); + checkTree(kBoxDecorationA); - tester.pumpFrame( - new FlipComponent( - left: new DecoratedBox(decoration: kBoxDecorationB), - right: new DecoratedBox(decoration: kBoxDecorationA) - ) - ); + tester.pumpWidget( + new FlipComponent( + left: new DecoratedBox(decoration: kBoxDecorationB), + right: new DecoratedBox(decoration: kBoxDecorationA) + ) + ); - checkTree(kBoxDecorationB); + checkTree(kBoxDecorationB); - flipStatefulComponent(tester); + flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + tester.pump(); - checkTree(kBoxDecorationA); + checkTree(kBoxDecorationA); - tester.pumpFrame( - new FlipComponent( - left: new DecoratedBox(decoration: kBoxDecorationA), - right: new DecoratedBox(decoration: kBoxDecorationB) - ) - ); - - checkTree(kBoxDecorationB); + tester.pumpWidget( + new FlipComponent( + left: new DecoratedBox(decoration: kBoxDecorationA), + right: new DecoratedBox(decoration: kBoxDecorationB) + ) + ); + checkTree(kBoxDecorationB); + }); }); test('Don\'t rebuild subcomponents', () { - WidgetTester tester = new WidgetTester(); - tester.pumpFrame( - 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. - left: new TestBuildCounter(), - right: new DecoratedBox(decoration: kBoxDecorationB) - ) - ); + testWidgets((WidgetTester tester) { + tester.pumpWidget( + 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. + left: new TestBuildCounter(), + right: new DecoratedBox(decoration: kBoxDecorationB) + ) + ); - expect(TestBuildCounter.buildCount, equals(1)); + expect(TestBuildCounter.buildCount, equals(1)); - flipStatefulComponent(tester); + flipStatefulComponent(tester); - tester.pumpFrameWithoutChange(); + tester.pump(); - expect(TestBuildCounter.buildCount, equals(1)); + expect(TestBuildCounter.buildCount, equals(1)); + }); }); } diff --git a/sky/unit/test/widget/stateful_components_test.dart b/sky/unit/test/widget/stateful_components_test.dart index f7d7a1f1fdc..e52e4fd6ad8 100644 --- a/sky/unit/test/widget/stateful_components_test.dart +++ b/sky/unit/test/widget/stateful_components_test.dart @@ -37,45 +37,44 @@ class OuterContainerState extends State { void main() { test('resync stateful widget', () { + testWidgets((WidgetTester tester) { + Key innerKey = new Key('inner'); + Key outerKey = new Key('outer'); - WidgetTester tester = new WidgetTester(); + InnerComponent inner1 = new InnerComponent(key: innerKey); + InnerComponent inner2; + OuterContainer outer1 = new OuterContainer(key: outerKey, child: inner1); + OuterContainer outer2; - Key innerKey = new Key('inner'); - Key outerKey = new Key('outer'); + tester.pumpWidget(outer1); - InnerComponent inner1 = new InnerComponent(key: innerKey); - InnerComponent inner2; - OuterContainer outer1 = new OuterContainer(key: outerKey, child: inner1); - OuterContainer outer2; + StatefulComponentElement innerElement = tester.findElementByKey(innerKey); + InnerComponentState innerElementState = innerElement.state; + expect(innerElementState.config, equals(inner1)); + expect(innerElementState._didInitState, isTrue); + expect(innerElement.renderObject.attached, isTrue); - tester.pumpFrame(outer1); + inner2 = new InnerComponent(key: innerKey); + outer2 = new OuterContainer(key: outerKey, child: inner2); - StatefulComponentElement innerElement = tester.findElementByKey(innerKey); - InnerComponentState innerElementState = innerElement.state; - expect(innerElementState.config, equals(inner1)); - expect(innerElementState._didInitState, isTrue); - expect(innerElement.renderObject.attached, isTrue); + tester.pumpWidget(outer2); - inner2 = new InnerComponent(key: innerKey); - outer2 = new OuterContainer(key: outerKey, child: inner2); + expect(tester.findElementByKey(innerKey), equals(innerElement)); + expect(innerElement.state, equals(innerElementState)); - tester.pumpFrame(outer2); + expect(innerElementState.config, equals(inner2)); + expect(innerElementState._didInitState, isTrue); + expect(innerElement.renderObject.attached, isTrue); - expect(tester.findElementByKey(innerKey), equals(innerElement)); - expect(innerElement.state, equals(innerElementState)); + StatefulComponentElement outerElement = tester.findElementByKey(outerKey); + expect(outerElement.state.config, equals(outer2)); + outerElement.state.setState(() {}); + tester.pump(); - expect(innerElementState.config, equals(inner2)); - expect(innerElementState._didInitState, isTrue); - expect(innerElement.renderObject.attached, isTrue); - - StatefulComponentElement outerElement = tester.findElementByKey(outerKey); - expect(outerElement.state.config, equals(outer2)); - outerElement.state.setState(() {}); - tester.pumpFrameWithoutChange(0.0); - - expect(tester.findElementByKey(innerKey), equals(innerElement)); - expect(innerElement.state, equals(innerElementState)); - expect(innerElementState.config, equals(inner2)); - expect(innerElement.renderObject.attached, isTrue); + expect(tester.findElementByKey(innerKey), equals(innerElement)); + expect(innerElement.state, equals(innerElementState)); + expect(innerElementState.config, equals(inner2)); + expect(innerElement.renderObject.attached, isTrue); + }); }); } diff --git a/sky/unit/test/widget/syncing_test.dart b/sky/unit/test/widget/syncing_test.dart index e88d1fca72c..c8849b6cf8f 100644 --- a/sky/unit/test/widget/syncing_test.dart +++ b/sky/unit/test/widget/syncing_test.dart @@ -37,164 +37,160 @@ class TestWidgetState extends State { void main() { test('no change', () { - WidgetTester tester = new WidgetTester(); - - tester.pumpFrame( - new Container( - child: new Container( - child: new TestWidget( - persistentState: 1, - child: new Container() + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Container( + child: new Container( + child: new TestWidget( + persistentState: 1, + child: new Container() + ) ) ) - ) - ); + ); - TestWidgetState state = tester.findStateOfType(TestWidgetState); + TestWidgetState state = tester.findStateOfType(TestWidgetState); - expect(state.persistentState, equals(1)); - expect(state.updates, equals(0)); + expect(state.persistentState, equals(1)); + expect(state.updates, equals(0)); - tester.pumpFrame( - new Container( - child: new Container( - child: new TestWidget( - persistentState: 2, - child: new Container() + tester.pumpWidget( + new Container( + child: new Container( + child: new TestWidget( + persistentState: 2, + child: new Container() + ) ) ) - ) - ); + ); - expect(state.persistentState, equals(1)); - expect(state.updates, equals(1)); + expect(state.persistentState, equals(1)); + expect(state.updates, equals(1)); - tester.pumpFrame(new Container()); + tester.pumpWidget(new Container()); + }); }); test('remove one', () { + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new Container( + child: new Container( + child: new TestWidget( + persistentState: 10, + child: new Container() + ) + ) + ) + ); - WidgetTester tester = new WidgetTester(); + TestWidgetState state = tester.findStateOfType(TestWidgetState); - tester.pumpFrame( - new Container( - child: new Container( + expect(state.persistentState, equals(10)); + expect(state.updates, equals(0)); + + tester.pumpWidget( + new Container( child: new TestWidget( - persistentState: 10, + persistentState: 11, child: new Container() ) ) - ) - ); + ); - TestWidgetState state = tester.findStateOfType(TestWidgetState); + state = tester.findStateOfType(TestWidgetState); - expect(state.persistentState, equals(10)); - expect(state.updates, equals(0)); + expect(state.persistentState, equals(11)); + expect(state.updates, equals(0)); - tester.pumpFrame( - new Container( - child: new TestWidget( - persistentState: 11, - child: new Container() - ) - ) - ); - - state = tester.findStateOfType(TestWidgetState); - - expect(state.persistentState, equals(11)); - expect(state.updates, equals(0)); - - tester.pumpFrame(new Container()); + tester.pumpWidget(new Container()); + }); }); test('swap instances around', () { + testWidgets((WidgetTester tester) { + Widget a = new TestWidget(persistentState: 0x61, syncedState: 0x41, child: new Text('apple')); + Widget b = new TestWidget(persistentState: 0x62, syncedState: 0x42, child: new Text('banana')); + tester.pumpWidget(new Column([])); - WidgetTester tester = new WidgetTester(); + GlobalKey keyA = new GlobalKey(); + GlobalKey keyB = new GlobalKey(); - Widget a = new TestWidget(persistentState: 0x61, syncedState: 0x41, child: new Text('apple')); - Widget b = new TestWidget(persistentState: 0x62, syncedState: 0x42, child: new Text('banana')); - tester.pumpFrame(new Column([])); + tester.pumpWidget( + new Column([ + new Container( + key: keyA, + child: a + ), + new Container( + key: keyB, + child: b + ) + ]) + ); - GlobalKey keyA = new GlobalKey(); - GlobalKey keyB = new GlobalKey(); + TestWidgetState first, second; - tester.pumpFrame( - new Column([ - new Container( - key: keyA, - child: a - ), - new Container( - key: keyB, - child: b - ) - ]) - ); + first = tester.findStateByConfig(a); + second = tester.findStateByConfig(b); - TestWidgetState first, second; + expect(first.config, equals(a)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x41)); + expect(second.config, equals(b)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x42)); - first = tester.findStateByConfig(a); - second = tester.findStateByConfig(b); + tester.pumpWidget( + new Column([ + new Container( + key: keyA, + child: a + ), + new Container( + key: keyB, + child: b + ) + ]) + ); - expect(first.config, equals(a)); - expect(first.persistentState, equals(0x61)); - expect(first.syncedState, equals(0x41)); - expect(second.config, equals(b)); - expect(second.persistentState, equals(0x62)); - expect(second.syncedState, equals(0x42)); + first = tester.findStateByConfig(a); + second = tester.findStateByConfig(b); - tester.pumpFrame( - new Column([ - new Container( - key: keyA, - child: a - ), - new Container( - key: keyB, - child: b - ) - ]) - ); + // same as before + expect(first.config, equals(a)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x41)); + expect(second.config, equals(b)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x42)); - first = tester.findStateByConfig(a); - second = tester.findStateByConfig(b); + // now we swap the nodes over + // since they are both "old" nodes, they shouldn't sync with each other even though they look alike - // same as before - expect(first.config, equals(a)); - expect(first.persistentState, equals(0x61)); - expect(first.syncedState, equals(0x41)); - expect(second.config, equals(b)); - expect(second.persistentState, equals(0x62)); - expect(second.syncedState, equals(0x42)); + tester.pumpWidget( + new Column([ + new Container( + key: keyA, + child: b + ), + new Container( + key: keyB, + child: a + ) + ]) + ); - // now we swap the nodes over - // since they are both "old" nodes, they shouldn't sync with each other even though they look alike - - tester.pumpFrame( - new Column([ - new Container( - key: keyA, - child: b - ), - new Container( - key: keyB, - child: a - ) - ]) - ); - - first = tester.findStateByConfig(b); - second = tester.findStateByConfig(a); - - expect(first.config, equals(b)); - expect(first.persistentState, equals(0x61)); - expect(first.syncedState, equals(0x42)); - expect(second.config, equals(a)); - expect(second.persistentState, equals(0x62)); - expect(second.syncedState, equals(0x41)); + first = tester.findStateByConfig(b); + second = tester.findStateByConfig(a); + expect(first.config, equals(b)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x42)); + expect(second.config, equals(a)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x41)); + }); }); - } diff --git a/sky/unit/test/widget/transform_test.dart b/sky/unit/test/widget/transform_test.dart index ba92424faf4..1fff18fe1cd 100644 --- a/sky/unit/test/widget/transform_test.dart +++ b/sky/unit/test/widget/transform_test.dart @@ -5,47 +5,47 @@ import 'widget_tester.dart'; void main() { test('Transform origin', () { - WidgetTester tester = new WidgetTester(); - - bool didReceiveTap = false; - tester.pumpFrame( - new Stack([ - new Positioned( - top: 100.0, - left: 100.0, - child: new Container( - width: 100.0, - height: 100.0, - decoration: new BoxDecoration( - backgroundColor: new Color(0xFF0000FF) + testWidgets((WidgetTester tester) { + bool didReceiveTap = false; + tester.pumpWidget( + new Stack([ + new Positioned( + top: 100.0, + left: 100.0, + child: new Container( + width: 100.0, + height: 100.0, + decoration: new BoxDecoration( + backgroundColor: new Color(0xFF0000FF) + ) ) - ) - ), - new Positioned( - top: 100.0, - left: 100.0, - child: new Container( - width: 100.0, - height: 100.0, - child: new Transform( - transform: new Matrix4.identity().scale(0.5, 0.5), - origin: new Offset(100.0, 50.0), - child: new GestureDetector( - onTap: () { - didReceiveTap = true; - }, - child: new Container() + ), + new Positioned( + top: 100.0, + left: 100.0, + child: new Container( + width: 100.0, + height: 100.0, + child: new Transform( + transform: new Matrix4.identity().scale(0.5, 0.5), + origin: new Offset(100.0, 50.0), + child: new GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: new Container() + ) ) ) ) - ) - ]) - ); + ]) + ); - expect(didReceiveTap, isFalse); - tester.tapAt(new Point(110.0, 110.0)); - expect(didReceiveTap, isFalse); - tester.tapAt(new Point(190.0, 150.0)); - expect(didReceiveTap, isTrue); + expect(didReceiveTap, isFalse); + tester.tapAt(new Point(110.0, 110.0)); + expect(didReceiveTap, isFalse); + tester.tapAt(new Point(190.0, 150.0)); + expect(didReceiveTap, isTrue); + }); }); } diff --git a/sky/unit/test/widget/widget_tester.dart b/sky/unit/test/widget/widget_tester.dart index 0068a147198..465a14094ec 100644 --- a/sky/unit/test/widget/widget_tester.dart +++ b/sky/unit/test/widget/widget_tester.dart @@ -3,6 +3,8 @@ import 'dart:sky' as sky; import 'package:sky/animation.dart'; import 'package:sky/rendering.dart'; import 'package:sky/widgets.dart'; +import 'package:quiver/testing/async.dart'; +import 'package:quiver/time.dart'; import '../engine/mock_events.dart'; @@ -24,21 +26,24 @@ class RootComponentState extends State { } 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); - scheduler.beginFrame(frameTimeMs); + pump(duration); } - void pumpFrameWithoutChange([ double frameTimeMs = 0.0 ]) { - scheduler.beginFrame(frameTimeMs); - } - - void reset() { - runApp(new Container()); - scheduler.beginFrame(0.0); + void pump([ Duration duration ]) { + if (duration != null) + async.elapse(duration); + scheduler.beginFrame(clock.now().millisecondsSinceEpoch.toDouble()); + async.flushMicrotasks(); } List _layers(Layer layer) { @@ -162,3 +167,9 @@ class WidgetTester { } } + +void testWidgets(callback(WidgetTester tester)) { + new FakeAsync().run((FakeAsync async) { + callback(new WidgetTester._(async)); + }); +}