|
|
@ -5,7 +5,6 @@ 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/components.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:pinball/game/components/android_acres/behaviors/behaviors.dart';
|
|
|
|
import 'package:pinball/game/components/android_acres/behaviors/behaviors.dart';
|
|
|
@ -14,6 +13,10 @@ import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../../helpers/helpers.dart';
|
|
|
|
import '../../../../helpers/helpers.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockGameBloc extends Mock implements GameBloc {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockSpaceshipRampCubit extends Mock implements SpaceshipRampCubit {}
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final assets = [
|
|
|
|
final assets = [
|
|
|
@ -29,16 +32,16 @@ void main() {
|
|
|
|
Assets.images.android.ramp.arrow.active5.keyName,
|
|
|
|
Assets.images.android.ramp.arrow.active5.keyName,
|
|
|
|
Assets.images.android.rail.main.keyName,
|
|
|
|
Assets.images.android.rail.main.keyName,
|
|
|
|
Assets.images.android.rail.exit.keyName,
|
|
|
|
Assets.images.android.rail.exit.keyName,
|
|
|
|
Assets.images.score.oneMillion.keyName,
|
|
|
|
Assets.images.score.fiveThousand.keyName,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
group('RampBonusBehavior', () {
|
|
|
|
group('RampBonusBehavior', () {
|
|
|
|
const bonusPoints = Points.oneMillion;
|
|
|
|
const shotPoints = Points.oneMillion;
|
|
|
|
|
|
|
|
|
|
|
|
late GameBloc gameBloc;
|
|
|
|
late GameBloc gameBloc;
|
|
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
setUp(() {
|
|
|
|
gameBloc = MockGameBloc();
|
|
|
|
gameBloc = _MockGameBloc();
|
|
|
|
whenListen(
|
|
|
|
whenListen(
|
|
|
|
gameBloc,
|
|
|
|
gameBloc,
|
|
|
|
const Stream<GameState>.empty(),
|
|
|
|
const Stream<GameState>.empty(),
|
|
|
@ -53,145 +56,65 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
"hit on door sensor doesn't add any score",
|
|
|
|
"when withoutBonus doesn't add any score or show any score points",
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
final ball = Ball(baseColor: Colors.red);
|
|
|
|
final bloc = _MockSpaceshipRampCubit();
|
|
|
|
final behavior = RampBonusBehavior(
|
|
|
|
whenListen(
|
|
|
|
points: bonusPoints,
|
|
|
|
bloc,
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
const Stream<SpaceshipRampState>.empty(),
|
|
|
|
);
|
|
|
|
initialState: SpaceshipRampState.initial(),
|
|
|
|
final parent = SpaceshipRamp.test();
|
|
|
|
|
|
|
|
final sensors = [
|
|
|
|
|
|
|
|
RampSensor.test(
|
|
|
|
|
|
|
|
type: RampSensorType.door,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await parent.addAll(sensors);
|
|
|
|
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (final sensor in sensors) {
|
|
|
|
|
|
|
|
sensor.bloc.onDoor(ball);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verifyNever(() => gameBloc.add(Scored(points: bonusPoints.value)));
|
|
|
|
|
|
|
|
expect(scores.length, 0);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
final behavior = RampShotBehavior(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
points: shotPoints,
|
|
|
|
'hit on inside sensor without previous hit on door sensor '
|
|
|
|
|
|
|
|
"doesn't add any score",
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final ball = Ball(baseColor: Colors.red);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final behavior = RampBonusBehavior(
|
|
|
|
|
|
|
|
points: bonusPoints,
|
|
|
|
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final parent = SpaceshipRamp.test();
|
|
|
|
final parent = SpaceshipRamp.test(
|
|
|
|
final doorSensor = RampSensor.test(
|
|
|
|
bloc: bloc,
|
|
|
|
type: RampSensorType.door,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final insideSensor = RampSensor.test(
|
|
|
|
|
|
|
|
type: RampSensorType.inside,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await parent.addAll([doorSensor, insideSensor]);
|
|
|
|
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
insideSensor.bloc.onInside(ball);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
verifyNever(() => gameBloc.add(Scored(points: bonusPoints.value)));
|
|
|
|
verifyNever(() => gameBloc.add(Scored(points: shotPoints.value)));
|
|
|
|
expect(scores.length, 0);
|
|
|
|
expect(scores.length, 0);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
'hit on inside sensor after hit on door sensor '
|
|
|
|
'when withBonus add score and show score points',
|
|
|
|
"less than 10 times doesn't add any score neither shows score points",
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
final ball = Ball(baseColor: Colors.red);
|
|
|
|
final bloc = _MockSpaceshipRampCubit();
|
|
|
|
final behavior = RampBonusBehavior(
|
|
|
|
whenListen(
|
|
|
|
points: bonusPoints,
|
|
|
|
bloc,
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
const Stream<SpaceshipRampState>.empty(),
|
|
|
|
);
|
|
|
|
initialState: SpaceshipRampState.initial().copyWith(
|
|
|
|
final parent = SpaceshipRamp.test();
|
|
|
|
status: SpaceshipRampStatus.withBonus,
|
|
|
|
final doorSensor = RampSensor.test(
|
|
|
|
),
|
|
|
|
type: RampSensorType.door,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final insideSensor = RampSensor.test(
|
|
|
|
|
|
|
|
type: RampSensorType.inside,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await parent.addAll([doorSensor, insideSensor]);
|
|
|
|
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doorSensor.bloc.onDoor(ball);
|
|
|
|
|
|
|
|
insideSensor.bloc.onInside(ball);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verifyNever(() => gameBloc.add(Scored(points: bonusPoints.value)));
|
|
|
|
|
|
|
|
expect(scores.length, 0);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
final behavior = RampShotBehavior(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
points: shotPoints,
|
|
|
|
'hit on inside sensor after hit on door sensor '
|
|
|
|
|
|
|
|
'10 times add score and show score point',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final ball = Ball(baseColor: Colors.red);
|
|
|
|
|
|
|
|
final behavior = RampBonusBehavior(
|
|
|
|
|
|
|
|
points: bonusPoints,
|
|
|
|
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
scorePosition: Vector2.zero(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final parent = SpaceshipRamp.test();
|
|
|
|
final parent = SpaceshipRamp.test(
|
|
|
|
final doorSensor = RampSensor.test(
|
|
|
|
bloc: bloc,
|
|
|
|
type: RampSensorType.door,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final insideSensor = RampSensor.test(
|
|
|
|
|
|
|
|
type: RampSensorType.inside,
|
|
|
|
|
|
|
|
bloc: RampSensorCubit(),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await parent.addAll([doorSensor, insideSensor]);
|
|
|
|
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
await game.ensureAdd(parent);
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
|
|
|
doorSensor.bloc.onDoor(ball);
|
|
|
|
|
|
|
|
insideSensor.bloc.onInside(ball);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
final scores = game.descendants().whereType<ScoreComponent>();
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
verify(() => gameBloc.add(Scored(points: bonusPoints.value))).called(1);
|
|
|
|
verifyNever(() => gameBloc.add(MultiplierIncreased()));
|
|
|
|
expect(scores.length, 1);
|
|
|
|
verifyNever(() => gameBloc.add(Scored(points: shotPoints.value)));
|
|
|
|
|
|
|
|
expect(scores.length, 0);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|