From 2785f881baa90162333d7217c8479999040c1e49 Mon Sep 17 00:00:00 2001 From: arturplaczek Date: Fri, 29 Apr 2022 16:35:41 +0200 Subject: [PATCH] fix: update test --- test/game/view/pinball_game_page_test.dart | 24 +++++++++++++++++++ .../character_selection_dialog_test.dart | 21 ++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/test/game/view/pinball_game_page_test.dart b/test/game/view/pinball_game_page_test.dart index 1795b88e..3fe36106 100644 --- a/test/game/view/pinball_game_page_test.dart +++ b/test/game/view/pinball_game_page_test.dart @@ -16,11 +16,13 @@ void main() { group('PinballGamePage', () { late CharacterThemeCubit characterThemeCubit; late GameBloc gameBloc; + late StartGameBloc startGameBloc; setUp(() async { await Future.wait(game.preLoadAssets()); characterThemeCubit = MockCharacterThemeCubit(); gameBloc = MockGameBloc(); + startGameBloc = MockStartGameBloc(); whenListen( characterThemeCubit, @@ -28,6 +30,12 @@ void main() { initialState: const CharacterThemeState.initial(), ); + whenListen( + startGameBloc, + const Stream.empty(), + initialState: const StartGameState.initial(), + ); + whenListen( gameBloc, Stream.value(const GameState.initial()), @@ -170,9 +178,17 @@ void main() { group('PinballGameView', () { final gameBloc = MockGameBloc(); final startGameBloc = MockStartGameBloc(); + late CharacterThemeCubit characterThemeCubit; setUp(() async { await Future.wait(game.preLoadAssets()); + characterThemeCubit = MockCharacterThemeCubit(); + + whenListen( + characterThemeCubit, + const Stream.empty(), + initialState: const CharacterThemeState.initial(), + ); whenListen( gameBloc, @@ -192,6 +208,7 @@ void main() { PinballGameView(game: game), gameBloc: gameBloc, startGameBloc: startGameBloc, + characterThemeCubit: characterThemeCubit, ); expect( @@ -216,10 +233,17 @@ void main() { initialState: startGameState, ); + whenListen( + startGameBloc, + Stream.value(startGameState), + initialState: startGameState, + ); + await tester.pumpApp( PinballGameView(game: game), gameBloc: gameBloc, startGameBloc: startGameBloc, + characterThemeCubit: characterThemeCubit, ); expect( diff --git a/test/select_character/character_selection_dialog_test.dart b/test/select_character/character_selection_dialog_test.dart index a0ada832..92fe96f3 100644 --- a/test/select_character/character_selection_dialog_test.dart +++ b/test/select_character/character_selection_dialog_test.dart @@ -4,16 +4,25 @@ import 'package:bloc_test/bloc_test.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockingjay/mockingjay.dart'; +import 'package:pinball/game/game.dart'; +import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/select_character/select_character.dart'; import 'package:pinball/start_game/start_game.dart'; import 'package:pinball_theme/pinball_theme.dart'; import '../helpers/helpers.dart'; +class MockBuildContext extends Mock implements BuildContext {} + void main() { late CharacterThemeCubit characterThemeCubit; late StartGameBloc startGameBloc; + setUpAll(() async { + await Future.wait(SelectedCharacter.loadAssets(MockBuildContext())); + await Future.wait(StarAnimation.loadAssets()); + }); + setUp(() { characterThemeCubit = MockCharacterThemeCubit(); startGameBloc = MockStartGameBloc(); @@ -37,15 +46,17 @@ void main() { group('CharacterSelectionView', () { testWidgets('renders correctly', (tester) async { - const titleText = 'Choose your character!'; + final l10n = await AppLocalizations.delegate.load(const Locale('en')); + await tester.pumpApp( CharacterSelectionView(), characterThemeCubit: characterThemeCubit, ); - expect(find.text(titleText), findsOneWidget); + expect(find.text(l10n.characterSelectionTitle), findsOneWidget); + expect(find.text(l10n.characterSelectionSubtitle), findsOneWidget); expect(find.byType(SelectedCharacter), findsOneWidget); - expect(find.byType(TextButton), findsOneWidget); + expect(find.byType(PinballButton), findsOneWidget); }); testWidgets('calls characterSelected when a character image is tapped', @@ -76,8 +87,8 @@ void main() { characterThemeCubit: characterThemeCubit, startGameBloc: startGameBloc, ); - await tester.ensureVisible(find.byType(TextButton)); - await tester.tap(find.byType(TextButton)); + await tester.ensureVisible(find.byType(PinballButton)); + await tester.tap(find.byType(PinballButton)); await tester.pumpAndSettle(); verify(() => startGameBloc.add(CharacterSelected())).called(1);