Ian Hickson 3252701753 Make it possible to run tests live on a device (#3936)
This makes it possible to substitute 'flutter run' for 'flutter test'
and actually watch a test run on a device.

For any test that depends on flutter_test:

1. Remove any import of 'package:test/test.dart'.

2. Replace `testWidgets('...', (WidgetTester tester) {`
      with `testWidgets('...', (WidgetTester tester) async {`

3. Add an "await" in front of calls to any of the following:
    * tap()
    * tapAt()
    * fling()
    * flingFrom()
    * scroll()
    * scrollAt()
    * pump()
    * pumpWidget()

4. Replace any calls to `tester.flushMicrotasks()` with calls to
   `await tester.idle()`.

There's a guarding API that you can use, if you have particularly
complicated tests, to get better error messages. Search for
TestAsyncUtils.
2016-05-16 12:53:13 -07:00

157 lines
4.5 KiB
Dart

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
void main() {
testWidgets('Transform origin', (WidgetTester tester) async {
bool didReceiveTap = false;
await tester.pumpWidget(
new Stack(
children: <Widget>[
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(
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF00FFFF)
)
)
)
)
)
)
]
)
);
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(110.0, 110.0));
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(190.0, 150.0));
expect(didReceiveTap, isTrue);
});
testWidgets('Transform alignment', (WidgetTester tester) async {
bool didReceiveTap = false;
await tester.pumpWidget(
new Stack(
children: <Widget>[
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),
alignment: new FractionalOffset(1.0, 0.5),
child: new GestureDetector(
onTap: () {
didReceiveTap = true;
},
child: new Container(
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF00FFFF)
)
)
)
)
)
)
]
)
);
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(110.0, 110.0));
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(190.0, 150.0));
expect(didReceiveTap, isTrue);
});
testWidgets('Transform offset + alignment', (WidgetTester tester) async {
bool didReceiveTap = false;
await tester.pumpWidget(
new Stack(
children: <Widget>[
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, 0.0),
alignment: new FractionalOffset(0.0, 0.5),
child: new GestureDetector(
onTap: () {
didReceiveTap = true;
},
child: new Container(
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF00FFFF)
)
)
)
)
)
)
]
)
);
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(110.0, 110.0));
expect(didReceiveTap, isFalse);
await tester.tapAt(new Point(190.0, 150.0));
expect(didReceiveTap, isTrue);
});
}