|
|
|
@ -84,114 +84,6 @@ void main() {
|
|
|
|
|
verify(() => gameBloc.add(const BallLost())).called(1);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
group('listenWhen', () {
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
'listens when a ball has been lost',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.ensureAdd(ball);
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
final controller =
|
|
|
|
|
game.descendants().whereType<LaunchedBallController>().first;
|
|
|
|
|
|
|
|
|
|
final previousState = MockGameState();
|
|
|
|
|
final newState = MockGameState();
|
|
|
|
|
when(() => previousState.balls).thenReturn(3);
|
|
|
|
|
when(() => newState.balls).thenReturn(2);
|
|
|
|
|
|
|
|
|
|
expect(controller.listenWhen(previousState, newState), isTrue);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
'does not listen when a ball has not been lost',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.ensureAdd(ball);
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
final controller =
|
|
|
|
|
game.descendants().whereType<LaunchedBallController>().first;
|
|
|
|
|
|
|
|
|
|
final previousState = MockGameState();
|
|
|
|
|
final newState = MockGameState();
|
|
|
|
|
when(() => previousState.balls).thenReturn(3);
|
|
|
|
|
when(() => newState.balls).thenReturn(3);
|
|
|
|
|
|
|
|
|
|
expect(controller.listenWhen(previousState, newState), isFalse);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('onNewState', () {
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
'removes ball',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.ensureAdd(ball);
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(1);
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
await game.ready();
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
expect(game.contains(ball), isFalse);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
'spawns a new ball when the ball is not the last one',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.ensureAdd(ball);
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
final previousBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final currentBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
|
|
|
|
|
|
expect(currentBalls.contains(ball), isFalse);
|
|
|
|
|
expect(currentBalls.length, equals(previousBalls.length));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
'does not spawn a new ball is the last one',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.ensureAdd(ball);
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(0);
|
|
|
|
|
|
|
|
|
|
final previousBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final currentBalls = game.descendants().whereType<Ball>();
|
|
|
|
|
|
|
|
|
|
expect(currentBalls.contains(ball), isFalse);
|
|
|
|
|
expect(
|
|
|
|
|
currentBalls.length,
|
|
|
|
|
equals((previousBalls..remove(ball)).length),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|