animated_align_test.dart 5.22 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
Ian Hickson's avatar
Ian Hickson committed
8 9

void main() {
10
  testWidgetsWithLeakTracking('AnimatedAlign.debugFillProperties', (WidgetTester tester) async {
11
    const AnimatedAlign box = AnimatedAlign(
Ian Hickson's avatar
Ian Hickson committed
12 13
      alignment: Alignment.topCenter,
      curve: Curves.ease,
14
      duration: Duration(milliseconds: 200),
Ian Hickson's avatar
Ian Hickson committed
15 16 17 18
    );
    expect(box, hasOneLineDescription);
  });

19
  testWidgetsWithLeakTracking('AnimatedAlign alignment visual-to-directional animation', (WidgetTester tester) async {
20
    final Key target = UniqueKey();
Ian Hickson's avatar
Ian Hickson committed
21 22

    await tester.pumpWidget(
23
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
24
        textDirection: TextDirection.rtl,
25
        child: AnimatedAlign(
Ian Hickson's avatar
Ian Hickson committed
26 27
          duration: const Duration(milliseconds: 200),
          alignment: Alignment.topRight,
28
          child: SizedBox(key: target, width: 100.0, height: 200.0),
Ian Hickson's avatar
Ian Hickson committed
29 30 31 32 33 34 35 36
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(100.0, 200.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 0.0));

    await tester.pumpWidget(
37
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
38
        textDirection: TextDirection.rtl,
39
        child: AnimatedAlign(
Ian Hickson's avatar
Ian Hickson committed
40 41
          duration: const Duration(milliseconds: 200),
          alignment: AlignmentDirectional.bottomStart,
42
          child: SizedBox(key: target, width: 100.0, height: 200.0),
Ian Hickson's avatar
Ian Hickson committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(100.0, 200.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 0.0));

    await tester.pump(const Duration(milliseconds: 100));

    expect(tester.getSize(find.byKey(target)), const Size(100.0, 200.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 200.0));

    await tester.pump(const Duration(milliseconds: 500));

    expect(tester.getSize(find.byKey(target)), const Size(100.0, 200.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 400.0));
  });
60

61
  testWidgetsWithLeakTracking('AnimatedAlign widthFactor', (WidgetTester tester) async {
62
    await tester.pumpWidget(
63
      const Directionality(
64 65 66
        textDirection: TextDirection.ltr,
        child: Row(
          mainAxisSize: MainAxisSize.min,
67
          children: <Widget>[
68 69 70 71
            AnimatedAlign(
              alignment: Alignment.center,
              curve: Curves.ease,
              widthFactor: 0.5,
72 73
              duration: Duration(milliseconds: 200),
              child: SizedBox(
74 75 76 77 78 79 80 81 82 83 84 85
                height: 100.0,
                width: 100.0,
              ),
            ),
          ],
        ),
      ),
    );
    final RenderBox box = tester.renderObject<RenderBox>(find.byType(AnimatedAlign));
    expect(box.size.width, equals(50.0));
  });

86
  testWidgetsWithLeakTracking('AnimatedAlign heightFactor', (WidgetTester tester) async {
87
    await tester.pumpWidget(
88
      const Directionality(
89 90
        textDirection: TextDirection.ltr,
        child: Column(
91
          children: <Widget>[
92 93 94 95
            AnimatedAlign(
              alignment: Alignment.center,
              curve: Curves.ease,
              heightFactor: 0.5,
96 97
              duration: Duration(milliseconds: 200),
              child: SizedBox(
98 99 100 101 102 103 104 105 106 107 108 109
                height: 100.0,
                width: 100.0,
              ),
            ),
          ],
        ),
      ),
    );
    final RenderBox box = tester.renderObject<RenderBox>(find.byType(AnimatedAlign));
    expect(box.size.height, equals( 50.0));
  });

110
  testWidgetsWithLeakTracking('AnimatedAlign null height factor', (WidgetTester tester) async {
111
    await tester.pumpWidget(
112
      const Directionality(
113 114 115
        textDirection: TextDirection.ltr,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
116
          children: <Widget>[
117 118 119
            AnimatedAlign(
              alignment: Alignment.center,
              curve: Curves.ease,
120 121
              duration: Duration(milliseconds: 200),
              child: SizedBox(
122 123 124 125 126 127 128 129
                height: 100.0,
                width: 100.0,
              ),
            ),
          ],
        ),
      ),
    );
130
    final RenderBox box = tester.renderObject<RenderBox>(find.byType(SizedBox));
131 132 133
    expect(box.size, equals(const Size(100.0, 100)));
  });

134
  testWidgetsWithLeakTracking('AnimatedAlign null widthFactor', (WidgetTester tester) async {
135
    await tester.pumpWidget(
136
      const Directionality(
137 138 139 140 141
        textDirection: TextDirection.ltr,
        child: SizedBox.shrink(
          child: Row(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
142
            children: <Widget>[
143 144 145
               AnimatedAlign(
                alignment: Alignment.center,
                curve: Curves.ease,
146 147
                duration: Duration(milliseconds: 200),
                child: SizedBox(
148 149 150 151 152 153 154 155 156
                  height: 100.0,
                  width: 100.0,
                ),
              ),
            ],
          ),
        ),
      ),
    );
157
    final RenderBox box = tester.renderObject<RenderBox>(find.byType(SizedBox).last);
158 159
    expect(box.size, equals(const Size(100.0, 100)));
  });
Ian Hickson's avatar
Ian Hickson committed
160
}