fix: update widgets

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

@ -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<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(
context: context,
child: const CharacterSelectionDialog(),
@ -50,7 +58,7 @@ class StartGameListener extends StatelessWidget {
}
}
Future<void> _onHowToPlay(BuildContext context) async {
void _onHowToPlay(BuildContext context) {
_showPinballDialog(
context: context,
child: HowToPlayDialog(

@ -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,
);
},
);

Loading…
Cancel
Save