error_test.dart 2.34 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 12 13 14
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

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

/// Unit tests error.dart's usage via ErrorWidget.
void main() {
15
  const String errorMessage = 'Some error message';
16 17

  testWidgets('test draw error paragraph', (WidgetTester tester) async {
18
    await tester.pumpWidget(ErrorWidget(Exception(errorMessage)));
19 20 21 22 23 24 25 26 27 28 29 30 31 32
    expect(find.byType(ErrorWidget), paints
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
        ..paragraph(offset: const Offset(64.0, 96.0)));

    final Widget _error = Builder(builder: (BuildContext context) => throw 'pillow');

    await tester.pumpWidget(Center(child: SizedBox(width: 100.0, child: _error)));
    expect(tester.takeException(), 'pillow');
    expect(find.byType(ErrorWidget), paints
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 100.0, 600.0))
        ..paragraph(offset: const Offset(0.0, 96.0)));

    await tester.pumpWidget(Center(child: SizedBox(height: 100.0, child: _error)));
    expect(tester.takeException(), null);
33

34 35 36 37 38 39 40 41 42
    await tester.pumpWidget(Center(child: SizedBox(key: UniqueKey(), height: 100.0, child: _error)));
    expect(tester.takeException(), 'pillow');
    expect(find.byType(ErrorWidget), paints
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 100.0))
        ..paragraph(offset: const Offset(64.0, 0.0)));

    RenderErrorBox.minimumWidth = 800.0;
    await tester.pumpWidget(Center(child: _error));
    expect(tester.takeException(), 'pillow');
43
    expect(find.byType(ErrorWidget), paints
Dan Field's avatar
Dan Field committed
44
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
45 46 47 48 49 50 51 52 53 54 55 56 57 58
        ..paragraph(offset: const Offset(0.0, 96.0)));

    await tester.pumpWidget(Center(child: _error));
    expect(tester.takeException(), null);
    expect(find.byType(ErrorWidget), paints
        ..rect(color: const Color(0xF0900000))
        ..paragraph());

    RenderErrorBox.backgroundColor = const Color(0xFF112233);
    await tester.pumpWidget(Center(child: _error));
    expect(tester.takeException(), null);
    expect(find.byType(ErrorWidget), paints
        ..rect(color: const Color(0xFF112233))
        ..paragraph());
59 60
  });
}