constrained_box_test.dart 6.76 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

void main() {
  testWidgets('Placeholder intrinsics', (WidgetTester tester) async {
    await tester.pumpWidget(const Placeholder());
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });

  testWidgets('ConstrainedBox intrinsics - minHeight', (WidgetTester tester) async {
    await tester.pumpWidget(
19
      ConstrainedBox(
20 21 22 23 24 25 26 27 28 29 30 31 32 33
        constraints: const BoxConstraints(
          minHeight: 20.0,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 20.0);
  });

  testWidgets('ConstrainedBox intrinsics - minWidth', (WidgetTester tester) async {
    await tester.pumpWidget(
34
      ConstrainedBox(
35 36 37 38 39 40 41 42 43 44 45 46 47 48
        constraints: const BoxConstraints(
          minWidth: 20.0,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });

  testWidgets('ConstrainedBox intrinsics - maxHeight', (WidgetTester tester) async {
    await tester.pumpWidget(
49
      ConstrainedBox(
50 51 52 53 54 55 56 57 58 59 60 61 62 63
        constraints: const BoxConstraints(
          maxHeight: 20.0,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });

  testWidgets('ConstrainedBox intrinsics - maxWidth', (WidgetTester tester) async {
    await tester.pumpWidget(
64
      ConstrainedBox(
65 66 67 68 69 70 71 72 73 74 75 76 77 78
        constraints: const BoxConstraints(
          maxWidth: 20.0,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });

  testWidgets('ConstrainedBox intrinsics - tight', (WidgetTester tester) async {
    await tester.pumpWidget(
79
      ConstrainedBox(
80 81 82 83 84 85 86 87 88 89 90 91 92
        constraints: const BoxConstraints.tightFor(width: 10.0, height: 30.0),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 10.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 10.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 30.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 30.0);
  });


  testWidgets('ConstrainedBox intrinsics - minHeight - with infinite width', (WidgetTester tester) async {
    await tester.pumpWidget(
93
      ConstrainedBox(
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        constraints: const BoxConstraints(
          minWidth: double.infinity,
          minHeight: 20.0,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 20.0);
  });

  testWidgets('ConstrainedBox intrinsics - minWidth - with infinite height', (WidgetTester tester) async {
    await tester.pumpWidget(
109
      ConstrainedBox(
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        constraints: const BoxConstraints(
          minWidth: 20.0,
          minHeight: double.infinity,
        ),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 20.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });

  testWidgets('ConstrainedBox intrinsics - infinite', (WidgetTester tester) async {
    await tester.pumpWidget(
125
      ConstrainedBox(
126 127 128 129 130 131 132 133 134 135
        constraints: const BoxConstraints.tightFor(width: double.infinity, height: double.infinity),
        child: const Placeholder(),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicWidth(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMinIntrinsicHeight(double.infinity), 0.0);
    expect(tester.renderObject<RenderBox>(find.byType(ConstrainedBox)).getMaxIntrinsicHeight(double.infinity), 0.0);
  });
}