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

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

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

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

  testWidgets('test draw error paragraph', (WidgetTester tester) async {
16
    await tester.pumpWidget(ErrorWidget(Exception(errorMessage)));
17 18 19
    expect(
      find.byType(ErrorWidget),
      paints
20
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
21 22
        ..paragraph(offset: const Offset(64.0, 96.0)),
    );
23

24
    final Widget error = Builder(builder: (BuildContext context) => throw 'pillow');
25

26
    await tester.pumpWidget(Center(child: SizedBox(width: 100.0, child: error)));
27
    expect(tester.takeException(), 'pillow');
28 29 30
    expect(
      find.byType(ErrorWidget),
      paints
31
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 100.0, 600.0))
32 33
        ..paragraph(offset: const Offset(0.0, 96.0)),
    );
34

35
    await tester.pumpWidget(Center(child: SizedBox(height: 100.0, child: error)));
36
    expect(tester.takeException(), null);
37

38
    await tester.pumpWidget(Center(child: SizedBox(key: UniqueKey(), height: 100.0, child: error)));
39
    expect(tester.takeException(), 'pillow');
40 41 42
    expect(
      find.byType(ErrorWidget),
      paints
43
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 100.0))
44 45
        ..paragraph(offset: const Offset(64.0, 0.0)),
    );
46 47

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

57
    await tester.pumpWidget(Center(child: error));
58
    expect(tester.takeException(), null);
59 60 61
    expect(
      find.byType(ErrorWidget),
      paints
62
        ..rect(color: const Color(0xF0900000))
63 64
        ..paragraph(),
    );
65 66

    RenderErrorBox.backgroundColor = const Color(0xFF112233);
67
    await tester.pumpWidget(Center(child: error));
68
    expect(tester.takeException(), null);
69 70 71
    expect(
      find.byType(ErrorWidget),
      paints
72
        ..rect(color: const Color(0xFF112233))
73 74
        ..paragraph(),
    );
75 76
  });
}