error_test.dart 2.39 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

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

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

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

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

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

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

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

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

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