diff --git a/lib/game/view/game_hud.dart b/lib/game/view/game_hud.dart index beff3391..7bf1e8c3 100644 --- a/lib/game/view/game_hud.dart +++ b/lib/game/view/game_hud.dart @@ -26,11 +26,12 @@ class GameHud extends StatelessWidget { '${state.score}', style: Theme.of(context).textTheme.headline3, ), - Column( + Wrap( + direction: Axis.vertical, children: [ for (var i = 0; i < state.balls; i++) const Padding( - padding: EdgeInsets.only(top: 6), + padding: EdgeInsets.only(top: 6, right: 6), child: CircleAvatar( radius: 8, backgroundColor: Colors.black, diff --git a/test/game/view/game_hud_test.dart b/test/game/view/game_hud_test.dart index 40079a2f..27a423ed 100644 --- a/test/game/view/game_hud_test.dart +++ b/test/game/view/game_hud_test.dart @@ -8,25 +8,72 @@ import '../../helpers/helpers.dart'; void main() { group('GameHud', () { + late GameBloc gameBloc; + const initialState = GameState(score: 10, balls: 2); + + void _mockState(GameState state) { + whenListen( + gameBloc, + Stream.value(state), + initialState: state, + ); + } + + Future _pumpHud(WidgetTester tester) async { + await tester.pumpApp( + GameHud(), + gameBloc: gameBloc, + ); + } + + setUp(() { + gameBloc = MockGameBloc(); + _mockState(initialState); + }); + testWidgets( - 'renders the current score and balls', + 'renders the current score', (tester) async { - final state = GameState(score: 10, balls: 2); - final gameBloc = MockGameBloc(); - whenListen( - gameBloc, - Stream.value(state), - initialState: state, - ); + await _pumpHud(tester); + expect(find.text(initialState.score.toString()), findsOneWidget); + }, + ); - await tester.pumpApp( - GameHud(), - gameBloc: gameBloc, + testWidgets( + 'renders the current ball number', + (tester) async { + await _pumpHud(tester); + expect( + find.byType(CircleAvatar), + findsNWidgets(initialState.balls), ); - - expect(find.text('10'), findsOneWidget); - expect(find.byType(CircleAvatar), findsNWidgets(2)); }, ); + + testWidgets('updates the score', (tester) async { + await _pumpHud(tester); + expect(find.text(initialState.score.toString()), findsOneWidget); + + _mockState(initialState.copyWith(score: 20)); + + await tester.pump(); + expect(find.text('20'), findsOneWidget); + }); + + testWidgets('updates the ball number', (tester) async { + await _pumpHud(tester); + expect( + find.byType(CircleAvatar), + findsNWidgets(initialState.balls), + ); + + _mockState(initialState.copyWith(balls: 1)); + + await tester.pump(); + expect( + find.byType(CircleAvatar), + findsNWidgets(1), + ); + }); }); }