test: passed all tests

pull/357/head
alestiago 3 years ago
parent 9ec099ab4e
commit 70145cc35c

@ -77,9 +77,9 @@ void main() {
); );
}); });
flameBlocTester.testGameWidget( flameBlocTester.test(
'can be loaded', 'can be loaded',
setUp: (game, tester) async { (game) async {
await game.pump(parent); await game.pump(parent);
final behavior = ScoringBehavior( final behavior = ScoringBehavior(
@ -95,9 +95,9 @@ void main() {
}, },
); );
flameBlocTester.testGameWidget( flameBlocTester.test(
'emits Scored event with points when added', 'emits Scored event with points when added',
setUp: (game, tester) async { (game) async {
await game.pump(parent, gameBloc: bloc); await game.pump(parent, gameBloc: bloc);
const points = Points.oneMillion; const points = Points.oneMillion;
@ -115,9 +115,9 @@ void main() {
}, },
); );
flameBlocTester.testGameWidget( flameBlocTester.test(
'correctly renders text', 'correctly renders text',
setUp: (game, tester) async { (game) async {
await game.pump(parent); await game.pump(parent);
const points = Points.oneMillion; const points = Points.oneMillion;
@ -144,6 +144,7 @@ void main() {
flameBlocTester.testGameWidget( flameBlocTester.testGameWidget(
'is removed after duration', 'is removed after duration',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad();
await game.pump(parent); await game.pump(parent);
const duration = 2.0; const duration = 2.0;

@ -26,8 +26,7 @@ class _TestGame extends Forge2DGame with HasKeyboardHandlerComponents {
Future<void> pump(Flipper flipper, {GameBloc? gameBloc}) { Future<void> pump(Flipper flipper, {GameBloc? gameBloc}) {
return ensureAdd( return ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value( FlameBlocProvider<GameBloc, GameState>.value(
value: gameBloc ?? GameBloc() value: gameBloc ?? (GameBloc()..add(const GameStarted())),
..add(const GameStarted()),
children: [flipper], children: [flipper],
), ),
); );

@ -14,6 +14,7 @@ import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_audio/pinball_audio.dart'; import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -24,12 +25,21 @@ class _TestGame extends Forge2DGame with HasKeyboardHandlerComponents {
await images.load(Assets.images.plunger.plunger.keyName); await images.load(Assets.images.plunger.plunger.keyName);
} }
Future<void> pump(Plunger child, {GameBloc? gameBloc}) { Future<void> pump(
Plunger child, {
GameBloc? gameBloc,
PinballPlayer? pinballPlayer,
}) {
return ensureAdd( return ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value( FlameBlocProvider<GameBloc, GameState>.value(
value: gameBloc ?? GameBloc() value: gameBloc ?? GameBloc()
..add(const GameStarted()), ..add(const GameStarted()),
children: [
FlameProvider<PinballPlayer>.value(
pinballPlayer ?? _MockPinballPlayer(),
children: [child], children: [child],
)
],
), ),
); );
} }
@ -149,20 +159,21 @@ void main() {
group('PlungerNoisyBehavior', () { group('PlungerNoisyBehavior', () {
late PinballPlayer player; late PinballPlayer player;
late PlungerNoisyBehavior behavior;
setUp(() { setUp(() {
player = _MockPinballPlayer(); player = _MockPinballPlayer();
behavior = PlungerNoisyBehavior();
}); });
test('plays the correct sound on load', () async { flameTester.test('plays the correct sound on load', (game) async {
await behavior.onLoad(); final parent = ControlledPlunger(compressionDistance: 10);
await game.pump(parent, pinballPlayer: player);
await parent.ensureAdd(PlungerNoisyBehavior());
verify(() => player.play(PinballAudio.launcher)).called(1); verify(() => player.play(PinballAudio.launcher)).called(1);
}); });
test('is removed on the first update', () { test('is removed on the first update', () {
final parent = Component(); final parent = Component();
final behavior = PlungerNoisyBehavior();
parent.add(behavior); parent.add(behavior);
parent.update(0); // Run a tick to ensure it is added parent.update(0); // Run a tick to ensure it is added

@ -65,6 +65,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds GameBonus.googleWord to the game when all letters are activated', 'adds GameBonus.googleWord to the game when all letters are activated',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad();
final behavior = GoogleWordBonusBehavior(); final behavior = GoogleWordBonusBehavior();
final parent = GoogleWord.test(); final parent = GoogleWord.test();
final letters = [ final letters = [

@ -42,9 +42,9 @@ void main() {
}, },
); );
flameBlocTester.testGameWidget( flameBlocTester.test(
'loads four Multiball', 'loads four Multiball',
setUp: (game, tester) async { (game) async {
final multiballs = Multiballs(); final multiballs = Multiballs();
await game.pump(multiballs); await game.pump(multiballs);
expect( expect(

@ -32,8 +32,7 @@ class _TestPinballGame extends PinballGame {
images.prefix = ''; images.prefix = '';
final futures = preLoadAssets(); final futures = preLoadAssets();
await Future.wait<void>(futures); await Future.wait<void>(futures);
await super.onLoad();
return super.onLoad();
} }
} }
@ -52,8 +51,7 @@ class _DebugPinballGame extends DebugPinballGame {
images.prefix = ''; images.prefix = '';
final futures = preLoadAssets(); final futures = preLoadAssets();
await Future.wait<void>(futures); await Future.wait<void>(futures);
await super.onLoad();
return super.onLoad();
} }
} }
@ -159,7 +157,6 @@ void main() {
'has only one Multiballs', 'has only one Multiballs',
(game) async { (game) async {
await game.ready(); await game.ready();
expect( expect(
game.descendants().whereType<Multiballs>().length, game.descendants().whereType<Multiballs>().length,
equals(1), equals(1),
@ -189,7 +186,10 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'paints sprites with FilterQuality.medium', 'paints sprites with FilterQuality.medium',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad(); game.images.prefix = '';
final futures = game.preLoadAssets();
await Future.wait<void>(futures);
await game.ready(); await game.ready();
final descendants = game.descendants(); final descendants = game.descendants();

Loading…
Cancel
Save