Skip to content

Commit

Permalink
Add tests for new effects
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Feb 13, 2023
1 parent 016bd9e commit 8373c79
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 1 deletion.
35 changes: 35 additions & 0 deletions test/effects/box_shadow_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_animate/flutter_animate.dart';

import '../tester_extensions.dart';

void main() {
testWidgets('BoxShadowEffect: core', (tester) async {
BoxShadow? begin;
BoxShadow end = const BoxShadow(blurRadius: 32, color: Colors.red);
BorderRadius borderRadius = BorderRadius.circular(8);

// uses a Placeholder instead of FlutterLogo because the latter apparently has its own DecoratedBox
final animation = const Placeholder().animate().boxShadow(
duration: 1000.ms,
borderRadius: borderRadius,
begin: begin,
end: end,
);

// Check middle:
await tester.pumpAnimation(animation, initialDelay: 500.ms);
var expected = BoxShadow.lerp(begin, end, 0.5);
tester.expectWidgetWithBool<DecoratedBox>(
(o) => (o.decoration as BoxDecoration).boxShadow?.first == expected,
true,
'decoration.boxShadow @ 500ms',
);
tester.expectWidgetWithBool<DecoratedBox>(
(o) => (o.decoration as BoxDecoration).borderRadius == borderRadius,
true,
'decoration.borderRadius @ 500ms',
);
});
}
35 changes: 35 additions & 0 deletions test/effects/color_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_animate/flutter_animate.dart';

import '../tester_extensions.dart';

void main() {
testWidgets('ColorEffect: core', (tester) async {
BlendMode blend = BlendMode.colorDodge;
Color begin = Colors.blue, end = Colors.red;

final animation = const FlutterLogo().animate().color(
duration: 1000.ms,
blendMode: blend,
begin: begin,
end: end,
);

// Check begin:
await tester.pumpAnimation(animation);
tester.expectWidgetWithBool<ColorFiltered>(
(o) => o.colorFilter == ColorFilter.mode(begin, blend),
true,
'colorFilter @ 0ms',
);

// Check end:
await tester.pump(1000.ms);
tester.expectWidgetWithBool<ColorFiltered>(
(o) => o.colorFilter == ColorFilter.mode(end, blend),
true,
'colorFilter @ 1000ms',
);
});
}
61 changes: 61 additions & 0 deletions test/effects/crossfade_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_animate/flutter_animate.dart';

import '../tester_extensions.dart';

void main() {
testWidgets('CrossfadeEffect: core', (tester) async {
Widget beginChild = const FlutterLogo(), endChild = const Placeholder();
final anim = beginChild.animate().crossfade(
duration: 1000.ms,
delay: 0.ms,
builder: (_) => endChild,
);

// At begin, expect beginChild is 100% opaque, endChild is 0%
await tester.pumpAnimation(anim);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
1,
'beginChild opacity @ 0ms',
findFirst: true,
);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
0,
'endChild opacity @ 0ms',
findFirst: false,
);

// At middle, expect beginChild is 50% opaque, endChild is 50%
await tester.pump(500.ms);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
0.5,
'beginChild opacity @ 500ms',
findFirst: true,
);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
0.5,
'endChild opacity @ 500ms',
findFirst: false,
);

// At end, expect beginChild is 0% opaque, endChild is 100%
await tester.pump(500.ms);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
0,
'beginChild opacity @ 1000ms',
findFirst: true,
);
tester.expectWidgetWithDouble<FadeTransition>(
(o) => o.opacity.value,
1,
'endChild opacity @ 1000ms',
findFirst: false,
);
});
}
27 changes: 27 additions & 0 deletions test/effects/elevation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_animate/flutter_animate.dart';

import '../tester_extensions.dart';

void main() {
testWidgets('ElevationEffect: core', (tester) async {
double begin = 4, end = 32;

final animation = const FlutterLogo().animate().elevation(
duration: 1000.ms,
begin: begin,
end: end,
);

// Check begin:
await tester.pumpAnimation(animation);
tester.expectWidgetWithBool<PhysicalModel>(
(o) => o.elevation == begin, true, 'elevation @ 0ms');

// Check end:
await tester.pump(1000.ms);
tester.expectWidgetWithBool<PhysicalModel>(
(o) => o.elevation == end, true, 'elevation @ 1000ms');
});
}
3 changes: 3 additions & 0 deletions test/effects/flip_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void main() {
// TODO: expose FlipEffect.getTransformMatrix (name TBD) and use in test
}
2 changes: 1 addition & 1 deletion test/effects/swap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../tester_extensions.dart';
void main() {
testWidgets('SwapEffect: core', (tester) async {
final anim = const FlutterLogo().animate().fadeOut(duration: 500.ms).swap(
builder: (_, __) => const Placeholder().animate().fadeIn(),
builder: (_, __) => const Placeholder(),
);

await tester.pumpAnimation(anim);
Expand Down

0 comments on commit 8373c79

Please sign in to comment.