diff --git a/test/game/components/controlled_flipper_test.dart b/test/game/components/controlled_flipper_test.dart index 68e6703b..af262dbf 100644 --- a/test/game/components/controlled_flipper_test.dart +++ b/test/game/components/controlled_flipper_test.dart @@ -22,25 +22,19 @@ void main() { () => EmptyPinballTestGame(assets: assets), ); - final flameBlocTester = FlameBlocTester( - gameBuilder: EmptyPinballTestGame.new, - blocBuilder: () { - final bloc = _MockGameBloc(); - const state = GameState( - totalScore: 0, - roundScore: 0, - multiplier: 1, - rounds: 0, - bonusHistory: [], - status: GameStatus.playing, - ); - whenListen(bloc, Stream.value(state), initialState: state); - return bloc; - }, - assets: assets, - ); - group('FlipperController', () { + late GameBloc gameBloc; + + setUp(() { + gameBloc = _MockGameBloc(); + }); + + final flameBlocTester = FlameBlocTester( + gameBuilder: EmptyPinballTestGame.new, + blocBuilder: () => gameBloc, + assets: assets, + ); + group('onKeyEvent', () { final leftKeys = UnmodifiableListView([ LogicalKeyboardKey.arrowLeft, @@ -66,6 +60,12 @@ void main() { 'moves upwards ' 'when ${event.logicalKey.keyLabel} is pressed', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ready(); await game.add(flipper); controller.onKeyEvent(event, {}); @@ -80,6 +80,14 @@ void main() { flameBlocTester.testGameWidget( 'does nothing when is game over', setUp: (game, tester) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial().copyWith( + status: GameStatus.gameOver, + ), + ); + await game.ensureAdd(flipper); controller.onKeyEvent(event, {}); }, @@ -95,6 +103,12 @@ void main() { 'moves downwards ' 'when ${event.logicalKey.keyLabel} is released', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ready(); await game.add(flipper); controller.onKeyEvent(event, {}); @@ -110,6 +124,12 @@ void main() { 'does nothing ' 'when ${event.logicalKey.keyLabel} is released', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ready(); await game.add(flipper); controller.onKeyEvent(event, {}); @@ -136,6 +156,12 @@ void main() { 'moves upwards ' 'when ${event.logicalKey.keyLabel} is pressed', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ready(); await game.add(flipper); controller.onKeyEvent(event, {}); @@ -151,6 +177,12 @@ void main() { 'moves downwards ' 'when ${event.logicalKey.keyLabel} is released', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ready(); await game.add(flipper); controller.onKeyEvent(event, {}); @@ -165,6 +197,14 @@ void main() { flameBlocTester.testGameWidget( 'does nothing when is game over', setUp: (game, tester) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial().copyWith( + status: GameStatus.gameOver, + ), + ); + await game.ensureAdd(flipper); controller.onKeyEvent(event, {}); }, diff --git a/test/game/components/controlled_plunger_test.dart b/test/game/components/controlled_plunger_test.dart index abf58378..f91b0c37 100644 --- a/test/game/components/controlled_plunger_test.dart +++ b/test/game/components/controlled_plunger_test.dart @@ -17,24 +17,18 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); final flameTester = FlameTester(EmptyPinballTestGame.new); - final flameBlocTester = FlameBlocTester( - gameBuilder: EmptyPinballTestGame.new, - blocBuilder: () { - final bloc = _MockGameBloc(); - const state = GameState( - totalScore: 0, - roundScore: 0, - multiplier: 1, - rounds: 0, - bonusHistory: [], - status: GameStatus.playing, - ); - whenListen(bloc, Stream.value(state), initialState: state); - return bloc; - }, - ); - group('PlungerController', () { + late GameBloc gameBloc; + + setUp(() { + gameBloc = _MockGameBloc(); + }); + + final flameBlocTester = FlameBlocTester( + gameBuilder: EmptyPinballTestGame.new, + blocBuilder: () => gameBloc, + ); + group('onKeyEvent', () { final downKeys = UnmodifiableListView([ LogicalKeyboardKey.arrowDown, @@ -56,6 +50,12 @@ void main() { 'moves down ' 'when ${event.logicalKey.keyLabel} is pressed', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ensureAdd(plunger); controller.onKeyEvent(event, {}); @@ -71,6 +71,12 @@ void main() { 'when ${event.logicalKey.keyLabel} is released ' 'and plunger is below its starting position', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ensureAdd(plunger); plunger.body.setTransform(Vector2(0, 1), 0); controller.onKeyEvent(event, {}); @@ -86,6 +92,12 @@ void main() { 'does not move when ${event.logicalKey.keyLabel} is released ' 'and plunger is in its starting position', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + await game.ensureAdd(plunger); controller.onKeyEvent(event, {}); @@ -99,6 +111,14 @@ void main() { flameBlocTester.testGameWidget( 'does nothing when is game over', setUp: (game, tester) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial().copyWith( + status: GameStatus.gameOver, + ), + ); + await game.ensureAdd(plunger); controller.onKeyEvent(event, {}); },