error_test.dart 2.32 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12
// 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/rendering.dart';
import 'package:flutter/widgets.dart';

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 20 21 22 23 24 25 26 27 28 29 30
    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);
31

32 33 34 35 36 37 38 39 40
    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');
41
    expect(find.byType(ErrorWidget), paints
Dan Field's avatar
Dan Field committed
42
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
43 44 45 46 47 48 49 50 51 52 53 54 55 56
        ..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());
57 58
  });
}