animated_align_test.dart 5.05 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';
Ian Hickson's avatar
Ian Hickson committed
7 8 9

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

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

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

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

    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));
  });
59 60 61 62 63 64 65

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

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

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

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