debug_overflow_indicator_test.dart 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2017 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.

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

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 37 38 39
    final dynamic exception = tester.takeException();
    expect(exception, isInstanceOf<FlutterError>());
    expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
    expect(exception.diagnostics.first.toString(), startsWith('A RenderUnconstrainedBox overflowed by '));
40 41 42
    expect(find.byType(UnconstrainedBox), paints..rect());

    await tester.pumpWidget(
43
      const Center(
44
        child: SizedBox(
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
          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(
60
        child: SizedBox(
61
          height: 0.0,
62 63
          child: UnconstrainedBox(
            child: SizedBox(width: 200.0, height: 200.0),
64 65 66 67 68 69 70 71
          ),
        ),
      ),
    );

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