fix: update widgets

pull/254/head
arturplaczek 3 years ago
parent 01a44c3a51
commit 2c5ac4224f

@ -12,12 +12,15 @@ class StartGameListener extends StatelessWidget {
Key? key, Key? key,
required Widget child, required Widget child,
required PinballGame game, required PinballGame game,
int selectCharacterDelay = 1300,
}) : _child = child, }) : _child = child,
_game = game, _game = game,
_selectCharacterDelay = selectCharacterDelay,
super(key: key); super(key: key);
final Widget _child; final Widget _child;
final PinballGame _game; final PinballGame _game;
final int _selectCharacterDelay;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -27,13 +30,13 @@ class StartGameListener extends StatelessWidget {
case StartGameStatus.initial: case StartGameStatus.initial:
break; break;
case StartGameStatus.selectCharacter: case StartGameStatus.selectCharacter:
_game.gameFlowController.start();
_onSelectCharacter(context); _onSelectCharacter(context);
break; break;
case StartGameStatus.howToPlay: case StartGameStatus.howToPlay:
_onHowToPlay(context); _onHowToPlay(context);
break; break;
case StartGameStatus.play: case StartGameStatus.play:
_game.gameFlowController.start();
break; break;
} }
}, },
@ -41,7 +44,12 @@ class StartGameListener extends StatelessWidget {
); );
} }
void _onSelectCharacter(BuildContext context) { Future<void> _onSelectCharacter(BuildContext context) async {
// We need to add a delay between starting the game and showing
// the dialog.
await Future<void>.delayed(
Duration(milliseconds: _selectCharacterDelay),
);
_showPinballDialog( _showPinballDialog(
context: context, context: context,
child: const CharacterSelectionDialog(), child: const CharacterSelectionDialog(),
@ -50,7 +58,7 @@ class StartGameListener extends StatelessWidget {
} }
} }
Future<void> _onHowToPlay(BuildContext context) async { void _onHowToPlay(BuildContext context) {
_showPinballDialog( _showPinballDialog(
context: context, context: context,
child: HowToPlayDialog( child: HowToPlayDialog(

@ -18,8 +18,10 @@ void main() {
pinballGame = MockPinballGame(); pinballGame = MockPinballGame();
}); });
// TODO(arturplaczek): need to fix that test
testWidgets( testWidgets(
'on selectCharacter status shows SelectCharacter dialog', 'on selectCharacter status calls start on the game controller and shows '
'SelectCharacter dialog',
(tester) async { (tester) async {
whenListen( whenListen(
startGameBloc, startGameBloc,
@ -28,18 +30,23 @@ void main() {
), ),
initialState: const StartGameState.initial(), initialState: const StartGameState.initial(),
); );
final gameController = MockGameFlowController();
when(() => pinballGame.gameFlowController)
.thenAnswer((_) => gameController);
await tester.pumpApp( await tester.pumpApp(
StartGameListener( StartGameListener(
game: pinballGame, game: pinballGame,
selectCharacterDelay: 0,
child: const SizedBox.shrink(), child: const SizedBox.shrink(),
), ),
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
); );
verify(gameController.start).called(1);
await tester.pumpAndSettle(); await tester.pumpAndSettle(kThemeAnimationDuration);
expect( await expectLater(
find.byType(CharacterSelectionDialog), find.byType(CharacterSelectionDialog),
findsOneWidget, findsOneWidget,
); );
@ -75,7 +82,7 @@ void main() {
); );
testWidgets( testWidgets(
'on play status call start on game controller', 'do nothing on play status',
(tester) async { (tester) async {
whenListen( whenListen(
startGameBloc, startGameBloc,
@ -85,10 +92,6 @@ void main() {
initialState: const StartGameState.initial(), initialState: const StartGameState.initial(),
); );
final gameController = MockGameFlowController();
when(() => pinballGame.gameFlowController)
.thenAnswer((invocation) => gameController);
await tester.pumpApp( await tester.pumpApp(
StartGameListener( StartGameListener(
game: pinballGame, game: pinballGame,
@ -97,10 +100,16 @@ void main() {
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
); );
await tester.pumpAndSettle(kThemeAnimationDuration); await tester.pumpAndSettle();
await tester.pumpAndSettle(kThemeAnimationDuration);
verify(gameController.start).called(1); expect(
find.byType(HowToPlayDialog),
findsNothing,
);
expect(
find.byType(CharacterSelectionDialog),
findsNothing,
);
}, },
); );

Loading…
Cancel
Save