block_test.dart 1.97 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 9 10

final Key blockKey = new Key('test');

void main() {
  test('Cannot scroll a non-overflowing block', () {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    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

      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));

      expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isTrue);

      tester.dispatchEvent(pointer.up(), target);
    });
Hixie's avatar
Hixie committed
35 36 37
  });

  test('Can scroll an overflowing block', () {
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    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

      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));

      expect(tester.getCenter(tester.findText('Hello')) == middleOfContainer, isFalse);

      tester.dispatchEvent(pointer.up(), target);
    });
Hixie's avatar
Hixie committed
62 63
  });
}