draggable_test.dart 2.19 KB
Newer Older
1
import 'package:sky/widgets.dart';
Hixie's avatar
Hixie committed
2 3 4
import 'package:test/test.dart';

import '../engine/mock_events.dart';
Adam Barth's avatar
Adam Barth committed
5
import 'widget_tester.dart';
Hixie's avatar
Hixie committed
6 7 8

void main() {
  test('Drag and drop - control test', () {
9 10
    testWidgets((WidgetTester tester) {
      TestPointer pointer = new TestPointer(7);
Hixie's avatar
Hixie committed
11

12
      List accepted = [];
Hixie's avatar
Hixie committed
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      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);
                }
              ),
            ]);
          },
        }
      ));
Hixie's avatar
Hixie committed
38

39 40 41 42
      expect(accepted, isEmpty);
      expect(tester.findText('Source'), isNotNull);
      expect(tester.findText('Dragging'), isNull);
      expect(tester.findText('Target'), isNotNull);
Hixie's avatar
Hixie committed
43

44 45 46
      Point firstLocation = tester.getCenter(tester.findText('Source'));
      tester.dispatchEvent(pointer.down(firstLocation), firstLocation);
      tester.pump();
Hixie's avatar
Hixie committed
47

48 49 50 51
      expect(accepted, isEmpty);
      expect(tester.findText('Source'), isNotNull);
      expect(tester.findText('Dragging'), isNotNull);
      expect(tester.findText('Target'), isNotNull);
Hixie's avatar
Hixie committed
52

53 54 55
      Point secondLocation = tester.getCenter(tester.findText('Target'));
      tester.dispatchEvent(pointer.move(secondLocation), firstLocation);
      tester.pump();
Hixie's avatar
Hixie committed
56

57 58 59 60
      expect(accepted, isEmpty);
      expect(tester.findText('Source'), isNotNull);
      expect(tester.findText('Dragging'), isNotNull);
      expect(tester.findText('Target'), isNotNull);
Hixie's avatar
Hixie committed
61

62 63
      tester.dispatchEvent(pointer.up(), firstLocation);
      tester.pump();
Hixie's avatar
Hixie committed
64

65 66 67 68 69
      expect(accepted, equals([1]));
      expect(tester.findText('Source'), isNotNull);
      expect(tester.findText('Dragging'), isNull);
      expect(tester.findText('Target'), isNotNull);
    });
Hixie's avatar
Hixie committed
70 71
  });
}