title_test.dart 1.73 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
import 'package:flutter/services.dart';
6 7
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
8 9 10

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

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

  testWidgets('should not allow non-opaque color', (WidgetTester tester) async {
30
    expect(() => Title(
31
      color: const Color(0x00000000),
32
      child: Container(),
33 34 35
    ), throwsAssertionError);
  });

36
  testWidgets('should not pass "null" to setApplicationSwitcherDescription', (WidgetTester tester) async {
37 38
    final List<MethodCall> log = <MethodCall>[];

39
    tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
40
      log.add(methodCall);
41
      return null;
42 43
    });

44
    await tester.pumpWidget(Title(
45
      color: const Color(0xFF00FF00),
46
      child: Container(),
47 48
    ));

49 50 51 52 53
    expect(log, hasLength(1));
    expect(log.single, isMethodCall(
      'SystemChrome.setApplicationSwitcherDescription',
      arguments: <String, dynamic>{'label': '', 'primaryColor': 4278255360},
    ));
54
  });
55
}