test: refactored tests for pinballgame

pull/213/head
RuiAlonso 3 years ago
parent 8ddd59176e
commit c048ae7065

@ -77,11 +77,10 @@ void main() {
// [BallScorePointsCallback] once the following issue is resolved: // [BallScorePointsCallback] once the following issue is resolved:
// https://github.com/flame-engine/flame/issues/1416 // https://github.com/flame-engine/flame/issues/1416
group('components', () { group('components', () {
flameBlocTester.test( flameTester.test(
'has only one BottomWall', 'has only one BottomWall',
(game) async { (game) async {
await game.ready(); await game.ready();
expect( expect(
game.children.whereType<BottomWall>().length, game.children.whereType<BottomWall>().length,
equals(1), equals(1),
@ -119,15 +118,12 @@ void main() {
group('controller', () { group('controller', () {
// TODO(alestiago): Write test to be controller agnostic. // TODO(alestiago): Write test to be controller agnostic.
group('listenWhen', () { group('listenWhen', () {
flameBlocTester.testGameWidget( flameTester.test(
'listens when all balls are lost and there are more than 0 balls', 'listens when all balls are lost and there are more than 0 rounds',
setUp: (game, tester) async { (game) async {
final newState = MockGameState(); final newState = MockGameState();
when(() => newState.balls).thenReturn(2); when(() => newState.balls).thenReturn(0);
game.descendants().whereType<ControlledBall>().forEach( when(() => newState.rounds).thenReturn(2);
(ball) => ball.controller.lost(),
);
await game.ready();
expect( expect(
game.controller.listenWhen(MockGameState(), newState), game.controller.listenWhen(MockGameState(), newState),
@ -141,11 +137,8 @@ void main() {
(game) async { (game) async {
final newState = MockGameState(); final newState = MockGameState();
when(() => newState.balls).thenReturn(1); when(() => newState.balls).thenReturn(1);
when(() => newState.rounds).thenReturn(2);
expect(
game.descendants().whereType<Ball>().length,
greaterThan(0),
);
expect( expect(
game.controller.listenWhen(MockGameState(), newState), game.controller.listenWhen(MockGameState(), newState),
isFalse, isFalse,
@ -153,21 +146,13 @@ void main() {
}, },
); );
flameBlocTester.test( flameTester.test(
"doesn't listen when no balls left", "doesn't listen when no balls left",
(game) async { (game) async {
final newState = MockGameState(); final newState = MockGameState();
when(() => newState.balls).thenReturn(0); when(() => newState.balls).thenReturn(1);
when(() => newState.rounds).thenReturn(0);
game.descendants().whereType<ControlledBall>().forEach(
(ball) => ball.controller.lost(),
);
await game.ready();
expect(
game.descendants().whereType<Ball>().isEmpty,
isTrue,
);
expect( expect(
game.controller.listenWhen(MockGameState(), newState), game.controller.listenWhen(MockGameState(), newState),
isFalse, isFalse,
@ -223,38 +208,5 @@ void main() {
equals(previousBalls.length + 1), equals(previousBalls.length + 1),
); );
}); });
group('controller', () {
late GameBloc gameBloc;
setUp(() {
gameBloc = GameBloc();
});
final debugModeFlameBlocTester =
FlameBlocTester<DebugPinballGame, GameBloc>(
gameBuilder: DebugPinballTestGame.new,
blocBuilder: () => gameBloc,
assets: assets,
);
debugModeFlameBlocTester.testGameWidget(
'ignores debug balls',
setUp: (game, tester) async {
final newState = MockGameState();
when(() => newState.balls).thenReturn(1);
await game.ready();
game.children.removeWhere((component) => component is Ball);
await game.ready();
await game.ensureAdd(ControlledBall.debug());
expect(
game.controller.listenWhen(MockGameState(), newState),
isTrue,
);
},
);
});
}); });
} }

Loading…
Cancel
Save