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

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

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

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

Loading…
Cancel
Save