diff --git a/test/game/components/ball_test.dart b/test/game/components/ball_test.dart index 38419320..30f294fc 100644 --- a/test/game/components/ball_test.dart +++ b/test/game/components/ball_test.dart @@ -13,19 +13,9 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('Ball', () { - final gameBloc = MockGameBloc(); + final flameTester = FlameTester(PinballGame.initial); - setUp(() { - whenListen( - gameBloc, - const Stream.empty(), - initialState: const GameState.initial(), - ); - }); - - final tester = flameBlocTester(gameBloc: gameBloc); - - tester.test( + flameTester.test( 'loads correctly', (game) async { final ball = Ball(position: Vector2.zero()); @@ -36,7 +26,7 @@ void main() { ); group('body', () { - tester.test( + flameTester.test( 'positions correctly', (game) async { final position = Vector2.all(10); @@ -48,7 +38,7 @@ void main() { }, ); - tester.test( + flameTester.test( 'is dynamic', (game) async { final ball = Ball(position: Vector2.zero()); @@ -60,7 +50,7 @@ void main() { }); group('first fixture', () { - tester.test( + flameTester.test( 'exists', (game) async { final ball = Ball(position: Vector2.zero()); @@ -70,7 +60,7 @@ void main() { }, ); - tester.test( + flameTester.test( 'is dense', (game) async { final ball = Ball(position: Vector2.zero()); @@ -81,7 +71,7 @@ void main() { }, ); - tester.test( + flameTester.test( 'shape is circular', (game) async { final ball = Ball(position: Vector2.zero()); @@ -95,6 +85,18 @@ void main() { }); group('resetting a ball', () { + final gameBloc = MockGameBloc(); + + setUp(() { + whenListen( + gameBloc, + const Stream.empty(), + initialState: const GameState.initial(), + ); + }); + + final tester = flameBlocTester(gameBloc: gameBloc); + tester.widgetTest( 'adds BallLost to GameBloc', (game, tester) async { diff --git a/test/game/components/plunger_test.dart b/test/game/components/plunger_test.dart index f87f5adc..ae6b1c05 100644 --- a/test/game/components/plunger_test.dart +++ b/test/game/components/plunger_test.dart @@ -132,13 +132,13 @@ void main() { final gameBloc = MockGameBloc(); setUp(() { - plunger = Plunger(position: Vector2.zero()); - anchor = Anchor(position: Vector2(0, -1)); whenListen( gameBloc, const Stream.empty(), initialState: const GameState.initial(), ); + plunger = Plunger(position: Vector2.zero()); + anchor = Anchor(position: Vector2(0, -1)); }); final flameTester = flameBlocTester(gameBloc: gameBloc); diff --git a/test/game/view/pinball_game_page_test.dart b/test/game/view/pinball_game_page_test.dart index d02bfa2b..c1f1062f 100644 --- a/test/game/view/pinball_game_page_test.dart +++ b/test/game/view/pinball_game_page_test.dart @@ -3,7 +3,6 @@ import 'package:flame/game.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/game/game.dart'; -import 'package:pinball/theme/theme.dart'; import 'package:pinball_theme/pinball_theme.dart'; import '../../helpers/helpers.dart'; @@ -28,13 +27,6 @@ void main() { }); testWidgets('route returns a valid navigation route', (tester) async { - final themeCubit = MockThemeCubit(); - whenListen( - themeCubit, - const Stream.empty(), - initialState: const ThemeState.initial(), - ); - await tester.pumpApp( Scaffold( body: Builder( @@ -49,7 +41,6 @@ void main() { }, ), ), - themeCubit: themeCubit, ); await tester.tap(find.text('Tap me')); @@ -86,24 +77,16 @@ void main() { 'renders a game over dialog when the user has lost', (tester) async { final gameBloc = MockGameBloc(); - const gameState = GameState(score: 0, balls: 0); + const state = GameState(score: 0, balls: 0); whenListen( gameBloc, - Stream.value(gameState), - initialState: gameState, - ); - - final themeCubit = MockThemeCubit(); - whenListen( - themeCubit, - const Stream.empty(), - initialState: const ThemeState.initial(), + Stream.value(state), + initialState: state, ); await tester.pumpApp( const PinballGameView(theme: theme), gameBloc: gameBloc, - themeCubit: themeCubit, ); await tester.pump();