test: fixed tests for animation

pull/200/head
RuiAlonso 3 years ago
parent 1721f628c5
commit adff493c98

@ -1,5 +1,6 @@
// ignore_for_file: cascade_invocations // ignore_for_file: cascade_invocations
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -149,6 +150,33 @@ void main() {
expect(plunger.body.linearVelocity.y, isPositive); expect(plunger.body.linearVelocity.y, isPositive);
expect(plunger.body.linearVelocity.x, isZero); expect(plunger.body.linearVelocity.x, isZero);
}); });
flameTester.test(
'animates when called',
(game) async {
await game.ensureAdd(plunger);
plunger.pull();
final animation =
plunger.descendants().whereType<SpriteAnimationComponent>().first;
expect(animation.playing, isTrue);
},
);
flameTester.test(
'stops animating after animation completes',
(game) async {
await game.ensureAdd(plunger);
plunger.pull();
game.update(1);
final animation =
plunger.descendants().whereType<SpriteAnimationComponent>().first;
expect(animation.playing, isFalse);
},
);
}); });
group('release', () { group('release', () {
@ -182,6 +210,35 @@ void main() {
expect(plunger.body.linearVelocity.x, isZero); expect(plunger.body.linearVelocity.x, isZero);
}, },
); );
flameTester.test(
'animates when called',
(game) async {
await game.ensureAdd(plunger);
plunger.pull();
plunger.release();
final animation =
plunger.descendants().whereType<SpriteAnimationComponent>().first;
expect(animation.playing, isTrue);
},
);
flameTester.test(
'stops animating after animation completes',
(game) async {
await game.ensureAdd(plunger);
plunger.pull();
plunger.release();
game.update(1);
final animation =
plunger.descendants().whereType<SpriteAnimationComponent>().first;
expect(animation.playing, isFalse);
},
);
}); });
}); });

Loading…
Cancel
Save