From d157d81e919bfa30c97edc85a0b7180b2d770ff9 Mon Sep 17 00:00:00 2001 From: Alvaro Almeida Freire Stivi Date: Tue, 2 Jul 2024 22:02:37 +0000 Subject: [PATCH] Fixes even more async test issues --- test/game/components/backbox/backbox_test.dart | 18 ++++++++++++++++++ .../flutter_forest_bonus_behavior_test.dart | 10 +++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/test/game/components/backbox/backbox_test.dart b/test/game/components/backbox/backbox_test.dart index c6737bf6..2bd7d867 100644 --- a/test/game/components/backbox/backbox_test.dart +++ b/test/game/components/backbox/backbox_test.dart @@ -300,6 +300,7 @@ void main() { flameTester.testGameWidget( 'adds PlayerInitialsSubmitted when initials are submitted', setUp: (game, _) async { + await game.onLoad(); final state = InitialsFormState( score: 10, character: game.character, @@ -336,6 +337,7 @@ void main() { flameTester.testGameWidget( 'adds GameOverInfoDisplay when InitialsSuccessState', setUp: (game, _) async { + await game.onLoad(); final state = InitialsSuccessState(score: 100); whenListen( bloc, @@ -350,6 +352,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -363,6 +366,7 @@ void main() { 'adds the mobile controls overlay ' 'when platform is mobile at InitialsFormState', setUp: (game, _) async { + await game.onLoad(); final platformHelper = _MockPlatformHelper(); final state = InitialsFormState( score: 10, @@ -382,6 +386,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -395,6 +400,7 @@ void main() { 'remove the mobile controls overlay ' 'when InitialsSuccessState', setUp: (game, _) async { + await game.onLoad(); final platformHelper = _MockPlatformHelper(); final state = InitialsSuccessState(score: 10); whenListen( @@ -411,6 +417,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -423,6 +430,7 @@ void main() { flameTester.testGameWidget( 'adds InitialsSubmissionSuccessDisplay on InitialsSuccessState', setUp: (game, _) async { + await game.onLoad(); final state = InitialsSuccessState(score: 100); whenListen( bloc, @@ -437,6 +445,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -449,6 +458,7 @@ void main() { flameTester.testGameWidget( 'adds ShareScoreRequested event when sharing', setUp: (game, _) async { + await game.onLoad(); final state = InitialsSuccessState(score: 100); whenListen( bloc, @@ -484,6 +494,7 @@ void main() { flameTester.testGameWidget( 'adds InitialsSubmissionFailureDisplay on InitialsFailureState', setUp: (game, _) async { + await game.onLoad(); whenListen( bloc, Stream.empty(), @@ -500,6 +511,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -521,6 +533,7 @@ void main() { flameTester.testGameWidget( 'adds ShareDisplay on ShareState', setUp: (game, _) async { + await game.onLoad(); final state = ShareState(score: 100); whenListen( bloc, @@ -535,6 +548,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { expect( @@ -547,6 +561,7 @@ void main() { flameTester.testGameWidget( 'opens Facebook link when sharing with Facebook', setUp: (game, _) async { + await game.onLoad(); when(() => urlLauncher.canLaunch(any())) .thenAnswer((_) async => true); when( @@ -711,6 +726,7 @@ void main() { flameTester.testGameWidget( 'closes the subscription when it is removed', setUp: (game, _) async { + await game.onLoad(); final streamController = StreamController(); whenListen( bloc, @@ -751,6 +767,7 @@ void main() { flameTester.testGameWidget( 'adds PlayerInitialsSubmitted when the timer is finished', setUp: (game, _) async { + await game.onLoad(); final initialState = InitialsFailureState( score: 10, character: theme.DashTheme(), @@ -769,6 +786,7 @@ void main() { backbox, platformHelper: platformHelper, ); + await game.ready(); }, verify: (game, _) async { game.update(4); 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 8c59a62c..d994f9c0 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 @@ -77,6 +77,7 @@ void main() { 'adds GameBonus.dashNest to the game ' 'when signpost becomes fully activated', setUp: (game, tester) async { + await game.onLoad(); final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final signpostBloc = _MockSignpostCubit(); @@ -94,6 +95,7 @@ void main() { signpostBloc: signpostBloc, ); await parent.ensureAdd(behavior); + await game.ready(); streamController.add(SignpostState.active3); await tester.pump(); @@ -108,6 +110,7 @@ void main() { 'calls onProgressed and onReset ' 'when signpost becomes fully activated', setUp: (game, tester) async { + await game.onLoad(); final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final dashBumpersBloc = _MockDashBumpersCubit(); @@ -127,6 +130,7 @@ void main() { dashBumpersBloc: dashBumpersBloc, ); await parent.ensureAdd(behavior); + await game.ready(); streamController.add(SignpostState.active3); await tester.pump(); @@ -140,6 +144,7 @@ void main() { 'adds BonusBallSpawningBehavior to the game ' 'when signpost becomes fully activated', setUp: (game, tester) async { + await game.onLoad(); final behavior = FlutterForestBonusBehavior(); final parent = FlutterForest.test(); final signpostBloc = _MockSignpostCubit(); @@ -157,11 +162,10 @@ void main() { signpostBloc: signpostBloc, ); await parent.ensureAdd(behavior); - streamController.add(SignpostState.active3); - await tester.pump(); await game.ready(); - + await tester.pump(); + expect( game.descendants().whereType().length, equals(1),