From 70145cc35c63ae88fd5a3f4a8b3a24ad47c2a660 Mon Sep 17 00:00:00 2001 From: alestiago Date: Fri, 6 May 2022 04:06:30 +0100 Subject: [PATCH] test: passed all tests --- .../game/behaviors/scoring_behavior_test.dart | 13 ++++++----- .../components/controlled_flipper_test.dart | 3 +-- .../components/controlled_plunger_test.dart | 23 ++++++++++++++----- .../google_word_bonus_behavior_test.dart | 1 + .../multiballs/multiballs_test.dart | 4 ++-- test/game/pinball_game_test.dart | 12 +++++----- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/test/game/behaviors/scoring_behavior_test.dart b/test/game/behaviors/scoring_behavior_test.dart index d1f53ec0..0207eb07 100644 --- a/test/game/behaviors/scoring_behavior_test.dart +++ b/test/game/behaviors/scoring_behavior_test.dart @@ -77,9 +77,9 @@ void main() { ); }); - flameBlocTester.testGameWidget( + flameBlocTester.test( 'can be loaded', - setUp: (game, tester) async { + (game) async { await game.pump(parent); final behavior = ScoringBehavior( @@ -95,9 +95,9 @@ void main() { }, ); - flameBlocTester.testGameWidget( + flameBlocTester.test( 'emits Scored event with points when added', - setUp: (game, tester) async { + (game) async { await game.pump(parent, gameBloc: bloc); const points = Points.oneMillion; @@ -115,9 +115,9 @@ void main() { }, ); - flameBlocTester.testGameWidget( + flameBlocTester.test( 'correctly renders text', - setUp: (game, tester) async { + (game) async { await game.pump(parent); const points = Points.oneMillion; @@ -144,6 +144,7 @@ void main() { flameBlocTester.testGameWidget( 'is removed after duration', setUp: (game, tester) async { + await game.onLoad(); await game.pump(parent); const duration = 2.0; diff --git a/test/game/components/controlled_flipper_test.dart b/test/game/components/controlled_flipper_test.dart index 1c304784..561ddccb 100644 --- a/test/game/components/controlled_flipper_test.dart +++ b/test/game/components/controlled_flipper_test.dart @@ -26,8 +26,7 @@ class _TestGame extends Forge2DGame with HasKeyboardHandlerComponents { Future pump(Flipper flipper, {GameBloc? gameBloc}) { return ensureAdd( FlameBlocProvider.value( - value: gameBloc ?? GameBloc() - ..add(const GameStarted()), + value: gameBloc ?? (GameBloc()..add(const GameStarted())), children: [flipper], ), ); diff --git a/test/game/components/controlled_plunger_test.dart b/test/game/components/controlled_plunger_test.dart index 1d17d78c..56f9f23a 100644 --- a/test/game/components/controlled_plunger_test.dart +++ b/test/game/components/controlled_plunger_test.dart @@ -14,6 +14,7 @@ import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball_audio/pinball_audio.dart'; import 'package:pinball_components/pinball_components.dart'; +import 'package:pinball_flame/pinball_flame.dart'; import '../../helpers/helpers.dart'; @@ -24,12 +25,21 @@ class _TestGame extends Forge2DGame with HasKeyboardHandlerComponents { await images.load(Assets.images.plunger.plunger.keyName); } - Future pump(Plunger child, {GameBloc? gameBloc}) { + Future pump( + Plunger child, { + GameBloc? gameBloc, + PinballPlayer? pinballPlayer, + }) { return ensureAdd( FlameBlocProvider.value( value: gameBloc ?? GameBloc() ..add(const GameStarted()), - children: [child], + children: [ + FlameProvider.value( + pinballPlayer ?? _MockPinballPlayer(), + children: [child], + ) + ], ), ); } @@ -149,20 +159,21 @@ void main() { group('PlungerNoisyBehavior', () { late PinballPlayer player; - late PlungerNoisyBehavior behavior; setUp(() { player = _MockPinballPlayer(); - behavior = PlungerNoisyBehavior(); }); - test('plays the correct sound on load', () async { - await behavior.onLoad(); + flameTester.test('plays the correct sound on load', (game) async { + final parent = ControlledPlunger(compressionDistance: 10); + await game.pump(parent, pinballPlayer: player); + await parent.ensureAdd(PlungerNoisyBehavior()); verify(() => player.play(PinballAudio.launcher)).called(1); }); test('is removed on the first update', () { final parent = Component(); + final behavior = PlungerNoisyBehavior(); parent.add(behavior); parent.update(0); // Run a tick to ensure it is added diff --git a/test/game/components/google_word/behaviors/google_word_bonus_behavior_test.dart b/test/game/components/google_word/behaviors/google_word_bonus_behavior_test.dart index f917df81..40afeb09 100644 --- a/test/game/components/google_word/behaviors/google_word_bonus_behavior_test.dart +++ b/test/game/components/google_word/behaviors/google_word_bonus_behavior_test.dart @@ -65,6 +65,7 @@ void main() { flameTester.testGameWidget( 'adds GameBonus.googleWord to the game when all letters are activated', setUp: (game, tester) async { + await game.onLoad(); final behavior = GoogleWordBonusBehavior(); final parent = GoogleWord.test(); final letters = [ diff --git a/test/game/components/multiballs/multiballs_test.dart b/test/game/components/multiballs/multiballs_test.dart index f8cba3d3..1841d0a3 100644 --- a/test/game/components/multiballs/multiballs_test.dart +++ b/test/game/components/multiballs/multiballs_test.dart @@ -42,9 +42,9 @@ void main() { }, ); - flameBlocTester.testGameWidget( + flameBlocTester.test( 'loads four Multiball', - setUp: (game, tester) async { + (game) async { final multiballs = Multiballs(); await game.pump(multiballs); expect( diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index 866cffc5..9e7e84db 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -32,8 +32,7 @@ class _TestPinballGame extends PinballGame { images.prefix = ''; final futures = preLoadAssets(); await Future.wait(futures); - - return super.onLoad(); + await super.onLoad(); } } @@ -52,8 +51,7 @@ class _DebugPinballGame extends DebugPinballGame { images.prefix = ''; final futures = preLoadAssets(); await Future.wait(futures); - - return super.onLoad(); + await super.onLoad(); } } @@ -159,7 +157,6 @@ void main() { 'has only one Multiballs', (game) async { await game.ready(); - expect( game.descendants().whereType().length, equals(1), @@ -189,7 +186,10 @@ void main() { flameTester.testGameWidget( 'paints sprites with FilterQuality.medium', setUp: (game, tester) async { - await game.onLoad(); + game.images.prefix = ''; + final futures = game.preLoadAssets(); + await Future.wait(futures); + await game.ready(); final descendants = game.descendants();