test: chrome dino

pull/229/head
Allison Ryan 3 years ago
parent 97ded4a3a1
commit 67b27f78ec

@ -1,13 +1,19 @@
// ignore_for_file: cascade_invocations
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(Forge2DGame.new);
final assets = [
Assets.images.dino.animatronic.mouth.keyName,
Assets.images.dino.animatronic.head.keyName,
];
final flameTester = FlameTester(() => TestGame(assets));
group('ChromeDino', () {
flameTester.test(
@ -20,19 +26,90 @@ void main() {
},
);
flameTester.test(
'swivels',
(game) async {
// TODO(alestiago): Write golden tests to check the
// swivel animation.
flameTester.testGameWidget(
'renders correctly',
setUp: (game, tester) async {
await game.images.loadAll(assets);
await game.ensureAdd(ChromeDino());
game.camera.followVector2(Vector2.zero());
await tester.pump();
},
verify: (game, tester) async {
final sweepAnimationDuration = game
.descendants()
.whereType<SpriteAnimationComponent>()
.first
.animation!
.totalDuration() /
2;
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/chrome_dino/up.png'),
);
game.update(sweepAnimationDuration * 0.25);
await tester.pump();
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/chrome_dino/middle.png'),
);
game.update(sweepAnimationDuration * 0.25);
await tester.pump();
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/chrome_dino/down.png'),
);
},
);
group('swivels', () {
flameTester.testGameWidget(
'up',
setUp: (game, tester) async {
await game.images.loadAll(assets);
final chromeDino = ChromeDino();
await game.ensureAdd(chromeDino);
game.camera.followVector2(Vector2.zero());
await tester.pump();
final sweepAnimationDuration = game
.descendants()
.whereType<SpriteAnimationComponent>()
.first
.animation!
.totalDuration() /
2;
game.update(sweepAnimationDuration * 1.5);
await tester.pump();
expect(chromeDino.body.angularVelocity, isPositive);
},
);
flameTester.testGameWidget(
'down',
setUp: (game, tester) async {
await game.images.loadAll(assets);
final chromeDino = ChromeDino();
await game.ensureAdd(chromeDino);
game.camera.followVector2(Vector2.zero());
await tester.pump();
final previousPosition = chromeDino.body.position.clone();
game.update(64);
final sweepAnimationDuration = game
.descendants()
.whereType<SpriteAnimationComponent>()
.first
.animation!
.totalDuration() /
2;
game.update(sweepAnimationDuration * 0.5);
await tester.pump();
expect(chromeDino.body.position, isNot(equals(previousPosition)));
expect(chromeDino.body.angularVelocity, isNegative);
},
);
});
});
}

@ -45,6 +45,7 @@ void main() {
);
},
);
flameTester.test(
'loads correctly',
(game) async {

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

@ -103,18 +103,6 @@ void main() {
expect(flutterForest.length, equals(1));
},
);
flameTester.test(
'one ChromeDino',
(game) async {
final board = Board();
await game.ready();
await game.ensureAdd(board);
final chromeDino = board.descendants().whereType<ChromeDino>();
expect(chromeDino.length, equals(1));
},
);
});
});
}

@ -45,6 +45,8 @@ void main() {
Assets.images.spaceship.ramp.arrow.active3.keyName,
Assets.images.spaceship.ramp.arrow.active4.keyName,
Assets.images.spaceship.ramp.arrow.active5.keyName,
Assets.images.dino.animatronic.head.keyName,
Assets.images.dino.animatronic.mouth.keyName,
Assets.images.baseboard.left.keyName,
Assets.images.baseboard.right.keyName,
Assets.images.flipper.left.keyName,

Loading…
Cancel
Save