transform_test.dart 4.81 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// 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.

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
6
import 'package:flutter/widgets.dart';
7 8 9 10
import 'package:test/test.dart';

void main() {
  test('Transform origin', () {
11 12 13
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
14 15 16 17 18 19 20 21 22 23 24
        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)
                )
25
              )
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
            ),
            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)
                      )
Adam Barth's avatar
Adam Barth committed
44 45
                    )
                  )
46
                )
47 48
              )
            )
49 50
          ]
        )
51
      );
52

53 54 55 56 57 58
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
59
  });
Hixie's avatar
Hixie committed
60 61 62 63 64

  test('Transform alignment', () {
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
65 66 67 68 69 70 71 72 73 74 75
        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)
                )
Hixie's avatar
Hixie committed
76
              )
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
            ),
            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)
                      )
Adam Barth's avatar
Adam Barth committed
95 96
                    )
                  )
Hixie's avatar
Hixie committed
97 98 99
                )
              )
            )
100 101
          ]
        )
Hixie's avatar
Hixie committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115
      );

      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
  });

  test('Transform offset + alignment', () {
    testWidgets((WidgetTester tester) {
      bool didReceiveTap = false;
      tester.pumpWidget(
116 117 118 119 120 121 122 123 124 125 126
        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)
                )
Hixie's avatar
Hixie committed
127
              )
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
            ),
            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)
                      )
Adam Barth's avatar
Adam Barth committed
147 148
                    )
                  )
Hixie's avatar
Hixie committed
149 150 151
                )
              )
            )
152 153
          ]
        )
Hixie's avatar
Hixie committed
154 155 156 157 158 159 160 161 162
      );

      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(110.0, 110.0));
      expect(didReceiveTap, isFalse);
      tester.tapAt(new Point(190.0, 150.0));
      expect(didReceiveTap, isTrue);
    });
  });
163
}