|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
|
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:bloc_test/bloc_test.dart';
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
|
import 'package:flutter/painting.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
@ -22,6 +25,13 @@ void main() {
|
|
|
|
|
ball = Ball(baseColor: const Color(0xFF00FFFF));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can be instantiated', () {
|
|
|
|
|
expect(
|
|
|
|
|
BonusBallController(ball),
|
|
|
|
|
isA<LaunchedBallController>(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
'lost removes ball',
|
|
|
|
|
(game) async {
|
|
|
|
@ -39,6 +49,14 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('LaunchedBallController', () {
|
|
|
|
|
test('can be instantiated', () {
|
|
|
|
|
expect(
|
|
|
|
|
LaunchedBallController(MockBall()),
|
|
|
|
|
isA<LaunchedBallController>(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('description', () {
|
|
|
|
|
late Ball ball;
|
|
|
|
|
late GameBloc gameBloc;
|
|
|
|
|
|
|
|
|
@ -57,7 +75,7 @@ void main() {
|
|
|
|
|
gameBloc: () => gameBloc,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
tester.testGameWidget(
|
|
|
|
|
'lost adds BallLost to GameBloc',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
@ -73,13 +91,18 @@ void main() {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
group('listenWhen', () {
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
tester.testGameWidget(
|
|
|
|
|
'listens when a ball has been lost',
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.add(ball);
|
|
|
|
|
await game.ready();
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
final controller =
|
|
|
|
|
game.descendants().whereType<LaunchedBallController>().first;
|
|
|
|
|
|
|
|
|
|
final previousState = MockGameState();
|
|
|
|
|
final newState = MockGameState();
|
|
|
|
@ -90,45 +113,44 @@ void main() {
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
tester.testGameWidget(
|
|
|
|
|
'does not listen when a ball has not been lost',
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.add(ball);
|
|
|
|
|
await game.ready();
|
|
|
|
|
},
|
|
|
|
|
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), isTrue);
|
|
|
|
|
expect(controller.listenWhen(previousState, newState), isFalse);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('onNewState', () {
|
|
|
|
|
setUp(() {
|
|
|
|
|
whenListen(
|
|
|
|
|
gameBloc,
|
|
|
|
|
const Stream<GameState>.empty(),
|
|
|
|
|
initialState: const GameState.initial(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tester.testGameWidget(
|
|
|
|
|
'removes ball',
|
|
|
|
|
setUp: (game, _) => game.ready(),
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.add(ball);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(any());
|
|
|
|
|
controller.onNewState(MockGameState());
|
|
|
|
|
|
|
|
|
|
when(() => state.balls).thenReturn(1);
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
await game.ready();
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
expect(game.contains(ball), isFalse);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
@ -137,16 +159,21 @@ void main() {
|
|
|
|
|
'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.add(ball);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(2);
|
|
|
|
|
|
|
|
|
|
final previousBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
expect(game.contains(ball), isFalse);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final currentBalls = game.descendants().whereType<Ball>();
|
|
|
|
|
|
|
|
|
|
// TODO(erickzanardo): This expect should be in verify?
|
|
|
|
|
expect(currentBalls.length, equals(previousBalls.length));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -154,18 +181,27 @@ void main() {
|
|
|
|
|
'does not spawn a new ball is the last one',
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
final controller = LaunchedBallController(ball);
|
|
|
|
|
await ball.add(controller);
|
|
|
|
|
await game.add(ball);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final state = MockGameState();
|
|
|
|
|
when(() => state.balls).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
final previousBalls = game.descendants().whereType<Ball>().toList();
|
|
|
|
|
controller.onNewState(state);
|
|
|
|
|
},
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
expect(game.contains(ball), isFalse);
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
final currentBalls = game.descendants().whereType<Ball>();
|
|
|
|
|
|
|
|
|
|
// TODO(erickzanardo): This expect should be in verify?
|
|
|
|
|
expect(
|
|
|
|
|
currentBalls.length,
|
|
|
|
|
equals((previousBalls..remove(ball)).length),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|