title_test.dart 2.01 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
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
9
import 'package:flutter/services.dart';
10 11 12

void main() {
  testWidgets('toString control test', (WidgetTester tester) async {
13
    final Widget widget = Title(
14 15
      color: const Color(0xFF00FF00),
      title: 'Awesome app',
16
      child: Container(),
17 18 19
    );
    expect(widget.toString, isNot(throwsException));
  });
20 21

  testWidgets('should handle having no title', (WidgetTester tester) async {
22 23
    final Title widget = Title(
      child: Container(),
24 25 26 27 28 29 30 31
      color: const Color(0xFF00FF00),
    );
    expect(widget.toString, isNot(throwsException));
    expect(widget.title, equals(''));
    expect(widget.color, equals(const Color(0xFF00FF00)));
  });

  testWidgets('should not allow null title or color', (WidgetTester tester) async {
32
    expect(() => Title(
33 34
      title: null,
      color: const Color(0xFF00FF00),
35
      child: Container(),
36
    ), throwsAssertionError);
37
    expect(() => Title(
38
      color: null,
39
      child: Container(),
40 41 42 43
    ), throwsAssertionError);
  });

  testWidgets('should not allow non-opaque color', (WidgetTester tester) async {
44
    expect(() => Title(
45
      color: const Color(0x00000000),
46
      child: Container(),
47 48 49
    ), throwsAssertionError);
  });

50
  testWidgets('should not pass "null" to setApplicationSwitcherDescription', (WidgetTester tester) async {
51 52 53 54 55 56
    final List<MethodCall> log = <MethodCall>[];

    SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
      log.add(methodCall);
    });

57 58
    await tester.pumpWidget(Title(
      child: Container(),
59 60 61
      color: const Color(0xFF00FF00),
    ));

62 63 64 65 66
    expect(log, hasLength(1));
    expect(log.single, isMethodCall(
      'SystemChrome.setApplicationSwitcherDescription',
      arguments: <String, dynamic>{'label': '', 'primaryColor': 4278255360},
    ));
67
  });
68
}