test: modified Flipper and Plunger tests

pull/345/head
alestiago 3 years ago
parent e4efd2760a
commit 8d99cf65ab

@ -22,25 +22,19 @@ void main() {
() => EmptyPinballTestGame(assets: assets),
);
group('FlipperController', () {
late GameBloc gameBloc;
setUp(() {
gameBloc = _MockGameBloc();
});
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
gameBuilder: EmptyPinballTestGame.new,
blocBuilder: () {
final bloc = _MockGameBloc();
const state = GameState(
totalScore: 0,
roundScore: 0,
multiplier: 1,
rounds: 0,
bonusHistory: [],
status: GameStatus.playing,
);
whenListen(bloc, Stream.value(state), initialState: state);
return bloc;
},
blocBuilder: () => gameBloc,
assets: assets,
);
group('FlipperController', () {
group('onKeyEvent', () {
final leftKeys = UnmodifiableListView([
LogicalKeyboardKey.arrowLeft,
@ -66,6 +60,12 @@ void main() {
'moves upwards '
'when ${event.logicalKey.keyLabel} is pressed',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ready();
await game.add(flipper);
controller.onKeyEvent(event, {});
@ -80,6 +80,14 @@ void main() {
flameBlocTester.testGameWidget(
'does nothing when is game over',
setUp: (game, tester) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial().copyWith(
status: GameStatus.gameOver,
),
);
await game.ensureAdd(flipper);
controller.onKeyEvent(event, {});
},
@ -95,6 +103,12 @@ void main() {
'moves downwards '
'when ${event.logicalKey.keyLabel} is released',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ready();
await game.add(flipper);
controller.onKeyEvent(event, {});
@ -110,6 +124,12 @@ void main() {
'does nothing '
'when ${event.logicalKey.keyLabel} is released',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ready();
await game.add(flipper);
controller.onKeyEvent(event, {});
@ -136,6 +156,12 @@ void main() {
'moves upwards '
'when ${event.logicalKey.keyLabel} is pressed',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ready();
await game.add(flipper);
controller.onKeyEvent(event, {});
@ -151,6 +177,12 @@ void main() {
'moves downwards '
'when ${event.logicalKey.keyLabel} is released',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ready();
await game.add(flipper);
controller.onKeyEvent(event, {});
@ -165,6 +197,14 @@ void main() {
flameBlocTester.testGameWidget(
'does nothing when is game over',
setUp: (game, tester) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial().copyWith(
status: GameStatus.gameOver,
),
);
await game.ensureAdd(flipper);
controller.onKeyEvent(event, {});
},

@ -17,24 +17,18 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(EmptyPinballTestGame.new);
group('PlungerController', () {
late GameBloc gameBloc;
setUp(() {
gameBloc = _MockGameBloc();
});
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
gameBuilder: EmptyPinballTestGame.new,
blocBuilder: () {
final bloc = _MockGameBloc();
const state = GameState(
totalScore: 0,
roundScore: 0,
multiplier: 1,
rounds: 0,
bonusHistory: [],
status: GameStatus.playing,
);
whenListen(bloc, Stream.value(state), initialState: state);
return bloc;
},
blocBuilder: () => gameBloc,
);
group('PlungerController', () {
group('onKeyEvent', () {
final downKeys = UnmodifiableListView([
LogicalKeyboardKey.arrowDown,
@ -56,6 +50,12 @@ void main() {
'moves down '
'when ${event.logicalKey.keyLabel} is pressed',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ensureAdd(plunger);
controller.onKeyEvent(event, {});
@ -71,6 +71,12 @@ void main() {
'when ${event.logicalKey.keyLabel} is released '
'and plunger is below its starting position',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ensureAdd(plunger);
plunger.body.setTransform(Vector2(0, 1), 0);
controller.onKeyEvent(event, {});
@ -86,6 +92,12 @@ void main() {
'does not move when ${event.logicalKey.keyLabel} is released '
'and plunger is in its starting position',
(game) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial(),
);
await game.ensureAdd(plunger);
controller.onKeyEvent(event, {});
@ -99,6 +111,14 @@ void main() {
flameBlocTester.testGameWidget(
'does nothing when is game over',
setUp: (game, tester) async {
whenListen(
gameBloc,
const Stream<GameState>.empty(),
initialState: const GameState.initial().copyWith(
status: GameStatus.gameOver,
),
);
await game.ensureAdd(plunger);
controller.onKeyEvent(event, {});
},

Loading…
Cancel
Save