From 2c5ac4224f5f2796e97ce845f4be558a7cbd29b1 Mon Sep 17 00:00:00 2001 From: arturplaczek Date: Fri, 29 Apr 2022 00:22:15 +0200 Subject: [PATCH] fix: update widgets --- .../widgets/start_game_listener.dart | 14 +++++++-- .../widgets/start_game_listener_test.dart | 31 ++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/start_game/widgets/start_game_listener.dart b/lib/start_game/widgets/start_game_listener.dart index a7fed6aa..a29b1f12 100644 --- a/lib/start_game/widgets/start_game_listener.dart +++ b/lib/start_game/widgets/start_game_listener.dart @@ -12,12 +12,15 @@ class StartGameListener extends StatelessWidget { Key? key, required Widget child, required PinballGame game, + int selectCharacterDelay = 1300, }) : _child = child, _game = game, + _selectCharacterDelay = selectCharacterDelay, super(key: key); final Widget _child; final PinballGame _game; + final int _selectCharacterDelay; @override Widget build(BuildContext context) { @@ -27,13 +30,13 @@ class StartGameListener extends StatelessWidget { case StartGameStatus.initial: break; case StartGameStatus.selectCharacter: + _game.gameFlowController.start(); _onSelectCharacter(context); break; case StartGameStatus.howToPlay: _onHowToPlay(context); break; case StartGameStatus.play: - _game.gameFlowController.start(); break; } }, @@ -41,7 +44,12 @@ class StartGameListener extends StatelessWidget { ); } - void _onSelectCharacter(BuildContext context) { + Future _onSelectCharacter(BuildContext context) async { + // We need to add a delay between starting the game and showing + // the dialog. + await Future.delayed( + Duration(milliseconds: _selectCharacterDelay), + ); _showPinballDialog( context: context, child: const CharacterSelectionDialog(), @@ -50,7 +58,7 @@ class StartGameListener extends StatelessWidget { } } -Future _onHowToPlay(BuildContext context) async { +void _onHowToPlay(BuildContext context) { _showPinballDialog( context: context, child: HowToPlayDialog( diff --git a/test/start_game/widgets/start_game_listener_test.dart b/test/start_game/widgets/start_game_listener_test.dart index 5ce4ca94..39cc348b 100644 --- a/test/start_game/widgets/start_game_listener_test.dart +++ b/test/start_game/widgets/start_game_listener_test.dart @@ -18,8 +18,10 @@ void main() { pinballGame = MockPinballGame(); }); + // TODO(arturplaczek): need to fix that test testWidgets( - 'on selectCharacter status shows SelectCharacter dialog', + 'on selectCharacter status calls start on the game controller and shows ' + 'SelectCharacter dialog', (tester) async { whenListen( startGameBloc, @@ -28,18 +30,23 @@ void main() { ), initialState: const StartGameState.initial(), ); + final gameController = MockGameFlowController(); + when(() => pinballGame.gameFlowController) + .thenAnswer((_) => gameController); await tester.pumpApp( StartGameListener( game: pinballGame, + selectCharacterDelay: 0, child: const SizedBox.shrink(), ), startGameBloc: startGameBloc, ); + verify(gameController.start).called(1); - await tester.pumpAndSettle(); + await tester.pumpAndSettle(kThemeAnimationDuration); - expect( + await expectLater( find.byType(CharacterSelectionDialog), findsOneWidget, ); @@ -75,7 +82,7 @@ void main() { ); testWidgets( - 'on play status call start on game controller', + 'do nothing on play status', (tester) async { whenListen( startGameBloc, @@ -85,10 +92,6 @@ void main() { initialState: const StartGameState.initial(), ); - final gameController = MockGameFlowController(); - when(() => pinballGame.gameFlowController) - .thenAnswer((invocation) => gameController); - await tester.pumpApp( StartGameListener( game: pinballGame, @@ -97,10 +100,16 @@ void main() { startGameBloc: startGameBloc, ); - await tester.pumpAndSettle(kThemeAnimationDuration); - await tester.pumpAndSettle(kThemeAnimationDuration); + await tester.pumpAndSettle(); - verify(gameController.start).called(1); + expect( + find.byType(HowToPlayDialog), + findsNothing, + ); + expect( + find.byType(CharacterSelectionDialog), + findsNothing, + ); }, );