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

5 6
// @dart = 2.8

7 8 9 10 11
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
12
  testWidgets('OverflowBox control test', (WidgetTester tester) async {
13 14
    final GlobalKey inner = GlobalKey();
    await tester.pumpWidget(Align(
15
      alignment: const Alignment(1.0, 1.0),
16
      child: SizedBox(
17 18
        width: 10.0,
        height: 20.0,
19
        child: OverflowBox(
20 21 22 23
          minWidth: 0.0,
          maxWidth: 100.0,
          minHeight: 0.0,
          maxHeight: 50.0,
24
          child: Container(
25
            key: inner
26 27 28
          ),
        ),
      ),
29
    ));
30
    final RenderBox box = inner.currentContext.findRenderObject() as RenderBox;
31
    expect(box.localToGlobal(Offset.zero), equals(const Offset(745.0, 565.0)));
32
    expect(box.size, equals(const Size(100.0, 50.0)));
33
  });
34

35
  testWidgets('OverflowBox implements debugFillProperties', (WidgetTester tester) async {
36
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
37
    const OverflowBox(
38 39 40
      minWidth: 1.0,
      maxWidth: 2.0,
      minHeight: 3.0,
41
      maxHeight: 4.0,
42 43
    ).debugFillProperties(builder);
    final List<String> description = builder.properties
44
        .where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info))
45
        .map((DiagnosticsNode n) => n.toString()).toList();
46
    expect(description, <String>[
47
      'alignment: center',
48 49 50 51 52 53
      'minWidth: 1.0',
      'maxWidth: 2.0',
      'minHeight: 3.0',
      'maxHeight: 4.0',
    ]);
  });
54 55 56 57 58 59 60 61 62 63 64 65 66

  testWidgets('SizedOverflowBox alignment', (WidgetTester tester) async {
    final GlobalKey inner = GlobalKey();
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.rtl,
      child: Center(
        child: SizedOverflowBox(
          size: const Size(100.0, 100.0),
          alignment: Alignment.topRight,
          child: Container(height: 50.0, width: 50.0, key: inner),
        ),
      ),
    ));
67
    final RenderBox box = inner.currentContext.findRenderObject() as RenderBox;
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    expect(box.size, equals(const Size(50.0, 50.0)));
    expect(
      box.localToGlobal(box.size.center(Offset.zero)),
      equals(const Offset(
        (800.0 - 100.0) / 2.0 + 100.0 - 50.0 / 2.0,
        (600.0 - 100.0) / 2.0 + 0.0 + 50.0 / 2.0,
      )),
    );
  });

  testWidgets('SizedOverflowBox alignment (direction-sensitive)', (WidgetTester tester) async {
    final GlobalKey inner = GlobalKey();
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.rtl,
      child: Center(
        child: SizedOverflowBox(
          size: const Size(100.0, 100.0),
          alignment: AlignmentDirectional.bottomStart,
          child: Container(height: 50.0, width: 50.0, key: inner),
        ),
      ),
    ));
90
    final RenderBox box = inner.currentContext.findRenderObject() as RenderBox;
91 92 93 94 95 96 97 98 99
    expect(box.size, equals(const Size(50.0, 50.0)));
    expect(
      box.localToGlobal(box.size.center(Offset.zero)),
      equals(const Offset(
        (800.0 - 100.0) / 2.0 + 100.0 - 50.0 / 2.0,
        (600.0 - 100.0) / 2.0 + 100.0 - 50.0 / 2.0,
      )),
    );
  });
100
}