animation_style_test.dart 3.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 The Flutter 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/animation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('copyWith, ==, hashCode basics', () {
    expect(AnimationStyle(), AnimationStyle().copyWith());
    expect(AnimationStyle().hashCode, AnimationStyle().copyWith().hashCode);
  });

15
  testWidgets('AnimationStyle.copyWith() overrides all properties', (WidgetTester tester) async {
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    final AnimationStyle original = AnimationStyle(
      curve: Curves.ease,
      duration: const Duration(seconds: 1),
      reverseCurve: Curves.ease,
      reverseDuration: const Duration(seconds: 1),
    );
    final AnimationStyle copy = original.copyWith(
      curve: Curves.linear,
      duration: const Duration(seconds: 2),
      reverseCurve: Curves.linear,
      reverseDuration: const Duration(seconds: 2),
    );
    expect(copy.curve, Curves.linear);
    expect(copy.duration, const Duration(seconds: 2));
    expect(copy.reverseCurve, Curves.linear);
    expect(copy.reverseDuration, const Duration(seconds: 2));
  });

  test('AnimationStyle.lerp identical a,b', () {
    expect(AnimationStyle.lerp(null, null, 0), null);
    final AnimationStyle data = AnimationStyle();
    expect(identical(AnimationStyle.lerp(data, data, 0.5), data), true);
  });

40
  testWidgets('default AnimationStyle debugFillProperties', (WidgetTester tester) async {
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    final AnimationStyle a = AnimationStyle(
      curve: Curves.ease,
      duration: const Duration(seconds: 1),
      reverseCurve: Curves.ease,
      reverseDuration: const Duration(seconds: 1),
    );
    final AnimationStyle b = AnimationStyle(
      curve: Curves.linear,
      duration: const Duration(seconds: 2),
      reverseCurve: Curves.linear,
      reverseDuration: const Duration(seconds: 2),
    );

    expect(AnimationStyle.lerp(a, b, 0), a);
    expect(AnimationStyle.lerp(a, b, 0.5), b);
    expect(AnimationStyle.lerp(a, b, 1.0), b);
  });

59
  testWidgets('default AnimationStyle debugFillProperties', (WidgetTester tester) async {
60 61 62 63 64 65 66 67 68 69 70
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();

    AnimationStyle().debugFillProperties(builder);

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString()).toList();

    expect(description, <String>[]);
  });

71
  testWidgets('AnimationStyle implements debugFillProperties', (WidgetTester tester) async {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();

    AnimationStyle(
      curve: Curves.easeInOut,
      duration: const Duration(seconds: 1),
      reverseCurve: Curves.bounceInOut,
      reverseDuration: const Duration(seconds: 2),
    ).debugFillProperties(builder);

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString()).toList();

    expect(description, <String>[
      'curve: Cubic(0.42, 0.00, 0.58, 1.00)',
      'duration: 0:00:01.000000',
      'reverseCurve: _BounceInOutCurve',
      'reverseDuration: 0:00:02.000000'
    ]);
  });
}