From 61938057b49bb509eda9a6443ad61e8bc38e9ca5 Mon Sep 17 00:00:00 2001 From: arturplaczek Date: Wed, 13 Apr 2022 17:49:45 +0200 Subject: [PATCH] fix: apply code review --- lib/start_game/bloc/start_game_bloc.dart | 18 +++++------ lib/start_game/bloc/start_game_event.dart | 30 +++++++++---------- lib/start_game/bloc/start_game_state.dart | 4 +-- lib/start_game/start_game.dart | 1 + .../start_game/bloc/start_game_bloc_test.dart | 14 ++++----- .../bloc/start_game_event_test.dart | 18 +++++------ .../bloc/start_game_state_test.dart | 6 ++-- 7 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 lib/start_game/start_game.dart diff --git a/lib/start_game/bloc/start_game_bloc.dart b/lib/start_game/bloc/start_game_bloc.dart index d0d98913..254d2927 100644 --- a/lib/start_game/bloc/start_game_bloc.dart +++ b/lib/start_game/bloc/start_game_bloc.dart @@ -14,28 +14,28 @@ class StartGameBloc extends Bloc { required PinballGame game, }) : _game = game, super(const StartGameState.initial()) { - on(_onStartGame); - on(_onHowToPlay); - on(_onPlay); + on(_onStartGame); + on(_onCharacterSelected); + on(_onHowToPlayFinished); } final PinballGame _game; void _onStartGame( - StartGame event, + PlayTapped event, Emitter emit, ) { _game.gameFlowController.start(); emit( state.copyWith( - status: StartGameStatus.startGame, + status: StartGameStatus.selectCharacter, ), ); } - void _onHowToPlay( - HowToPlay event, + void _onCharacterSelected( + CharacterSelected event, Emitter emit, ) { emit( @@ -45,8 +45,8 @@ class StartGameBloc extends Bloc { ); } - void _onPlay( - Play event, + void _onHowToPlayFinished( + HowToPlayFinished event, Emitter emit, ) { emit( diff --git a/lib/start_game/bloc/start_game_event.dart b/lib/start_game/bloc/start_game_event.dart index ce5f8b02..ce164e97 100644 --- a/lib/start_game/bloc/start_game_event.dart +++ b/lib/start_game/bloc/start_game_event.dart @@ -8,34 +8,34 @@ abstract class StartGameEvent extends Equatable { const StartGameEvent(); } -/// {@template select_character} -/// Select character event. +/// {@template play_tapped} +/// Play tapped event. /// {@endtemplate} -class StartGame extends StartGameEvent { - /// {@macro select_character} - const StartGame(); +class PlayTapped extends StartGameEvent { + /// {@macro play_tapped} + const PlayTapped(); @override List get props => []; } -/// {@template how_to_play} -/// How to play event. +/// {@template character_selected} +/// Character selected event. /// {@endtemplate} -class HowToPlay extends StartGameEvent { - /// {@macro how_to_play} - const HowToPlay(); +class CharacterSelected extends StartGameEvent { + /// {@macro character_selected} + const CharacterSelected(); @override List get props => []; } -/// {@template play} -/// Play event. +/// {@template how_to_play_finished} +/// How to play finished event. /// {@endtemplate} -class Play extends StartGameEvent { - /// {@macro play} - const Play(); +class HowToPlayFinished extends StartGameEvent { + /// {@macro how_to_play_finished} + const HowToPlayFinished(); @override List get props => []; diff --git a/lib/start_game/bloc/start_game_state.dart b/lib/start_game/bloc/start_game_state.dart index 34fbd3c5..ad7c7cbe 100644 --- a/lib/start_game/bloc/start_game_state.dart +++ b/lib/start_game/bloc/start_game_state.dart @@ -2,11 +2,11 @@ part of 'start_game_bloc.dart'; /// Defines status of start game flow. enum StartGameStatus { - /// Starting status. + /// Initial status. initial, /// Selection characters status. - startGame, + selectCharacter, /// How to play status. howToPlay, diff --git a/lib/start_game/start_game.dart b/lib/start_game/start_game.dart new file mode 100644 index 00000000..7171c66d --- /dev/null +++ b/lib/start_game/start_game.dart @@ -0,0 +1 @@ +export 'bloc/start_game_bloc.dart'; diff --git a/test/start_game/bloc/start_game_bloc_test.dart b/test/start_game/bloc/start_game_bloc_test.dart index 250955bf..ec1b3ced 100644 --- a/test/start_game/bloc/start_game_bloc_test.dart +++ b/test/start_game/bloc/start_game_bloc_test.dart @@ -21,24 +21,24 @@ void main() { group('StartGameBloc', () { blocTest( - 'on StartGame changes status to StartGame', + 'on PlayTapped changes status to selectCharacter', build: () => StartGameBloc( game: pinballGame, ), - act: (bloc) => bloc.add(const StartGame()), + act: (bloc) => bloc.add(const PlayTapped()), expect: () => [ const StartGameState( - status: StartGameStatus.startGame, + status: StartGameStatus.selectCharacter, ) ], ); blocTest( - 'on HowToPlay changes status to howToPlay', + 'on CharacterSelected changes status to howToPlay', build: () => StartGameBloc( game: pinballGame, ), - act: (bloc) => bloc.add(const HowToPlay()), + act: (bloc) => bloc.add(const CharacterSelected()), expect: () => [ const StartGameState( status: StartGameStatus.howToPlay, @@ -47,11 +47,11 @@ void main() { ); blocTest( - 'on Play changes status to play', + 'on HowToPlayFinished changes status to play', build: () => StartGameBloc( game: pinballGame, ), - act: (bloc) => bloc.add(const Play()), + act: (bloc) => bloc.add(const HowToPlayFinished()), expect: () => [ const StartGameState( status: StartGameStatus.play, diff --git a/test/start_game/bloc/start_game_event_test.dart b/test/start_game/bloc/start_game_event_test.dart index 7a80783f..cf481d9f 100644 --- a/test/start_game/bloc/start_game_event_test.dart +++ b/test/start_game/bloc/start_game_event_test.dart @@ -5,24 +5,24 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart'; void main() { group('StartGameEvent', () { - test('StartGame supports value equality', () { + test('PlayTapped supports value equality', () { expect( - StartGame(), - equals(StartGame()), + PlayTapped(), + equals(PlayTapped()), ); }); - test('HowToPlay supports value equality', () { + test('CharacterSelected supports value equality', () { expect( - HowToPlay(), - equals(HowToPlay()), + CharacterSelected(), + equals(CharacterSelected()), ); }); - test('Play supports value equality', () { + test('HowToPlayFinished supports value equality', () { expect( - Play(), - equals(Play()), + HowToPlayFinished(), + equals(HowToPlayFinished()), ); }); }); diff --git a/test/start_game/bloc/start_game_state_test.dart b/test/start_game/bloc/start_game_state_test.dart index 20c7803a..7ede696d 100644 --- a/test/start_game/bloc/start_game_state_test.dart +++ b/test/start_game/bloc/start_game_state_test.dart @@ -6,7 +6,7 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart'; void main() { group('StartGameState', () { final testState = StartGameState( - status: StartGameStatus.startGame, + status: StartGameStatus.selectCharacter, ); test('initial state has correct values', () { @@ -19,7 +19,7 @@ void main() { test('supports value equality', () { final secondState = StartGameState( - status: StartGameStatus.startGame, + status: StartGameStatus.selectCharacter, ); expect(testState, secondState); @@ -35,7 +35,7 @@ void main() { expect( testState.props, equals([ - StartGameStatus.startGame, + StartGameStatus.selectCharacter, ]), ); });