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

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

@ -86,12 +86,12 @@ void main() {
group('controller', () {
group('listenWhen', () {
final gameBloc = MockGameBloc();
final tester = flameBlocTester(
game: TestGame.new,
gameBloc: () => gameBloc,
final flameBlocTester = FlameBlocTester<TestGame, GameBloc>(
gameBuilder: TestGame.new,
blocBuilder: () => gameBloc,
);
tester.testGameWidget(
flameBlocTester.testGameWidget(
'listens when a Bonus.dashNest is added',
verify: (game, tester) async {
final flutterForest = FlutterForest();
@ -145,12 +145,12 @@ void main() {
);
});
final tester = flameBlocTester<PinballGame>(
game: PinballGameTest.create,
gameBloc: () => gameBloc,
final flameBlocTester = FlameBlocTester<PinballGame, GameBloc>(
gameBuilder: PinballGameTest.create,
blocBuilder: () => gameBloc,
);
tester.testGameWidget(
flameBlocTester.testGameWidget(
'add DashNestActivated event',
setUp: (game, tester) async {
await game.ready();
@ -171,7 +171,7 @@ void main() {
},
);
tester.testGameWidget(
flameBlocTester.testGameWidget(
'add Scored event',
setUp: (game, tester) async {
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:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
FlameTester<T> flameBlocTester<T extends Forge2DGame>({
required T Function() game,
required GameBloc Function() gameBloc,
}) {
return FlameTester<T>(
game,
pumpWidget: (gameWidget, tester) async {
await tester.pumpWidget(
BlocProvider.value(
value: gameBloc(),
child: gameWidget,
),
);
},
);
class FlameBlocTester<T extends FlameGame, B extends Bloc<dynamic, dynamic>>
extends FlameTester<T> {
FlameBlocTester({
required GameCreateFunction<T> gameBuilder,
required B Function() blocBuilder,
}) : super(
gameBuilder,
pumpWidget: (gameWidget, tester) async {
await tester.pumpWidget(
BlocProvider.value(
value: blocBuilder(),
child: gameWidget,
),
);
},
);
}

Loading…
Cancel
Save