diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 62764259..7a0e6823 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -183,9 +183,7 @@ class _DebugGameBallsController extends _GameBallsController { final noBallsLeft = component .descendants() .whereType() - .where( - (ball) => ball.controller is! DebugBallController, - ) + .where((ball) => ball.controller is! DebugBallController) .isEmpty; final canBallRespawn = newState.balls > 0; diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index aca1d4ae..d83bb396 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -65,12 +65,25 @@ void main() { group('controller', () { // TODO(alestiago): Write test to be controller agnostic. group('listenWhen', () { - flameTester.test( - 'listens when all balls are gone and there are more than 0 balls', - (game) async { + late GameBloc gameBloc; + + setUp(() { + gameBloc = GameBloc(); + }); + + final flameBlocTester = FlameBlocTester( + gameBuilder: EmptyPinballGameTest.new, + blocBuilder: () => gameBloc, + ); + + flameBlocTester.testGameWidget( + 'listens when all balls are lost and there are more than 0 balls', + setUp: (game, tester) async { final newState = MockGameState(); when(() => newState.balls).thenReturn(2); - game.descendants().whereType().forEach(game.remove); + game.descendants().whereType().forEach( + (ball) => ball.controller.lost(), + ); await game.ready(); expect( @@ -84,7 +97,7 @@ void main() { "doesn't listen when some balls are left", (game) async { final newState = MockGameState(); - when(() => newState.balls).thenReturn(2); + when(() => newState.balls).thenReturn(1); expect( game.descendants().whereType().length, @@ -97,15 +110,21 @@ void main() { }, ); - flameTester.test( + flameBlocTester.test( "doesn't listen when no balls left", (game) async { final newState = MockGameState(); when(() => newState.balls).thenReturn(0); - game.descendants().whereType().forEach(game.remove); + game.descendants().whereType().forEach( + (ball) => ball.controller.lost(), + ); await game.ready(); + expect( + game.descendants().whereType().isEmpty, + isTrue, + ); expect( game.controller.listenWhen(MockGameState(), newState), isFalse, @@ -163,12 +182,26 @@ void main() { }); group('controller', () { - debugModeFlameTester.test( + late GameBloc gameBloc; + + setUp(() { + gameBloc = GameBloc(); + }); + + final debugModeFlameBlocTester = + FlameBlocTester( + gameBuilder: DebugPinballGameTest.new, + blocBuilder: () => gameBloc, + ); + + debugModeFlameBlocTester.testGameWidget( 'ignores debug balls', - (game) async { + setUp: (game, tester) async { final newState = MockGameState(); - when(() => newState.balls).thenReturn(2); - game.descendants().whereType().forEach(game.remove); + when(() => newState.balls).thenReturn(1); + + await game.ready(); + game.children.removeWhere((component) => component is Ball); await game.ready(); await game.ensureAdd(ControlledBall.debug());