refactor: implemented FlameBlocTester (#122)

* refactor: implemented FlameBlocTester

* refactor: renamed parameter bloc to blocBuilder
pull/127/head
Alejandro Santiago 2 years ago committed by GitHub
parent cbbf7b121e
commit 40d0fd0995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -196,10 +196,10 @@ void main() {
group('bonus letter activation', () { group('bonus letter activation', () {
late GameBloc gameBloc; late GameBloc gameBloc;
final tester = flameBlocTester<PinballGame>( final flameBlocTester = FlameBlocTester<PinballGame, GameBloc>(
// TODO(alestiago): Use TestGame once BonusLetter has controller. // TODO(alestiago): Use TestGame once BonusLetter has controller.
game: PinballGameTest.create, gameBuilder: PinballGameTest.create,
gameBloc: () => gameBloc, blocBuilder: () => gameBloc,
); );
setUp(() { setUp(() {
@ -211,7 +211,7 @@ void main() {
); );
}); });
tester.testGameWidget( flameBlocTester.testGameWidget(
'adds BonusLetterActivated to GameBloc when not activated', 'adds BonusLetterActivated to GameBloc when not activated',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.ready(); await game.ready();
@ -225,7 +225,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
"doesn't add BonusLetterActivated to GameBloc when already activated", "doesn't add BonusLetterActivated to GameBloc when already activated",
setUp: (game, tester) async { setUp: (game, tester) async {
const state = GameState( const state = GameState(
@ -253,7 +253,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'adds a ColorEffect', 'adds a ColorEffect',
setUp: (game, tester) async { setUp: (game, tester) async {
const state = GameState( const state = GameState(
@ -284,7 +284,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'only listens when there is a change on the letter status', 'only listens when there is a change on the letter status',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.ready(); await game.ready();

@ -66,12 +66,12 @@ void main() {
); );
}); });
final tester = flameBlocTester<PinballGame>( final flameBlocTester = FlameBlocTester<PinballGame, GameBloc>(
game: PinballGameTest.create, gameBuilder: PinballGameTest.create,
gameBloc: () => gameBloc, blocBuilder: () => gameBloc,
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'lost adds BallLost to GameBloc', 'lost adds BallLost to GameBloc',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);
@ -86,7 +86,7 @@ void main() {
); );
group('listenWhen', () { group('listenWhen', () {
tester.testGameWidget( flameBlocTester.testGameWidget(
'listens when a ball has been lost', 'listens when a ball has been lost',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);
@ -107,7 +107,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'does not listen when a ball has not been lost', 'does not listen when a ball has not been lost',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);
@ -130,7 +130,7 @@ void main() {
}); });
group('onNewState', () { group('onNewState', () {
tester.testGameWidget( flameBlocTester.testGameWidget(
'removes ball', 'removes ball',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);
@ -147,7 +147,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'spawns a new ball when the ball is not the last one', 'spawns a new ball when the ball is not the last one',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);
@ -168,7 +168,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'does not spawn a new ball is the last one', 'does not spawn a new ball is the last one',
setUp: (game, tester) async { setUp: (game, tester) async {
final controller = LaunchedBallController(ball); final controller = LaunchedBallController(ball);

@ -86,12 +86,12 @@ void main() {
group('controller', () { group('controller', () {
group('listenWhen', () { group('listenWhen', () {
final gameBloc = MockGameBloc(); final gameBloc = MockGameBloc();
final tester = flameBlocTester( final flameBlocTester = FlameBlocTester<TestGame, GameBloc>(
game: TestGame.new, gameBuilder: TestGame.new,
gameBloc: () => gameBloc, blocBuilder: () => gameBloc,
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'listens when a Bonus.dashNest is added', 'listens when a Bonus.dashNest is added',
verify: (game, tester) async { verify: (game, tester) async {
final flutterForest = FlutterForest(); final flutterForest = FlutterForest();
@ -145,12 +145,12 @@ void main() {
); );
}); });
final tester = flameBlocTester<PinballGame>( final flameBlocTester = FlameBlocTester<PinballGame, GameBloc>(
game: PinballGameTest.create, gameBuilder: PinballGameTest.create,
gameBloc: () => gameBloc, blocBuilder: () => gameBloc,
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'add DashNestActivated event', 'add DashNestActivated event',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.ready(); await game.ready();
@ -171,7 +171,7 @@ void main() {
}, },
); );
tester.testGameWidget( flameBlocTester.testGameWidget(
'add Scored event', 'add Scored event',
setUp: (game, tester) async { setUp: (game, tester) async {
final flutterForest = FlutterForest(); final flutterForest = FlutterForest();

@ -1,21 +1,21 @@
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame/src/game/flame_game.dart';
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
FlameTester<T> flameBlocTester<T extends Forge2DGame>({ class FlameBlocTester<T extends FlameGame, B extends Bloc<dynamic, dynamic>>
required T Function() game, extends FlameTester<T> {
required GameBloc Function() gameBloc, FlameBlocTester({
}) { required GameCreateFunction<T> gameBuilder,
return FlameTester<T>( required B Function() blocBuilder,
game, }) : super(
pumpWidget: (gameWidget, tester) async { gameBuilder,
await tester.pumpWidget( pumpWidget: (gameWidget, tester) async {
BlocProvider.value( await tester.pumpWidget(
value: gameBloc(), BlocProvider.value(
child: gameWidget, value: blocBuilder(),
), child: gameWidget,
); ),
}, );
); },
);
} }

Loading…
Cancel
Save