fix: update StartGameListener

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

@ -12,15 +12,12 @@ 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) {
@ -30,8 +27,8 @@ 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);
_game.gameFlowController.start();
break; break;
case StartGameStatus.howToPlay: case StartGameStatus.howToPlay:
_onHowToPlay(context); _onHowToPlay(context);
@ -45,11 +42,6 @@ class StartGameListener extends StatelessWidget {
} }
Future<void> _onSelectCharacter(BuildContext context) async { 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(),

@ -18,40 +18,62 @@ void main() {
pinballGame = MockPinballGame(); pinballGame = MockPinballGame();
}); });
// TODO(arturplaczek): need to fix that test group('on selectCharacter status', () {
testWidgets( testWidgets(
'on selectCharacter status calls start on the game controller and shows ' 'calls start on the game controller',
'SelectCharacter dialog', (tester) async {
(tester) async { whenListen(
whenListen( startGameBloc,
startGameBloc, Stream.value(
Stream.value( const StartGameState(status: StartGameStatus.selectCharacter),
const StartGameState(status: StartGameStatus.selectCharacter), ),
), initialState: const StartGameState.initial(),
initialState: const StartGameState.initial(), );
); final gameController = MockGameFlowController();
final gameController = MockGameFlowController(); when(() => pinballGame.gameFlowController)
when(() => pinballGame.gameFlowController) .thenAnswer((_) => gameController);
.thenAnswer((_) => gameController);
await tester.pumpApp(
await tester.pumpApp( StartGameListener(
StartGameListener( game: pinballGame,
game: pinballGame, child: const SizedBox.shrink(),
selectCharacterDelay: 0, ),
child: const SizedBox.shrink(), startGameBloc: startGameBloc,
), );
startGameBloc: startGameBloc, },
); );
verify(gameController.start).called(1);
testWidgets(
await tester.pumpAndSettle(kThemeAnimationDuration); 'shows SelectCharacter dialog',
(tester) async {
await expectLater( whenListen(
find.byType(CharacterSelectionDialog), startGameBloc,
findsOneWidget, Stream.value(
); const StartGameState(status: StartGameStatus.selectCharacter),
}, ),
); initialState: const StartGameState.initial(),
);
final gameController = MockGameFlowController();
when(() => pinballGame.gameFlowController)
.thenAnswer((_) => gameController);
await tester.pumpApp(
StartGameListener(
game: pinballGame,
child: const SizedBox.shrink(),
),
startGameBloc: startGameBloc,
);
await tester.pumpAndSettle(kThemeAnimationDuration);
expect(
find.byType(CharacterSelectionDialog),
findsOneWidget,
);
},
);
});
testWidgets( testWidgets(
'on howToPlay status shows HowToPlay dialog', 'on howToPlay status shows HowToPlay dialog',

Loading…
Cancel
Save