test: coverage

pull/416/head
RuiAlonso 3 years ago
parent 72ce22ef9a
commit b7011ea01b

@ -2,13 +2,14 @@ import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:pinball/game/behaviors/behaviors.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template ramp_bonus_behavior}
/// Increases the score when a [Ball] is shot 10 times into the [SpaceshipRamp].
/// {@endtemplate}
class RampBonusBehavior extends Component
with
HasGameRef,
ParentIsA<Component>,
FlameBlocListenable<SpaceshipRampCubit, SpaceshipRampState> {
/// {@macro ramp_bonus_behavior}
RampBonusBehavior({
@ -31,7 +32,7 @@ class RampBonusBehavior extends Component
@override
void onNewState(SpaceshipRampState state) {
gameRef.add(
parent.add(
ScoringBehavior(
points: _points,
position: Vector2(0, -60),

@ -2,13 +2,14 @@ import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:pinball/game/behaviors/behaviors.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template ramp_shot_behavior}
/// Increases the score when a [Ball] is shot into the [SpaceshipRamp].
/// {@endtemplate}
class RampShotBehavior extends Component
with
HasGameRef,
ParentIsA<Component>,
FlameBlocListenable<SpaceshipRampCubit, SpaceshipRampState> {
/// {@macro ramp_shot_behavior}
RampShotBehavior({
@ -28,7 +29,7 @@ class RampShotBehavior extends Component
@override
void onNewState(SpaceshipRampState state) {
gameRef.add(
parent.add(
ScoringBehavior(
points: _points,
position: Vector2(0, -45),

@ -3,6 +3,7 @@
import 'dart:async';
import 'package:bloc_test/bloc_test.dart';
import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart';
@ -36,14 +37,20 @@ class _TestGame extends Forge2DGame {
}
Future<void> pump(
SpaceshipRamp child, {
List<Component> children, {
required SpaceshipRampCubit bloc,
required GameBloc gameBloc,
}) async {
await ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value(
value: gameBloc,
children: [
ZCanvasComponent(children: [child]),
FlameBlocProvider<SpaceshipRampCubit, SpaceshipRampState>.value(
value: bloc,
children: [
ZCanvasComponent(children: children),
],
),
],
),
);
@ -57,14 +64,14 @@ class _MockSpaceshipRampCubit extends Mock implements SpaceshipRampCubit {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('RampBonusBehavior', () {
const shotPoints = Points.oneMillion;
late GameBloc gameBloc;
late GameBloc gameBloc;
setUp(() {
gameBloc = _MockGameBloc();
});
setUp(() {
gameBloc = _MockGameBloc();
});
group('RampBonusBehavior', () {
const shotPoints = Points.oneMillion;
final flameTester = FlameTester(_TestGame.new);
@ -79,14 +86,12 @@ void main() {
streamController.stream,
initialState: state,
);
final behavior = RampBonusBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(
bloc: bloc,
children: [behavior],
);
final behavior = RampBonusBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(bloc: bloc, children: [behavior]);
await game.pump(
parent,
[parent],
bloc: bloc,
gameBloc: gameBloc,
);
@ -110,14 +115,12 @@ void main() {
streamController.stream,
initialState: state,
);
final behavior = RampBonusBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(
bloc: bloc,
children: [behavior],
);
final behavior = RampBonusBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(bloc: bloc, children: [behavior]);
await game.pump(
parent,
[parent],
bloc: bloc,
gameBloc: gameBloc,
);

@ -3,6 +3,7 @@
import 'dart:async';
import 'package:bloc_test/bloc_test.dart';
import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart';
@ -36,14 +37,20 @@ class _TestGame extends Forge2DGame {
}
Future<void> pump(
SpaceshipRamp child, {
List<Component> children, {
required SpaceshipRampCubit bloc,
required GameBloc gameBloc,
}) async {
await ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value(
value: gameBloc,
children: [
ZCanvasComponent(children: [child]),
FlameBlocProvider<SpaceshipRampCubit, SpaceshipRampState>.value(
value: bloc,
children: [
ZCanvasComponent(children: children),
],
),
],
),
);
@ -57,14 +64,14 @@ class _MockSpaceshipRampCubit extends Mock implements SpaceshipRampCubit {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('RampShotBehavior', () {
const shotPoints = Points.fiveThousand;
late GameBloc gameBloc;
late GameBloc gameBloc;
setUp(() {
gameBloc = _MockGameBloc();
});
setUp(() {
gameBloc = _MockGameBloc();
});
group('RampShotBehavior', () {
const shotPoints = Points.fiveThousand;
final flameTester = FlameTester(_TestGame.new);
@ -79,14 +86,12 @@ void main() {
streamController.stream,
initialState: state,
);
final behavior = RampShotBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(
bloc: bloc,
children: [behavior],
);
final behavior = RampShotBehavior(points: shotPoints);
final parent = SpaceshipRamp.test(bloc: bloc, children: [behavior]);
await game.pump(
parent,
[parent],
bloc: bloc,
gameBloc: gameBloc,
);

Loading…
Cancel
Save