title_test.dart 1.99 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_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
7
import 'package:flutter/services.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 21
    final Title widget = Title(
      child: Container(),
22 23 24 25 26 27 28 29
      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 {
30
    expect(() => Title(
31 32
      title: null,
      color: const Color(0xFF00FF00),
33
      child: Container(),
34
    ), throwsAssertionError);
35
    expect(() => Title(
36
      color: null,
37
      child: Container(),
38 39 40 41
    ), throwsAssertionError);
  });

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

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

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

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

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