icon_theme_data_test.dart 3.39 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/widgets.dart';
6 7 8 9
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('IconThemeData control test', () {
10 11 12 13 14 15 16 17 18 19
    const IconThemeData data = IconThemeData(
      size: 16.0,
      fill: 0.5,
      weight: 600,
      grade: 25,
      opticalSize: 45,
      color: Color(0xAAAAAAAA),
      opacity: 0.5,
      shadows: <Shadow>[Shadow(color: Color(0xAAAAAAAA), blurRadius: 1.0, offset: Offset(1.0, 1.0))],
    );
20 21 22 23
    expect(data, hasOneLineDescription);
    expect(data, equals(data.copyWith()));
    expect(data.hashCode, equals(data.copyWith().hashCode));

24
    final IconThemeData lerped = IconThemeData.lerp(data, const IconThemeData.fallback(), 0.25);
25 26 27 28 29
    expect(lerped.size, 18.0);
    expect(lerped.fill, 0.375);
    expect(lerped.weight, 550.0);
    expect(lerped.grade, 18.75);
    expect(lerped.opticalSize, 45.75);
30 31
    expect(lerped.color, const Color(0xBF7F7F7F));
    expect(lerped.opacity, 0.625);
32
    expect(lerped.shadows, const <Shadow>[Shadow(color: Color(0xAAAAAAAA), blurRadius: 0.75, offset: Offset(0.75, 0.75))]);
33 34
  });

35 36 37 38 39 40 41 42 43 44 45
  group('IconThemeData lerp', () {
    const IconThemeData data = IconThemeData(
      size: 16.0,
      fill: 0.5,
      weight: 600,
      grade: 25,
      opticalSize: 45,
      color: Color(0xFFFFFFFF),
      opacity: 1.0,
      shadows: <Shadow>[Shadow(color: Color(0xFFFFFFFF), blurRadius: 1.0, offset: Offset(1.0, 1.0))],
    );
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    test('with first null', () {
      final IconThemeData lerped = IconThemeData.lerp(null, data, 0.25);

      expect(lerped.size, 4.0);
      expect(lerped.fill, 0.125);
      expect(lerped.weight, 150.0);
      expect(lerped.grade, 6.25);
      expect(lerped.opticalSize, 11.25);
      expect(lerped.color, const Color(0x40FFFFFF));
      expect(lerped.opacity, 0.25);
      expect(lerped.shadows, const <Shadow>[Shadow(color: Color(0xFFFFFFFF), blurRadius: 0.25, offset: Offset(0.25, 0.25))]);
    });

    test('with second null', () {
      final IconThemeData lerped = IconThemeData.lerp(data, null, 0.25);

      expect(lerped.size, 12.0);
      expect(lerped.fill, 0.375);
      expect(lerped.weight, 450.0);
      expect(lerped.grade, 18.75);
      expect(lerped.opticalSize, 33.75);
      expect(lerped.color, const Color(0xBFFFFFFF));
      expect(lerped.opacity, 0.75);
      expect(lerped.shadows, const <Shadow>[Shadow(color: Color(0xFFFFFFFF), blurRadius: 0.75, offset: Offset(0.75, 0.75))]);
    });
72

73 74
    test('with both null', () {
      final IconThemeData lerped = IconThemeData.lerp(null, null, 0.25);
75

76 77 78 79 80 81 82 83 84
      expect(lerped.size, null);
      expect(lerped.fill, null);
      expect(lerped.weight, null);
      expect(lerped.grade, null);
      expect(lerped.opticalSize, null);
      expect(lerped.color, null);
      expect(lerped.opacity, null);
      expect(lerped.shadows, null);
    });
85 86
  });

87 88 89 90 91 92 93
  test('Throws if given invalid values', () {
    expect(() => IconThemeData(fill: -0.1), throwsAssertionError);
    expect(() => IconThemeData(fill: 1.1), throwsAssertionError);
    expect(() => IconThemeData(weight: -0.1), throwsAssertionError);
    expect(() => IconThemeData(weight: 0.0), throwsAssertionError);
    expect(() => IconThemeData(opticalSize: -0.1), throwsAssertionError);
    expect(() => IconThemeData(opticalSize: 0), throwsAssertionError);
94 95
  });
}