diff --git a/test/leaderboard/view/leaderboard_page_test.dart b/test/leaderboard/view/leaderboard_page_test.dart index daacb4a7..17e44938 100644 --- a/test/leaderboard/view/leaderboard_page_test.dart +++ b/test/leaderboard/view/leaderboard_page_test.dart @@ -8,6 +8,7 @@ import 'package:leaderboard_repository/leaderboard_repository.dart'; import 'package:mockingjay/mockingjay.dart'; import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/leaderboard/leaderboard.dart'; +import 'package:pinball/start_game/start_game.dart'; import 'package:pinball_theme/pinball_theme.dart'; import '../../helpers/helpers.dart'; @@ -145,21 +146,25 @@ void main() { expect(find.byType(ListView), findsOneWidget); }); - testWidgets('navigates to CharacterSelectionPage when retry is tapped', - (tester) async { - final navigator = MockNavigator(); - when(() => navigator.push(any())).thenAnswer((_) async {}); + testWidgets('adds PlayTapped event when retry is tapped', (tester) async { + final startGameBloc = MockStartGameBloc(); + + whenListen( + startGameBloc, + Stream.value(const StartGameState.initial()), + initialState: const StartGameState.initial(), + ); await tester.pumpApp( LeaderboardPage( theme: DashTheme(), ), - navigator: navigator, + startGameBloc: startGameBloc, ); await tester.ensureVisible(find.byType(TextButton)); await tester.tap(find.byType(TextButton)); - verify(() => navigator.push(any())).called(1); + verify(() => startGameBloc.add(PlayTapped())).called(1); }); }); } diff --git a/test/select_character/widgets/star_animation_test.dart b/test/select_character/widgets/star_animation_test.dart index a743407f..773c9305 100644 --- a/test/select_character/widgets/star_animation_test.dart +++ b/test/select_character/widgets/star_animation_test.dart @@ -11,7 +11,7 @@ void main() { group('loads SpriteAnimationWidget correctly for', () { setUpAll(() async { - await StarAnimation.loadAssets(); + await Future.wait(StarAnimation.loadAssets()); }); testWidgets('starA', (tester) async { diff --git a/test/start_game/widgets/start_game_listener_test.dart b/test/start_game/widgets/start_game_listener_test.dart index 5ce4ca94..9a7960ee 100644 --- a/test/start_game/widgets/start_game_listener_test.dart +++ b/test/start_game/widgets/start_game_listener_test.dart @@ -8,16 +8,41 @@ import 'package:pinball/start_game/start_game.dart'; import '../../helpers/helpers.dart'; +class MockBuildContext extends Mock implements BuildContext {} + void main() { late StartGameBloc startGameBloc; + late CharacterThemeCubit characterThemeCubit; late PinballGame pinballGame; + late GameFlowController gameController; + + setUpAll(() async { + await Future.wait( + [ + ...SelectedCharacter.loadAssets(MockBuildContext()), + ...StarAnimation.loadAssets(), + ], + ); + }); - group('StartGameListener', () { - setUp(() { - startGameBloc = MockStartGameBloc(); - pinballGame = MockPinballGame(); - }); + setUp(() { + startGameBloc = MockStartGameBloc(); + characterThemeCubit = MockCharacterThemeCubit(); + pinballGame = MockPinballGame(); + gameController = MockGameFlowController(); + + when(() => pinballGame.gameFlowController).thenAnswer( + (_) => gameController, + ); + whenListen( + characterThemeCubit, + Stream.value(const CharacterThemeState.initial()), + initialState: const CharacterThemeState.initial(), + ); + }); + + group('StartGameListener', () { testWidgets( 'on selectCharacter status shows SelectCharacter dialog', (tester) async { @@ -35,9 +60,10 @@ void main() { child: const SizedBox.shrink(), ), startGameBloc: startGameBloc, + characterThemeCubit: characterThemeCubit, ); - await tester.pumpAndSettle(); + await tester.pump(); expect( find.byType(CharacterSelectionDialog), @@ -63,9 +89,10 @@ void main() { child: const SizedBox.shrink(), ), startGameBloc: startGameBloc, + characterThemeCubit: characterThemeCubit, ); - await tester.pumpAndSettle(); + await tester.pump(); expect( find.byType(HowToPlayDialog), @@ -75,7 +102,7 @@ void main() { ); testWidgets( - 'on play status call start on game controller', + 'do nothing on play status', (tester) async { whenListen( startGameBloc, @@ -85,10 +112,6 @@ void main() { initialState: const StartGameState.initial(), ); - final gameController = MockGameFlowController(); - when(() => pinballGame.gameFlowController) - .thenAnswer((invocation) => gameController); - await tester.pumpApp( StartGameListener( game: pinballGame, @@ -97,10 +120,16 @@ void main() { startGameBloc: startGameBloc, ); - await tester.pumpAndSettle(kThemeAnimationDuration); - await tester.pumpAndSettle(kThemeAnimationDuration); + await tester.pump(); - verify(gameController.start).called(1); + expect( + find.byType(HowToPlayDialog), + findsNothing, + ); + expect( + find.byType(CharacterSelectionDialog), + findsNothing, + ); }, ); @@ -123,7 +152,7 @@ void main() { startGameBloc: startGameBloc, ); - await tester.pumpAndSettle(); + await tester.pump(); expect( find.byType(HowToPlayDialog),