Add package:flutter_test
This package contains WidgetTester, which is very useful when writing tests for widgets.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
import '../../test/widget/widget_tester.dart';
|
||||
|
||||
const int _kNumberOfIterations = 50000;
|
||||
const bool _kRunForever = false;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
import '../../test/widget/widget_tester.dart';
|
||||
|
||||
const int _kNumberOfIterations = 100000;
|
||||
const bool _kRunForever = false;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
import '../../test/widget/widget_tester.dart';
|
||||
|
||||
const int _kNumberOfIterations = 100000;
|
||||
const bool _kRunForever = false;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
name: flutter_unit_tests
|
||||
dependencies:
|
||||
test: ^0.12.5
|
||||
quiver: ^0.21.4
|
||||
flx:
|
||||
path: ../flx
|
||||
flutter:
|
||||
path: ../flutter
|
||||
flutter_test:
|
||||
path: ../flutter_test
|
||||
stocks:
|
||||
path: ../../examples/stocks
|
||||
# To ensure the version of test doesn't get out of sync.
|
||||
flutter_tools:
|
||||
path: ../flutter_tools
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
export 'dart:ui' show Point;
|
||||
|
||||
class TestPointer {
|
||||
TestPointer([ this.pointer = 1 ]);
|
||||
|
||||
int pointer;
|
||||
bool isDown = false;
|
||||
ui.Point location;
|
||||
|
||||
PointerInputEvent down(ui.Point newLocation, { Duration timeStamp: const Duration() }) {
|
||||
assert(!isDown);
|
||||
isDown = true;
|
||||
location = newLocation;
|
||||
return new PointerInputEvent(
|
||||
type: 'pointerdown',
|
||||
pointer: pointer,
|
||||
x: location.x,
|
||||
y: location.y,
|
||||
timeStamp: timeStamp
|
||||
);
|
||||
}
|
||||
|
||||
PointerInputEvent move(ui.Point newLocation, { Duration timeStamp: const Duration() }) {
|
||||
assert(isDown);
|
||||
ui.Offset delta = newLocation - location;
|
||||
location = newLocation;
|
||||
return new PointerInputEvent(
|
||||
type: 'pointermove',
|
||||
pointer: pointer,
|
||||
x: newLocation.x,
|
||||
y: newLocation.y,
|
||||
dx: delta.dx,
|
||||
dy: delta.dy,
|
||||
timeStamp: timeStamp
|
||||
);
|
||||
}
|
||||
|
||||
PointerInputEvent up({ Duration timeStamp: const Duration() }) {
|
||||
assert(isDown);
|
||||
isDown = false;
|
||||
return new PointerInputEvent(
|
||||
type: 'pointerup',
|
||||
pointer: pointer,
|
||||
x: location.x,
|
||||
y: location.y,
|
||||
timeStamp: timeStamp
|
||||
);
|
||||
}
|
||||
|
||||
PointerInputEvent cancel({ Duration timeStamp: const Duration() }) {
|
||||
assert(isDown);
|
||||
isDown = false;
|
||||
return new PointerInputEvent(
|
||||
type: 'pointercancel',
|
||||
pointer: pointer,
|
||||
x: location.x,
|
||||
y: location.y,
|
||||
timeStamp: timeStamp
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
|
||||
void main() {
|
||||
test('Should route pointers', () {
|
||||
bool callbackRan = false;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
|
||||
void main() {
|
||||
test('Should recognize scale gestures', () {
|
||||
PointerRouter router = new PointerRouter();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
|
||||
void main() {
|
||||
test('Should recognize pan', () {
|
||||
PointerRouter router = new PointerRouter();
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Align smoke test', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
// 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/animation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('AnimatedContainer control test', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
final Key blockKey = new Key('test');
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Verify that a tap dismisses a modal BottomSheet', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
@@ -79,7 +78,7 @@ void main() {
|
||||
expect(showBottomSheetThenCalled, isFalse);
|
||||
expect(tester.findText('BottomSheet'), isNull);
|
||||
|
||||
scaffoldKey.currentState.showBottomSheet((BuildContext context) {
|
||||
scaffoldKey.currentState.showBottomSheet((BuildContext context) {
|
||||
return new Container(
|
||||
margin: new EdgeDims.all(40.0),
|
||||
child: new Text('BottomSheet')
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Circles can have uniform borders', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// 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/animation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import 'test_widgets.dart';
|
||||
|
||||
class ProbeWidget extends StatefulComponent {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Can be placed in an infinte box', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Comparing coordinates', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestMultiChildLayoutDelegate extends MultiChildLayoutDelegate {
|
||||
BoxConstraints getSizeConstraints;
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestOneChildLayoutDelegate extends OneChildLayoutDelegate {
|
||||
BoxConstraints constraintsFromGetSize;
|
||||
BoxConstraints constraintsFromGetConstraintsForChild;
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Can select a day', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const double itemExtent = 100.0;
|
||||
ScrollDirection scrollDirection = ScrollDirection.vertical;
|
||||
DismissDirection dismissDirection = DismissDirection.horizontal;
|
||||
@@ -284,4 +282,3 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Drag and drop - control test', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
test('Drawer control test', () {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class Item {
|
||||
GlobalKey key1 = new GlobalKey();
|
||||
GlobalKey key2 = new GlobalKey();
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Can hit test flex children of stacks', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestFocusable extends StatelessComponent {
|
||||
TestFocusable(this.no, this.yes, GlobalKey key) : super(key: key);
|
||||
final String no;
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('FractionallySizedBox', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Uncontested scrolls start immediately', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_matchers.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
Key firstKey = new Key('first');
|
||||
Key secondKey = new Key('second');
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import 'test_widgets.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
List<String> ancestors = <String>[];
|
||||
|
||||
class TestComponent extends StatefulComponent {
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:mojo_services/keyboard/keyboard.mojom.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mojo_services/keyboard/keyboard.mojom.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import '../services/mock_services.dart';
|
||||
|
||||
class MockKeyboard implements KeyboardService {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Events bubble up the tree', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import 'test_widgets.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_widgets.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
|
||||
MultiChildRenderObjectElement element =
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class FirstComponent extends StatelessComponent {
|
||||
Widget build(BuildContext context) {
|
||||
return new GestureDetector(
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_matchers.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestOverlayRoute extends OverlayRoute {
|
||||
List<WidgetBuilder> get builders => <WidgetBuilder>[ _build ];
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const Size pageSize = const Size(800.0, 600.0);
|
||||
const List<int> pages = const <int>[0, 1, 2, 3, 4, 5];
|
||||
int currentPage = null;
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'test_widgets.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestParentData {
|
||||
TestParentData({ this.top, this.right, this.bottom, this.left });
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
// 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/animation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
test('Can animate position data', () {
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('LinearProgressIndicator changes when its value changes', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/animation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class ThePositiveNumbers extends ScrollableWidgetList {
|
||||
ThePositiveNumbers() : super(itemExtent: 100.0);
|
||||
ThePositiveNumbersState createState() => new ThePositiveNumbersState();
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
final BoxDecoration kBoxDecorationA = new BoxDecoration();
|
||||
final BoxDecoration kBoxDecorationB = new BoxDecoration();
|
||||
final BoxDecoration kBoxDecorationC = new BoxDecoration();
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class StateMarker extends StatefulComponent {
|
||||
StateMarker({ Key key, this.child }) : super(key: key);
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
|
||||
List<int> tapped = <int>[];
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
|
||||
|
||||
Widget buildFrame() {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
|
||||
|
||||
Widget buildFrame() {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
List<int> items = <int>[0, 1, 2, 3, 4, 5];
|
||||
|
||||
Widget buildCard(BuildContext context, int index) {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
ChangerState changer;
|
||||
|
||||
class Changer extends StatefulComponent {
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class Inside extends StatefulComponent {
|
||||
InsideState createState() => new InsideState();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
ui.Shader createShader(Rect bounds) {
|
||||
return new LinearGradient(
|
||||
begin: Point.origin,
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('SizeObserver notices zero size', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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/material.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class Builder extends StatelessComponent {
|
||||
Builder({ this.builder });
|
||||
final WidgetBuilder builder;
|
||||
@@ -55,7 +54,7 @@ void main() {
|
||||
expect(tester.findText(helloSnackBar), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 1.50s
|
||||
expect(tester.findText(helloSnackBar), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
expect(tester.findText(helloSnackBar), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 3.00s // timer triggers to dismiss snackbar, reverse animation is scheduled
|
||||
tester.pump(); // begin animation
|
||||
@@ -114,7 +113,7 @@ void main() {
|
||||
tester.pump(new Duration(milliseconds: 750)); // 1.50s
|
||||
expect(tester.findText('bar1'), isNotNull);
|
||||
expect(tester.findText('bar2'), isNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
expect(tester.findText('bar1'), isNotNull);
|
||||
expect(tester.findText('bar2'), isNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 3.00s // timer triggers to dismiss snackbar, reverse animation is scheduled
|
||||
@@ -133,7 +132,7 @@ void main() {
|
||||
tester.pump(new Duration(milliseconds: 750)); // 5.25s
|
||||
expect(tester.findText('bar1'), isNull);
|
||||
expect(tester.findText('bar2'), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 6.00s
|
||||
tester.pump(new Duration(milliseconds: 750)); // 6.00s
|
||||
expect(tester.findText('bar1'), isNull);
|
||||
expect(tester.findText('bar2'), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 6.75s // timer triggers to dismiss snackbar, reverse animation is scheduled
|
||||
@@ -200,10 +199,10 @@ void main() {
|
||||
tester.pump(new Duration(milliseconds: 750)); // 1.50s
|
||||
expect(tester.findText('bar1'), isNotNull);
|
||||
expect(tester.findText('bar2'), isNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
tester.pump(new Duration(milliseconds: 750)); // 2.25s
|
||||
expect(tester.findText('bar1'), isNotNull);
|
||||
expect(tester.findText('bar2'), isNull);
|
||||
tester.pump(new Duration(milliseconds: 10000)); // 12.25s
|
||||
tester.pump(new Duration(milliseconds: 10000)); // 12.25s
|
||||
expect(tester.findText('bar1'), isNotNull);
|
||||
expect(tester.findText('bar2'), isNull);
|
||||
|
||||
@@ -225,7 +224,7 @@ void main() {
|
||||
tester.pump(new Duration(milliseconds: 750)); // 15.25s
|
||||
expect(tester.findText('bar1'), isNull);
|
||||
expect(tester.findText('bar2'), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 16.00s
|
||||
tester.pump(new Duration(milliseconds: 750)); // 16.00s
|
||||
expect(tester.findText('bar1'), isNull);
|
||||
expect(tester.findText('bar2'), isNotNull);
|
||||
tester.pump(new Duration(milliseconds: 750)); // 16.75s // timer triggers to dismiss snackbar, reverse animation is scheduled
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
const double itemExtent = 200.0;
|
||||
ScrollDirection scrollDirection = ScrollDirection.vertical;
|
||||
GlobalKey scrollableListKey;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import '../rendering/rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// 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/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
import 'test_widgets.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class InnerComponent extends StatefulComponent {
|
||||
InnerComponent({ Key key }) : super(key: key);
|
||||
InnerComponentState createState() => new InnerComponentState();
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
class TestWidget extends StatefulComponent {
|
||||
TestWidget({ this.child, this.persistentState, this.syncedState });
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// 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/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
int selectedIndex = 2;
|
||||
|
||||
Widget buildFrame({ List<String> tabs, bool isScrollable: false }) {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
final BoxDecoration kBoxDecorationA = new BoxDecoration(
|
||||
backgroundColor: const Color(0xFFFF0000)
|
||||
);
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Transform origin', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
// 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 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:quiver/testing/async.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
|
||||
class RootComponent extends StatefulComponent {
|
||||
RootComponentState createState() => new RootComponentState();
|
||||
}
|
||||
|
||||
class RootComponentState extends State<RootComponent> {
|
||||
Widget _child = new DecoratedBox(decoration: new BoxDecoration());
|
||||
Widget get child => _child;
|
||||
void set child(Widget value) {
|
||||
if (value != _child) {
|
||||
setState(() {
|
||||
_child = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
Widget build(BuildContext context) => child;
|
||||
}
|
||||
|
||||
typedef Point SizeToPointFunction(Size size);
|
||||
|
||||
class WidgetTester {
|
||||
WidgetTester._(FakeAsync async)
|
||||
: async = async,
|
||||
clock = async.getClock(new DateTime.utc(2015, 1, 1)) {
|
||||
timeDilation = 1.0;
|
||||
ui.window.onBeginFrame = null;
|
||||
}
|
||||
|
||||
final FakeAsync async;
|
||||
final Clock clock;
|
||||
|
||||
void pumpWidget(Widget widget, [ Duration duration ]) {
|
||||
runApp(widget);
|
||||
pump(duration);
|
||||
}
|
||||
|
||||
void pump([ Duration duration ]) {
|
||||
if (duration != null)
|
||||
async.elapse(duration);
|
||||
scheduler.beginFrame(new Duration(milliseconds: clock.now().millisecondsSinceEpoch));
|
||||
async.flushMicrotasks();
|
||||
}
|
||||
|
||||
List<Layer> _layers(Layer layer) {
|
||||
List<Layer> result = <Layer>[layer];
|
||||
if (layer is ContainerLayer) {
|
||||
ContainerLayer root = layer;
|
||||
Layer child = root.firstChild;
|
||||
while (child != null) {
|
||||
result.addAll(_layers(child));
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
List<Layer> get layers => _layers(FlutterBinding.instance.renderView.layer);
|
||||
|
||||
|
||||
void walkElements(ElementVisitor visitor) {
|
||||
void walk(Element element) {
|
||||
visitor(element);
|
||||
element.visitChildren(walk);
|
||||
}
|
||||
WidgetFlutterBinding.instance.renderViewElement.visitChildren(walk);
|
||||
}
|
||||
|
||||
Element findElement(bool predicate(Element element)) {
|
||||
try {
|
||||
walkElements((Element element) {
|
||||
if (predicate(element))
|
||||
throw element;
|
||||
});
|
||||
} on Element catch (e) {
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Element findElementByKey(Key key) {
|
||||
return findElement((Element element) => element.widget.key == key);
|
||||
}
|
||||
|
||||
Element findText(String text) {
|
||||
return findElement((Element element) {
|
||||
return element.widget is Text && element.widget.data == text;
|
||||
});
|
||||
}
|
||||
|
||||
State findStateOfType(Type type) {
|
||||
StatefulComponentElement element = findElement((Element element) {
|
||||
return element is StatefulComponentElement && element.state.runtimeType == type;
|
||||
});
|
||||
return element?.state;
|
||||
}
|
||||
|
||||
State findStateByConfig(Widget config) {
|
||||
StatefulComponentElement element = findElement((Element element) {
|
||||
return element is StatefulComponentElement && element.state.config == config;
|
||||
});
|
||||
return element?.state;
|
||||
}
|
||||
|
||||
Point getCenter(Element element) {
|
||||
return _getElementPoint(element, (Size size) => size.center(Point.origin));
|
||||
}
|
||||
|
||||
Point getTopLeft(Element element) {
|
||||
return _getElementPoint(element, (_) => Point.origin);
|
||||
}
|
||||
|
||||
Point getTopRight(Element element) {
|
||||
return _getElementPoint(element, (Size size) => size.topRight(Point.origin));
|
||||
}
|
||||
|
||||
Point getBottomLeft(Element element) {
|
||||
return _getElementPoint(element, (Size size) => size.bottomLeft(Point.origin));
|
||||
}
|
||||
|
||||
Point getBottomRight(Element element) {
|
||||
return _getElementPoint(element, (Size size) => size.bottomRight(Point.origin));
|
||||
}
|
||||
|
||||
Point _getElementPoint(Element element, SizeToPointFunction sizeToPoint) {
|
||||
assert(element != null);
|
||||
RenderBox box = element.renderObject as RenderBox;
|
||||
assert(box != null);
|
||||
return box.localToGlobal(sizeToPoint(box.size));
|
||||
}
|
||||
|
||||
|
||||
void tap(Element element, { int pointer: 1 }) {
|
||||
tapAt(getCenter(element), pointer: pointer);
|
||||
}
|
||||
|
||||
void tapAt(Point location, { int pointer: 1 }) {
|
||||
HitTestResult result = _hitTest(location);
|
||||
TestPointer p = new TestPointer(pointer);
|
||||
_dispatchEvent(p.down(location), result);
|
||||
_dispatchEvent(p.up(), result);
|
||||
}
|
||||
|
||||
void fling(Element element, Offset offset, double velocity, { int pointer: 1 }) {
|
||||
flingFrom(getCenter(element), offset, velocity, pointer: pointer);
|
||||
}
|
||||
|
||||
void flingFrom(Point startLocation, Offset offset, double velocity, { int pointer: 1 }) {
|
||||
assert(offset.distance > 0.0);
|
||||
assert(velocity != 0.0); // velocity is pixels/second
|
||||
final TestPointer p = new TestPointer(pointer);
|
||||
final HitTestResult result = _hitTest(startLocation);
|
||||
const int kMoveCount = 50; // Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
|
||||
final double timeStampDelta = 1000.0 * offset.distance / (kMoveCount * velocity);
|
||||
double timeStamp = 0.0;
|
||||
_dispatchEvent(p.down(startLocation, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
|
||||
for(int i = 0; i < kMoveCount; i++) {
|
||||
final Point location = startLocation + Offset.lerp(Offset.zero, offset, i / kMoveCount);
|
||||
_dispatchEvent(p.move(location, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
|
||||
timeStamp += timeStampDelta;
|
||||
}
|
||||
_dispatchEvent(p.up(timeStamp: new Duration(milliseconds: timeStamp.round())), result);
|
||||
}
|
||||
|
||||
void scroll(Element element, Offset offset, { int pointer: 1 }) {
|
||||
scrollAt(getCenter(element), offset, pointer: pointer);
|
||||
}
|
||||
|
||||
void scrollAt(Point startLocation, Offset offset, { int pointer: 1 }) {
|
||||
Point endLocation = startLocation + offset;
|
||||
TestPointer p = new TestPointer(pointer);
|
||||
// Events for the entire press-drag-release gesture are dispatched
|
||||
// to the widgets "hit" by the pointer down event.
|
||||
HitTestResult result = _hitTest(startLocation);
|
||||
_dispatchEvent(p.down(startLocation), result);
|
||||
_dispatchEvent(p.move(endLocation), result);
|
||||
_dispatchEvent(p.up(), result);
|
||||
}
|
||||
|
||||
void dispatchEvent(InputEvent event, Point location) {
|
||||
_dispatchEvent(event, _hitTest(location));
|
||||
}
|
||||
|
||||
HitTestResult _hitTest(Point location) => WidgetFlutterBinding.instance.hitTest(location);
|
||||
|
||||
void _dispatchEvent(InputEvent event, HitTestResult result) {
|
||||
WidgetFlutterBinding.instance.dispatchEvent(event, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void testWidgets(callback(WidgetTester tester)) {
|
||||
new FakeAsync().run((FakeAsync async) {
|
||||
callback(new WidgetTester._(async));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user