From 1e5cc0cf4d89ec4966b58637c902501bff5b4240 Mon Sep 17 00:00:00 2001 From: Alvaro Almeida Freire Stivi Date: Tue, 2 Jul 2024 21:43:50 +0000 Subject: [PATCH] Fixes some async issues with ramp tests --- .../behaviors/ramp_bonus_behavior_test.dart | 10 ++++-- .../ramp_multiplier_behavior_test.dart | 16 ++++++--- .../ramp_progress_behavior_test.dart | 34 +++++++++++++------ .../behaviors/ramp_reset_behavior_test.dart | 10 ++++-- .../behaviors/ramp_shot_behavior_test.dart | 1 + 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/test/game/components/android_acres/behaviors/ramp_bonus_behavior_test.dart b/test/game/components/android_acres/behaviors/ramp_bonus_behavior_test.dart index ee06484b..3f4b8ba6 100644 --- a/test/game/components/android_acres/behaviors/ramp_bonus_behavior_test.dart +++ b/test/game/components/android_acres/behaviors/ramp_bonus_behavior_test.dart @@ -80,6 +80,7 @@ void main() { flameTester.testGameWidget( 'when hits are multiples of 10 times adds a ScoringBehavior', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -101,7 +102,9 @@ void main() { await game.ready(); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final scores = game.descendants().whereType(); expect(scores.length, 1); }, @@ -110,6 +113,7 @@ void main() { flameTester.testGameWidget( "when hits are not multiple of 10 times doesn't add any ScoringBehavior", setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -131,7 +135,9 @@ void main() { await game.ready(); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final scores = game.descendants().whereType(); expect(scores.length, 0); }, diff --git a/test/game/components/android_acres/behaviors/ramp_multiplier_behavior_test.dart b/test/game/components/android_acres/behaviors/ramp_multiplier_behavior_test.dart index 7743c3cf..307570c5 100644 --- a/test/game/components/android_acres/behaviors/ramp_multiplier_behavior_test.dart +++ b/test/game/components/android_acres/behaviors/ramp_multiplier_behavior_test.dart @@ -80,6 +80,7 @@ void main() { 'adds MultiplierIncreased ' 'when hits are multiples of 5 times and multiplier is less than 6', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -105,9 +106,10 @@ void main() { ); streamController.add(state.copyWith(hits: 5)); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); verify(() => gameBloc.add(const MultiplierIncreased())).called(1); }, ); @@ -116,6 +118,7 @@ void main() { "doesn't add MultiplierIncreased " 'when hits are multiples of 5 times but multiplier is 6', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -140,9 +143,10 @@ void main() { ); streamController.add(state.copyWith(hits: 5)); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); verifyNever(() => gameBloc.add(const MultiplierIncreased())); }, ); @@ -178,7 +182,9 @@ void main() { await game.ready(); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); verifyNever(() => gameBloc.add(const MultiplierIncreased())); }, ); diff --git a/test/game/components/android_acres/behaviors/ramp_progress_behavior_test.dart b/test/game/components/android_acres/behaviors/ramp_progress_behavior_test.dart index f452f07f..abdd9d09 100644 --- a/test/game/components/android_acres/behaviors/ramp_progress_behavior_test.dart +++ b/test/game/components/android_acres/behaviors/ramp_progress_behavior_test.dart @@ -77,6 +77,7 @@ void main() { 'adds onProgressed ' 'when hits and multiplier are less than 6', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -105,7 +106,9 @@ void main() { streamController.add(state.copyWith(hits: 5)); await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -120,6 +123,7 @@ void main() { 'adds onProgressed ' 'when hits and multiplier are 6 but arrow is not fully lit', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -148,7 +152,9 @@ void main() { streamController.add(state.copyWith(hits: 5)); await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -163,6 +169,7 @@ void main() { "doesn't add onProgressed " 'when hits and multiplier are 6 and arrow is fully lit', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -194,9 +201,10 @@ void main() { lightState: ArrowLightState.active5, ), ); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -212,6 +220,7 @@ void main() { 'adds onProgressed to dim arrow ' 'when arrow is fully lit after hit and multiplier is less than 6', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -243,9 +252,10 @@ void main() { lightState: ArrowLightState.active5, ), ); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -260,6 +270,7 @@ void main() { "doesn't add onProgressed to dim arrow " 'when arrow is not fully lit after hit', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -291,9 +302,10 @@ void main() { lightState: ArrowLightState.active4, ), ); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -308,6 +320,7 @@ void main() { "doesn't add onProgressed to dim arrow " 'when multiplier is 6 after hit', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController(); @@ -336,9 +349,10 @@ void main() { streamController.add( state.copyWith(hits: 4), ); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< diff --git a/test/game/components/android_acres/behaviors/ramp_reset_behavior_test.dart b/test/game/components/android_acres/behaviors/ramp_reset_behavior_test.dart index 8c35a97a..b3296082 100644 --- a/test/game/components/android_acres/behaviors/ramp_reset_behavior_test.dart +++ b/test/game/components/android_acres/behaviors/ramp_reset_behavior_test.dart @@ -76,6 +76,7 @@ void main() { flameTester.testGameWidget( 'calls onReset when round lost', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = GameState.initial(); final streamController = StreamController(); @@ -96,9 +97,10 @@ void main() { ); streamController.add(state.copyWith(rounds: state.rounds - 1)); - await Future.delayed(Duration.zero); }, - verify: (game, _) async { + verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< @@ -112,6 +114,7 @@ void main() { flameTester.testGameWidget( "doesn't call onReset when round stays the same", setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = GameState.initial(); final streamController = StreamController(); @@ -133,9 +136,10 @@ void main() { streamController .add(state.copyWith(roundScore: state.roundScore + 100)); - await Future.delayed(Duration.zero); }, verify: (game, tester) async { + game.update(0); + await tester.pump(); final bloc = game .descendants() .whereType< diff --git a/test/game/components/android_acres/behaviors/ramp_shot_behavior_test.dart b/test/game/components/android_acres/behaviors/ramp_shot_behavior_test.dart index 800079eb..5d5d17c0 100644 --- a/test/game/components/android_acres/behaviors/ramp_shot_behavior_test.dart +++ b/test/game/components/android_acres/behaviors/ramp_shot_behavior_test.dart @@ -80,6 +80,7 @@ void main() { flameTester.testGameWidget( 'adds a ScoringBehavior when hit', setUp: (game, _) async { + await game.onLoad(); final bloc = _MockSpaceshipRampCubit(); final state = SpaceshipRampState.initial(); final streamController = StreamController();