diff --git a/lib/game/components/flutter_forest.dart b/lib/game/components/flutter_forest.dart index 0c051942..667e4f8e 100644 --- a/lib/game/components/flutter_forest.dart +++ b/lib/game/components/flutter_forest.dart @@ -61,7 +61,7 @@ class _FlutterForestController extends ComponentController children.whereType().forEach( (dashNestBumper) => dashNestBumper.deactivate(), ); - // gameRef.read().add(const BonusActivated(GameBonus.dashNest)); + gameRef.read().add(const BonusActivated(GameBonus.dashNest)); _addBonusBall(); _activatedBumpers.clear(); } diff --git a/test/game/components/flutter_forest_test.dart b/test/game/components/flutter_forest_test.dart index 9a29557c..db52610e 100644 --- a/test/game/components/flutter_forest_test.dart +++ b/test/game/components/flutter_forest_test.dart @@ -1,5 +1,6 @@ // ignore_for_file: cascade_invocations +import 'package:bloc_test/bloc_test.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -84,12 +85,16 @@ void main() { setUp(() { ball = Ball(baseColor: const Color(0xFF00FFFF)); - gameBloc = MockGameBloc(); }); final flameBlocTester = FlameBlocTester( gameBuilder: EmptyPinballTestGame.new, - blocBuilder: () => gameBloc, + blocBuilder: () { + gameBloc = MockGameBloc(); + const state = GameState.initial(); + whenListen(gameBloc, Stream.value(state), initialState: state); + return gameBloc; + }, ); flameBlocTester.testGameWidget( @@ -114,6 +119,32 @@ void main() { } }, ); + + flameBlocTester.testGameWidget( + 'adds GameBonus.dashNest to the game when all bumpers are activated', + setUp: (game, _) async { + final ball = Ball(baseColor: const Color(0xFFFF0000)); + final flutterForest = FlutterForest(); + await game.ensureAddAll([flutterForest, ball]); + + final bumpers = flutterForest.children.whereType(); + expect(bumpers, isNotEmpty); + for (final bumper in bumpers) { + beginContact(game, bumper, ball); + await game.ready(); + + if (bumper == bumpers.last) { + verify( + () => gameBloc.add(const BonusActivated(GameBonus.dashNest)), + ).called(1); + } else { + verifyNever( + () => gameBloc.add(const BonusActivated(GameBonus.dashNest)), + ); + } + } + }, + ); }); }); }