align_test.dart 2.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/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
      new Align(
        child: new Container(),
14 15
        alignment: const FractionalOffset(0.75, 0.75),
      ),
16
    );
Adam Barth's avatar
Adam Barth committed
17

18
    await tester.pumpWidget(
19 20
      new Align(
        child: new Container(),
21 22
        alignment: const FractionalOffset(0.5, 0.5),
      ),
23
    );
Adam Barth's avatar
Adam Barth committed
24
  });
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  testWidgets('Align control test (LTR)', (WidgetTester tester) async {
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Align(
        child: new Container(width: 100.0, height: 80.0),
        alignment: FractionalOffsetDirectional.topStart,
      ),
    ));

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

    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Align(
        child: new Container(width: 100.0, height: 80.0),
        alignment: FractionalOffset.topLeft,
      ),
    ));

    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 {
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.rtl,
      child: new Align(
        child: new Container(width: 100.0, height: 80.0),
        alignment: FractionalOffsetDirectional.topStart,
      ),
    ));

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

    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Align(
        child: new Container(width: 100.0, height: 80.0),
        alignment: FractionalOffset.topLeft,
      ),
    ));

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

74
  testWidgets('Shrink wraps in finite space', (WidgetTester tester) async {
75
    final GlobalKey alignKey = new GlobalKey();
76
    await tester.pumpWidget(
77
      new SingleChildScrollView(
78 79 80 81 82 83
        child: new Align(
          key: alignKey,
          child: new Container(
            width: 10.0,
            height: 10.0
          ),
84 85 86
          alignment: const FractionalOffset(0.50, 0.50),
        ),
      ),
87
    );
88

89 90 91
    final Size size = alignKey.currentContext.size;
    expect(size.width, equals(800.0));
    expect(size.height, equals(10.0));
92
  });
Adam Barth's avatar
Adam Barth committed
93
}