title_test.dart 2.04 KB
Newer Older
1 2 3 4 5 6
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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 = new Title(
12 13
      color: const Color(0xFF00FF00),
      title: 'Awesome app',
14
      child: new Container(),
15 16 17
    );
    expect(widget.toString, isNot(throwsException));
  });
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

  testWidgets('should handle having no title', (WidgetTester tester) async {
    final Title widget = new Title(
      child: new Container(),
      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 {
    expect(() => new Title(
      title: null,
      color: const Color(0xFF00FF00),
      child: new Container(),
    ), throwsAssertionError);
    expect(() => new Title(
      color: null,
      child: new Container(),
    ), throwsAssertionError);
  });

  testWidgets('should not allow non-opaque color', (WidgetTester tester) async {
    expect(() => new Title(
      color: const Color(0),
      child: new Container(),
    ), throwsAssertionError);
  });

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

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

    await tester.pumpWidget(new Title(
      child: new Container(),
      color: const Color(0xFF00FF00),
    ));

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