debug_overflow_indicator_test.dart 2.13 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
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';
7 8 9 10 11 12 13

import '../rendering/mock_canvas.dart';

void main() {
  testWidgets('overflow indicator is not shown when not overflowing', (WidgetTester tester) async {
    await tester.pumpWidget(
      const Center(
14 15
        child: UnconstrainedBox(
          child: SizedBox(width: 200.0, height: 200.0),
16 17 18 19 20 21 22 23
        ),
      ),
    );

    expect(find.byType(UnconstrainedBox), isNot(paints..rect()));
  });

  testWidgets('overflow indicator is shown when overflowing', (WidgetTester tester) async {
24 25
    const UnconstrainedBox box = UnconstrainedBox(
      child: SizedBox(width: 200.0, height: 200.0),
26 27
    );
    await tester.pumpWidget(
28
      const Center(
29
        child: SizedBox(
30 31 32 33 34 35
          height: 100.0,
          child: box,
        ),
      ),
    );

36
    final dynamic exception = tester.takeException();
Dan Field's avatar
Dan Field committed
37
    expect(exception, isFlutterError);
38
    // ignore: avoid_dynamic_calls
39
    expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
40
    // ignore: avoid_dynamic_calls
41
    expect(exception.diagnostics.first.toString(), startsWith('A RenderConstraintsTransformBox overflowed by '));
42 43 44
    expect(find.byType(UnconstrainedBox), paints..rect());

    await tester.pumpWidget(
45
      const Center(
46
        child: SizedBox(
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
          height: 100.0,
          child: box,
        ),
      ),
    );

    // Doesn't throw the exception a second time, because we didn't reset
    // overflowReportNeeded.
    expect(tester.takeException(), isNull);
    expect(find.byType(UnconstrainedBox), paints..rect());
  });

  testWidgets('overflow indicator is not shown when constraint size is zero.', (WidgetTester tester) async {
    await tester.pumpWidget(
      const Center(
62
        child: SizedBox(
63
          height: 0.0,
64 65
          child: UnconstrainedBox(
            child: SizedBox(width: 200.0, height: 200.0),
66 67 68 69 70 71 72 73
          ),
        ),
      ),
    );

    expect(find.byType(UnconstrainedBox), isNot(paints..rect()));
  });
}