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

@ -25,6 +25,12 @@ class _MockTapUpDetails extends Mock implements TapUpDetails {}
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() {
TestWidgetsFlutterBinding.ensureInitialized();
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