From 095a22fd9c601aaa2d7e4b468b76826e655f9810 Mon Sep 17 00:00:00 2001 From: alestiago Date: Fri, 6 May 2022 04:18:22 +0100 Subject: [PATCH] test: updeted ControlledFlipperTest --- .../components/controlled_flipper_test.dart | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/test/game/components/controlled_flipper_test.dart b/test/game/components/controlled_flipper_test.dart index 561ddccb..116e903c 100644 --- a/test/game/components/controlled_flipper_test.dart +++ b/test/game/components/controlled_flipper_test.dart @@ -23,10 +23,10 @@ class _TestGame extends Forge2DGame with HasKeyboardHandlerComponents { ]); } - Future pump(Flipper flipper, {GameBloc? gameBloc}) { + Future pump(Flipper flipper, {required GameBloc gameBloc}) { return ensureAdd( FlameBlocProvider.value( - value: gameBloc ?? (GameBloc()..add(const GameStarted())), + value: gameBloc, children: [flipper], ), ); @@ -74,11 +74,13 @@ void main() { whenListen( gameBloc, const Stream.empty(), - initialState: const GameState.initial(), + initialState: const GameState.initial().copyWith( + status: GameStatus.playing, + ), ); await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isNegative); @@ -114,8 +116,16 @@ void main() { 'moves downwards ' 'when ${event.logicalKey.keyLabel} is released', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial().copyWith( + status: GameStatus.playing, + ), + ); + await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isPositive); @@ -136,7 +146,7 @@ void main() { ); await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isZero); @@ -164,11 +174,13 @@ void main() { whenListen( gameBloc, const Stream.empty(), - initialState: const GameState.initial(), + initialState: const GameState.initial().copyWith( + status: GameStatus.playing, + ), ); await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isNegative); @@ -185,11 +197,13 @@ void main() { whenListen( gameBloc, const Stream.empty(), - initialState: const GameState.initial(), + initialState: const GameState.initial().copyWith( + status: GameStatus.playing, + ), ); await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isPositive); @@ -225,8 +239,16 @@ void main() { 'does nothing ' 'when ${event.logicalKey.keyLabel} is released', (game) async { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial().copyWith( + status: GameStatus.playing, + ), + ); + await game.ready(); - await game.pump(flipper); + await game.pump(flipper, gameBloc: gameBloc); controller.onKeyEvent(event, {}); expect(flipper.body.linearVelocity.y, isZero);