mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

- force the time dilation to 1.0 for the Widget tests, so that a local change doesn't break all the tests during development. - add missing license block to all the files. - set ui.window.onBeginFrame to null when you use WidgetTester, so that the engine doesn't trigger any confusing frames after our fake frames.
75 lines
2.3 KiB
Dart
75 lines
2.3 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/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) {
|
|
TestPointer pointer = new TestPointer(7);
|
|
|
|
List accepted = [];
|
|
|
|
tester.pumpWidget(new MaterialApp(
|
|
routes: <String, RouteBuilder>{
|
|
'/': (RouteArguments args) { return new Column(<Widget>[
|
|
new Draggable(
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
});
|
|
});
|
|
}
|