fix: update StartGameListener

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

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

@ -18,40 +18,62 @@ void main() {
pinballGame = MockPinballGame();
});
// TODO(arturplaczek): need to fix that test
testWidgets(
'on selectCharacter status calls start on the game controller and shows '
'SelectCharacter dialog',
(tester) async {
whenListen(
startGameBloc,
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,
selectCharacterDelay: 0,
child: const SizedBox.shrink(),
),
startGameBloc: startGameBloc,
);
verify(gameController.start).called(1);
await tester.pumpAndSettle(kThemeAnimationDuration);
await expectLater(
find.byType(CharacterSelectionDialog),
findsOneWidget,
);
},
);
group('on selectCharacter status', () {
testWidgets(
'calls start on the game controller',
(tester) async {
whenListen(
startGameBloc,
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,
);
},
);
testWidgets(
'shows SelectCharacter dialog',
(tester) async {
whenListen(
startGameBloc,
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(
'on howToPlay status shows HowToPlay dialog',

Loading…
Cancel
Save