feat: pr suggestions

pull/22/head
Erick Zanardo 4 years ago
parent f9f109ba5a
commit 38b8a28ffc

@ -26,11 +26,12 @@ class GameHud extends StatelessWidget {
'${state.score}', '${state.score}',
style: Theme.of(context).textTheme.headline3, style: Theme.of(context).textTheme.headline3,
), ),
Column( Wrap(
direction: Axis.vertical,
children: [ children: [
for (var i = 0; i < state.balls; i++) for (var i = 0; i < state.balls; i++)
const Padding( const Padding(
padding: EdgeInsets.only(top: 6), padding: EdgeInsets.only(top: 6, right: 6),
child: CircleAvatar( child: CircleAvatar(
radius: 8, radius: 8,
backgroundColor: Colors.black, backgroundColor: Colors.black,

@ -8,25 +8,72 @@ import '../../helpers/helpers.dart';
void main() { void main() {
group('GameHud', () { group('GameHud', () {
late GameBloc gameBloc;
const initialState = GameState(score: 10, balls: 2);
void _mockState(GameState state) {
whenListen(
gameBloc,
Stream.value(state),
initialState: state,
);
}
Future<void> _pumpHud(WidgetTester tester) async {
await tester.pumpApp(
GameHud(),
gameBloc: gameBloc,
);
}
setUp(() {
gameBloc = MockGameBloc();
_mockState(initialState);
});
testWidgets( testWidgets(
'renders the current score and balls', 'renders the current score',
(tester) async { (tester) async {
final state = GameState(score: 10, balls: 2); await _pumpHud(tester);
final gameBloc = MockGameBloc(); expect(find.text(initialState.score.toString()), findsOneWidget);
whenListen( },
gameBloc, );
Stream.value(state),
initialState: state,
);
await tester.pumpApp( testWidgets(
GameHud(), 'renders the current ball number',
gameBloc: gameBloc, (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),
);
});
}); });
} }

Loading…
Cancel
Save