align_test.dart 3.23 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/rendering.dart';
7
import 'package:flutter/widgets.dart';
Adam Barth's avatar
Adam Barth committed
8 9

void main() {
10 11
  testWidgets('Align smoke test', (WidgetTester tester) async {
    await tester.pumpWidget(
12 13
      Align(
        child: Container(),
14
        alignment: const Alignment(0.50, 0.50),
15
      ),
16
    );
Adam Barth's avatar
Adam Barth committed
17

18
    await tester.pumpWidget(
19 20
      Align(
        child: Container(),
21
        alignment: const Alignment(0.0, 0.0),
22
      ),
23
    );
Ian Hickson's avatar
Ian Hickson committed
24 25 26

    await tester.pumpWidget(
      const Align(
27
        key: GlobalObjectKey<State<StatefulWidget>>(null),
28
        alignment: Alignment.topLeft,
Ian Hickson's avatar
Ian Hickson committed
29 30 31 32
      ),
    );
    await tester.pumpWidget(const Directionality(
      textDirection: TextDirection.rtl,
33
      child: Align(
34
        key: GlobalObjectKey<State<StatefulWidget>>(null),
35
        alignment: AlignmentDirectional.topStart,
Ian Hickson's avatar
Ian Hickson committed
36 37 38 39
      ),
    ));
    await tester.pumpWidget(
      const Align(
40
        key: GlobalObjectKey<State<StatefulWidget>>(null),
41
        alignment: Alignment.topLeft,
Ian Hickson's avatar
Ian Hickson committed
42 43
      ),
    );
Adam Barth's avatar
Adam Barth committed
44
  });
45

46
  testWidgets('Align control test (LTR)', (WidgetTester tester) async {
47
    await tester.pumpWidget(Directionality(
48
      textDirection: TextDirection.ltr,
49 50
      child: Align(
        child: Container(width: 100.0, height: 80.0),
51
        alignment: AlignmentDirectional.topStart,
52 53 54 55 56 57
      ),
    ));

    expect(tester.getTopLeft(find.byType(Container)).dx, 0.0);
    expect(tester.getBottomRight(find.byType(Container)).dx, 100.0);

58
    await tester.pumpWidget(Directionality(
59
      textDirection: TextDirection.ltr,
60 61
      child: Align(
        child: Container(width: 100.0, height: 80.0),
62
        alignment: Alignment.topLeft,
63 64 65 66 67 68 69 70
      ),
    ));

    expect(tester.getTopLeft(find.byType(Container)).dx, 0.0);
    expect(tester.getBottomRight(find.byType(Container)).dx, 100.0);
  });

  testWidgets('Align control test (RTL)', (WidgetTester tester) async {
71
    await tester.pumpWidget(Directionality(
72
      textDirection: TextDirection.rtl,
73 74
      child: Align(
        child: Container(width: 100.0, height: 80.0),
75
        alignment: AlignmentDirectional.topStart,
76 77 78 79 80 81
      ),
    ));

    expect(tester.getTopLeft(find.byType(Container)).dx, 700.0);
    expect(tester.getBottomRight(find.byType(Container)).dx, 800.0);

82
    await tester.pumpWidget(Directionality(
83
      textDirection: TextDirection.ltr,
84 85
      child: Align(
        child: Container(width: 100.0, height: 80.0),
86
        alignment: Alignment.topLeft,
87 88 89 90 91 92 93
      ),
    ));

    expect(tester.getTopLeft(find.byType(Container)).dx, 0.0);
    expect(tester.getBottomRight(find.byType(Container)).dx, 100.0);
  });

94
  testWidgets('Shrink wraps in finite space', (WidgetTester tester) async {
95
    final GlobalKey alignKey = GlobalKey();
96
    await tester.pumpWidget(
97 98
      SingleChildScrollView(
        child: Align(
99
          key: alignKey,
100
          child: Container(
101 102 103
            width: 10.0,
            height: 10.0
          ),
104
          alignment: const Alignment(0.0, 0.0),
105 106
        ),
      ),
107
    );
108

109 110 111
    final Size size = alignKey.currentContext.size;
    expect(size.width, equals(800.0));
    expect(size.height, equals(10.0));
112
  });
Adam Barth's avatar
Adam Barth committed
113
}