test: updated Signpost test and goldens

pull/303/head
alestiago 3 years ago
parent fc553d8bfb
commit f5c7202cc8

@ -1,5 +1,6 @@
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/foundation.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
@ -32,6 +33,16 @@ class Signpost extends BodyComponent with InitialPosition {
],
);
/// Creates an [Signpost] without any children.
///
/// This can be used for testing [Signpost]'s behaviors in isolation.
// TODO(alestiago): Refactor injecting bloc once the following is merged:
// https://github.com/flame-engine/flame/pull/1538
@visibleForTesting
Signpost.test({
required this.bloc,
});
// TODO(alestiago): Consider refactoring once the following is merged:
// https://github.com/flame-engine/flame/pull/1538
// ignore: public_member_api_docs

@ -34,6 +34,6 @@ class SignpostGame extends BallGame {
@override
void onTap() {
super.onTap();
firstChild<Signpost>()!.progress();
firstChild<Signpost>()!.bloc.onProgressed();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 21 KiB

@ -18,13 +18,13 @@ void main() {
final flameTester = FlameTester(() => TestGame(assets));
group('Signpost', () {
const goldenPath = 'golden/signpost/';
flameTester.test(
'loads correctly',
(game) async {
final signpost = Signpost();
await game.ready();
await game.ensureAdd(signpost);
expect(game.contains(signpost), isTrue);
},
);
@ -39,8 +39,8 @@ void main() {
await tester.pump();
expect(
signpost.firstChild<SpriteGroupComponent>()!.current,
SignpostSpriteState.inactive,
signpost.bloc.state,
equals(SignpostState.active1),
);
game.camera.followVector2(Vector2.zero());
@ -48,7 +48,7 @@ void main() {
verify: (game, tester) async {
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/signpost/inactive.png'),
matchesGoldenFile('${goldenPath}inactive.png'),
);
},
);
@ -59,12 +59,12 @@ void main() {
await game.images.loadAll(assets);
final signpost = Signpost();
await game.ensureAdd(signpost);
signpost.progress();
signpost.bloc.onProgressed();
await tester.pump();
expect(
signpost.firstChild<SpriteGroupComponent>()!.current,
SignpostSpriteState.active1,
signpost.bloc.state,
equals(SignpostState.active1),
);
game.camera.followVector2(Vector2.zero());
@ -72,7 +72,7 @@ void main() {
verify: (game, tester) async {
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/signpost/active1.png'),
matchesGoldenFile('${goldenPath}active1.png'),
);
},
);
@ -83,14 +83,14 @@ void main() {
await game.images.loadAll(assets);
final signpost = Signpost();
await game.ensureAdd(signpost);
signpost
..progress()
..progress();
signpost.bloc
..onProgressed()
..onProgressed();
await tester.pump();
expect(
signpost.firstChild<SpriteGroupComponent>()!.current,
SignpostSpriteState.active2,
signpost.bloc.state,
equals(SignpostState.active2),
);
game.camera.followVector2(Vector2.zero());
@ -98,7 +98,7 @@ void main() {
verify: (game, tester) async {
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/signpost/active2.png'),
matchesGoldenFile('${goldenPath}active2.png'),
);
},
);
@ -109,15 +109,16 @@ void main() {
await game.images.loadAll(assets);
final signpost = Signpost();
await game.ensureAdd(signpost);
signpost
..progress()
..progress()
..progress();
signpost.bloc
..onProgressed()
..onProgressed()
..onProgressed();
await tester.pump();
expect(
signpost.firstChild<SpriteGroupComponent>()!.current,
SignpostSpriteState.active3,
signpost.bloc.state,
equals(SignpostState.active3),
);
game.camera.followVector2(Vector2.zero());
@ -125,33 +126,12 @@ void main() {
verify: (game, tester) async {
await expectLater(
find.byGame<TestGame>(),
matchesGoldenFile('golden/signpost/active3.png'),
matchesGoldenFile('${goldenPath}active3.png'),
);
},
);
});
flameTester.test(
'progress correctly cycles through all sprites',
(game) async {
final signpost = Signpost();
await game.ready();
await game.ensureAdd(signpost);
final spriteComponent = signpost.firstChild<SpriteGroupComponent>()!;
expect(spriteComponent.current, SignpostSpriteState.inactive);
signpost.progress();
expect(spriteComponent.current, SignpostSpriteState.active1);
signpost.progress();
expect(spriteComponent.current, SignpostSpriteState.active2);
signpost.progress();
expect(spriteComponent.current, SignpostSpriteState.active3);
signpost.progress();
expect(spriteComponent.current, SignpostSpriteState.inactive);
},
);
flameTester.test('adds new children', (game) async {
final component = Component();
final signpost = Signpost(

Loading…
Cancel
Save