From 2f875009960a6765dc4325d9c3cbe5837393bfea Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 2 May 2022 22:41:16 +0100 Subject: [PATCH] test: tested FlutterForestBonusBehavior --- .../flutter_forest_bonus_behavior_test.dart | 90 ++++++++++++++++--- 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart b/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart index 3481cb38..2de84edd 100644 --- a/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart +++ b/test/game/components/flutter_forest/behaviors/flutter_forest_bonus_behavior_test.dart @@ -16,6 +16,7 @@ import '../../../../helpers/helpers.dart'; void main() { group('FlutterForestBonusBehavior', () { late GameBloc gameBloc; + final assets = [Assets.images.dash.animatronic.keyName]; setUp(() { gameBloc = MockGameBloc(); @@ -31,9 +32,14 @@ void main() { blocBuilder: () => gameBloc, ); + void _contactedBumper(DashNestBumper bumper) => + bumper.bloc.onBallContacted(); + flameBlocTester.testGameWidget( - 'adds GameBonus.dashNest to the game when all bumpers are active', + 'adds GameBonus.dashNest to the game ' + 'when bumpers are activated three times', setUp: (game, tester) async { + await game.images.loadAll(assets); final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final bumpers = [ @@ -41,12 +47,18 @@ void main() { DashNestBumper.test(bloc: DashNestBumperCubit()), DashNestBumper.test(bloc: DashNestBumperCubit()), ]; + final animatronic = DashAnimatronic(); + final signpost = Signpost.test(bloc: SignpostCubit()); await game.ensureAdd(ZCanvasComponent(children: [parent])); - await parent.ensureAddAll([...bumpers, behavior]); + await parent.ensureAddAll([...bumpers, animatronic, signpost]); + await parent.ensureAdd(behavior); - for (final bumper in bumpers) { - bumper.bloc.onBallContacted(); - } + expect(game.descendants().whereType(), equals(bumpers)); + bumpers.forEach(_contactedBumper); + await tester.pump(); + bumpers.forEach(_contactedBumper); + await tester.pump(); + bumpers.forEach(_contactedBumper); await tester.pump(); verify( @@ -56,8 +68,10 @@ void main() { ); flameBlocTester.testGameWidget( - 'adds a new ball to the game when all bumpers are active', + 'adds a new Ball to the game ' + 'when bumpers are activated three times', setUp: (game, tester) async { + await game.images.loadAll(assets); final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final bumpers = [ @@ -65,18 +79,68 @@ void main() { DashNestBumper.test(bloc: DashNestBumperCubit()), DashNestBumper.test(bloc: DashNestBumperCubit()), ]; + final animatronic = DashAnimatronic(); + final signpost = Signpost.test(bloc: SignpostCubit()); await game.ensureAdd(ZCanvasComponent(children: [parent])); + await parent.ensureAddAll([...bumpers, animatronic, signpost]); await parent.ensureAdd(behavior); - for (final bumper in bumpers) { - bumper.bloc.onBallContacted(); - } + expect(game.descendants().whereType(), equals(bumpers)); + bumpers.forEach(_contactedBumper); + await tester.pump(); + bumpers.forEach(_contactedBumper); + await tester.pump(); + bumpers.forEach(_contactedBumper); + await tester.pump(); + await game.ready(); + expect( + game.descendants().whereType().length, + equals(1), + ); + }, + ); + + flameBlocTester.testGameWidget( + 'progress the signpost ' + 'when bumpers are activated', + setUp: (game, tester) async { + await game.images.loadAll(assets); + final behavior = FlutterForestBonusBehavior(); + final parent = FlutterForest.test(); + final bumpers = [ + DashNestBumper.test(bloc: DashNestBumperCubit()), + DashNestBumper.test(bloc: DashNestBumperCubit()), + DashNestBumper.test(bloc: DashNestBumperCubit()), + ]; + final animatronic = DashAnimatronic(); + final signpost = Signpost.test(bloc: SignpostCubit()); + await game.ensureAdd(ZCanvasComponent(children: [parent])); + await parent.ensureAddAll([...bumpers, animatronic, signpost]); + await parent.ensureAdd(behavior); + + expect(game.descendants().whereType(), equals(bumpers)); + + bumpers.forEach(_contactedBumper); + await tester.pump(); + expect( + signpost.bloc.state, + equals(SignpostState.active1), + ); - // expect( - // game.descendants().whereType().single, - // isNotNull, - // ); + bumpers.forEach(_contactedBumper); + await tester.pump(); + expect( + signpost.bloc.state, + equals(SignpostState.active2), + ); + + bumpers.forEach(_contactedBumper); + await tester.pump(); + expect( + signpost.bloc.state, + equals(SignpostState.inactive), + ); }, ); });