|
|
@ -103,10 +103,9 @@ 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', () {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
'has only one BottomWall',
|
|
|
|
'has only one BottomWall',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ensureAdd(BottomWall());
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.children.whereType<BottomWall>().length,
|
|
|
|
game.children.whereType<BottomWall>().length,
|
|
|
@ -115,9 +114,9 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
'has only one Plunger',
|
|
|
|
'has only one Plunger',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.children.whereType<Plunger>().length,
|
|
|
|
game.children.whereType<Plunger>().length,
|
|
|
@ -126,9 +125,9 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
'has one Board',
|
|
|
|
'has one Board',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.children.whereType<Board>().length,
|
|
|
|
game.children.whereType<Board>().length,
|
|
|
@ -137,23 +136,35 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
'one AlienZone',
|
|
|
|
'one AlienZone',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
expect(game.children.whereType<AlienZone>().length, equals(1));
|
|
|
|
expect(game.children.whereType<AlienZone>().length, equals(1));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
|
|
|
'one GoogleWord',
|
|
|
|
|
|
|
|
(game) async {
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
expect(game.children.whereType<GoogleWord>().length, equals(1));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
group('controller', () {
|
|
|
|
group('controller', () {
|
|
|
|
// TODO(alestiago): Write test to be controller agnostic.
|
|
|
|
|
|
|
|
group('listenWhen', () {
|
|
|
|
group('listenWhen', () {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
'listens when all balls are lost and there are more than 0 rounds',
|
|
|
|
'listens when all balls are lost and there are more than 0 rounds',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
// TODO(ruimiguel): check why testGameWidget doesn't add any ball
|
|
|
|
|
|
|
|
// to the game. Test needs to have no balls, so fortunately works.
|
|
|
|
final newState = MockGameState();
|
|
|
|
final newState = MockGameState();
|
|
|
|
when(() => newState.balls).thenReturn(0);
|
|
|
|
when(() => newState.isGameOver).thenReturn(false);
|
|
|
|
when(() => newState.rounds).thenReturn(2);
|
|
|
|
game.descendants().whereType<ControlledBall>().forEach(
|
|
|
|
|
|
|
|
(ball) => ball.controller.lost(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
@ -162,13 +173,16 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
"doesn't listen when some balls are left",
|
|
|
|
"doesn't listen when some balls are left",
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
final newState = MockGameState();
|
|
|
|
final newState = MockGameState();
|
|
|
|
when(() => newState.balls).thenReturn(1);
|
|
|
|
when(() => newState.isGameOver).thenReturn(false);
|
|
|
|
when(() => newState.rounds).thenReturn(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
game.descendants().whereType<ControlledBall>().length,
|
|
|
|
|
|
|
|
greaterThan(0),
|
|
|
|
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
|
isFalse,
|
|
|
|
isFalse,
|
|
|
@ -177,12 +191,21 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
"doesn't listen when no balls left",
|
|
|
|
"doesn't listen when game is over",
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
// TODO(ruimiguel): check why testGameWidget doesn't add any ball
|
|
|
|
|
|
|
|
// to the game. Test needs to have no balls, so fortunately works.
|
|
|
|
final newState = MockGameState();
|
|
|
|
final newState = MockGameState();
|
|
|
|
when(() => newState.balls).thenReturn(1);
|
|
|
|
when(() => newState.isGameOver).thenReturn(true);
|
|
|
|
when(() => newState.rounds).thenReturn(0);
|
|
|
|
game.descendants().whereType<ControlledBall>().forEach(
|
|
|
|
|
|
|
|
(ball) => ball.controller.lost(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
game.descendants().whereType<ControlledBall>().isEmpty,
|
|
|
|
|
|
|
|
isTrue,
|
|
|
|
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
|
game.controller.listenWhen(MockGameState(), newState),
|
|
|
|
isFalse,
|
|
|
|
isFalse,
|
|
|
@ -194,18 +217,16 @@ void main() {
|
|
|
|
group(
|
|
|
|
group(
|
|
|
|
'onNewState',
|
|
|
|
'onNewState',
|
|
|
|
() {
|
|
|
|
() {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.test(
|
|
|
|
'spawns a ball',
|
|
|
|
'spawns a ball',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final previousBalls =
|
|
|
|
final previousBalls =
|
|
|
|
game.descendants().whereType<Ball>().toList();
|
|
|
|
game.descendants().whereType<ControlledBall>().toList();
|
|
|
|
|
|
|
|
|
|
|
|
game.controller.onNewState(MockGameState());
|
|
|
|
game.controller.onNewState(MockGameState());
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
final currentBalls =
|
|
|
|
final currentBalls =
|
|
|
|
game.descendants().whereType<Ball>().toList();
|
|
|
|
game.descendants().whereType<ControlledBall>().toList();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
currentBalls.length,
|
|
|
|
currentBalls.length,
|
|
|
@ -220,25 +241,23 @@ void main() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
group('DebugPinballGame', () {
|
|
|
|
group('DebugPinballGame', () {
|
|
|
|
debugModeFlameTester.testGameWidget(
|
|
|
|
debugModeFlameTester.test(
|
|
|
|
'adds a ball on tap up',
|
|
|
|
'adds a ball on tap up',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
(game) async {
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final eventPosition = MockEventPosition();
|
|
|
|
final eventPosition = MockEventPosition();
|
|
|
|
when(() => eventPosition.game).thenReturn(Vector2.all(10));
|
|
|
|
when(() => eventPosition.game).thenReturn(Vector2.all(10));
|
|
|
|
|
|
|
|
|
|
|
|
final tapUpEvent = MockTapUpInfo();
|
|
|
|
final tapUpEvent = MockTapUpInfo();
|
|
|
|
when(() => tapUpEvent.eventPosition).thenReturn(eventPosition);
|
|
|
|
when(() => tapUpEvent.eventPosition).thenReturn(eventPosition);
|
|
|
|
|
|
|
|
|
|
|
|
final previousBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
final previousBalls =
|
|
|
|
|
|
|
|
game.descendants().whereType<ControlledBall>().toList();
|
|
|
|
|
|
|
|
|
|
|
|
game.onTapUp(tapUpEvent);
|
|
|
|
game.onTapUp(tapUpEvent);
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
game.children.whereType<Ball>().length,
|
|
|
|
game.children.whereType<ControlledBall>().length,
|
|
|
|
equals(previousBalls.length + 1),
|
|
|
|
equals(previousBalls.length + 1),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|