test: coverage

pull/333/head
RuiAlonso 3 years ago
parent a932f22aa8
commit bee6ab1fa8

@ -163,7 +163,6 @@ class _GameBallsController extends ComponentController<PinballGame>
} }
} }
// coverage:ignore-start
class DebugPinballGame extends PinballGame with FPSCounter, PanDetector { class DebugPinballGame extends PinballGame with FPSCounter, PanDetector {
DebugPinballGame({ DebugPinballGame({
required CharacterTheme characterTheme, required CharacterTheme characterTheme,
@ -181,7 +180,7 @@ class DebugPinballGame extends PinballGame with FPSCounter, PanDetector {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await add(_PreviewLine()); await add(PreviewLine());
await add(_DebugInformation()); await add(_DebugInformation());
} }
@ -211,23 +210,22 @@ class DebugPinballGame extends PinballGame with FPSCounter, PanDetector {
void onPanEnd(DragEndInfo info) { void onPanEnd(DragEndInfo info) {
if (lineEnd != null) { if (lineEnd != null) {
final line = lineEnd! - lineStart!; final line = lineEnd! - lineStart!;
onLine(line); _turboChargeBall(line);
lineEnd = null; lineEnd = null;
lineStart = null; lineStart = null;
} }
} }
void onLine(Vector2 line) { void _turboChargeBall(Vector2 line) {
final ball = ControlledBall.debug()..initialPosition = lineStart!; final ball = ControlledBall.debug()..initialPosition = lineStart!;
final impulse = line * -1 * 10; final impulse = line * -1 * 10;
ball.add(BallTurboChargingBehavior(impulse: impulse)); ball.add(BallTurboChargingBehavior(impulse: impulse));
firstChild<ZCanvasComponent>()?.add(ball); firstChild<ZCanvasComponent>()?.add(ball);
} }
} }
// coverage:ignore-end
// coverage:ignore-start // coverage:ignore-start
class _PreviewLine extends PositionComponent with HasGameRef<DebugPinballGame> { class PreviewLine extends PositionComponent with HasGameRef<DebugPinballGame> {
static final _previewLinePaint = Paint() static final _previewLinePaint = Paint()
..color = Colors.pink ..color = Colors.pink
..strokeWidth = 0.4 ..strokeWidth = 0.4
@ -246,10 +244,8 @@ class _PreviewLine extends PositionComponent with HasGameRef<DebugPinballGame> {
} }
} }
} }
// coverage:ignore-end
// TODO(wolfenrain): investigate this CI failure. // TODO(wolfenrain): investigate this CI failure.
// coverage:ignore-start
class _DebugInformation extends Component with HasGameRef<DebugPinballGame> { class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {
@override @override
PositionType get positionType => PositionType.widget; PositionType get positionType => PositionType.widget;

@ -25,6 +25,12 @@ class _MockTapUpDetails extends Mock implements TapUpDetails {}
class _MockTapUpInfo extends Mock implements TapUpInfo {} class _MockTapUpInfo extends Mock implements TapUpInfo {}
class _MockDragStartInfo extends Mock implements DragStartInfo {}
class _MockDragUpdateInfo extends Mock implements DragUpdateInfo {}
class _MockDragEndInfo extends Mock implements DragEndInfo {}
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final assets = [ final assets = [
@ -469,5 +475,68 @@ void main() {
); );
}, },
); );
debugModeFlameTester.test(
'set lineStart on pan start',
(game) async {
final startPosition = Vector2.all(10);
final eventPosition = _MockEventPosition();
when(() => eventPosition.game).thenReturn(startPosition);
final dragStartInfo = _MockDragStartInfo();
when(() => dragStartInfo.eventPosition).thenReturn(eventPosition);
game.onPanStart(dragStartInfo);
await game.ready();
expect(
game.lineStart,
equals(startPosition),
);
},
);
debugModeFlameTester.test(
'set lineEnd on pan update',
(game) async {
final endPosition = Vector2.all(10);
final eventPosition = _MockEventPosition();
when(() => eventPosition.game).thenReturn(endPosition);
final dragUpdateInfo = _MockDragUpdateInfo();
when(() => dragUpdateInfo.eventPosition).thenReturn(eventPosition);
game.onPanUpdate(dragUpdateInfo);
await game.ready();
expect(
game.lineEnd,
equals(endPosition),
);
},
);
debugModeFlameTester.test(
'launch ball on pan end',
(game) async {
final startPosition = Vector2.zero();
final endPosition = Vector2.all(10);
game.lineStart = startPosition;
game.lineEnd = endPosition;
await game.ready();
final previousBalls =
game.descendants().whereType<ControlledBall>().toList();
game.onPanEnd(_MockDragEndInfo());
await game.ready();
expect(
game.descendants().whereType<ControlledBall>().length,
equals(previousBalls.length + 1),
);
},
);
}); });
} }

Loading…
Cancel
Save