fix: apply code review

pull/184/head
arturplaczek 3 years ago
parent cfa6e5abc4
commit 61938057b4

@ -14,28 +14,28 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
required PinballGame game, required PinballGame game,
}) : _game = game, }) : _game = game,
super(const StartGameState.initial()) { super(const StartGameState.initial()) {
on<StartGame>(_onStartGame); on<PlayTapped>(_onStartGame);
on<HowToPlay>(_onHowToPlay); on<CharacterSelected>(_onCharacterSelected);
on<Play>(_onPlay); on<HowToPlayFinished>(_onHowToPlayFinished);
} }
final PinballGame _game; final PinballGame _game;
void _onStartGame( void _onStartGame(
StartGame event, PlayTapped event,
Emitter<StartGameState> emit, Emitter<StartGameState> emit,
) { ) {
_game.gameFlowController.start(); _game.gameFlowController.start();
emit( emit(
state.copyWith( state.copyWith(
status: StartGameStatus.startGame, status: StartGameStatus.selectCharacter,
), ),
); );
} }
void _onHowToPlay( void _onCharacterSelected(
HowToPlay event, CharacterSelected event,
Emitter<StartGameState> emit, Emitter<StartGameState> emit,
) { ) {
emit( emit(
@ -45,8 +45,8 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
); );
} }
void _onPlay( void _onHowToPlayFinished(
Play event, HowToPlayFinished event,
Emitter<StartGameState> emit, Emitter<StartGameState> emit,
) { ) {
emit( emit(

@ -8,34 +8,34 @@ abstract class StartGameEvent extends Equatable {
const StartGameEvent(); const StartGameEvent();
} }
/// {@template select_character} /// {@template play_tapped}
/// Select character event. /// Play tapped event.
/// {@endtemplate} /// {@endtemplate}
class StartGame extends StartGameEvent { class PlayTapped extends StartGameEvent {
/// {@macro select_character} /// {@macro play_tapped}
const StartGame(); const PlayTapped();
@override @override
List<Object> get props => []; List<Object> get props => [];
} }
/// {@template how_to_play} /// {@template character_selected}
/// How to play event. /// Character selected event.
/// {@endtemplate} /// {@endtemplate}
class HowToPlay extends StartGameEvent { class CharacterSelected extends StartGameEvent {
/// {@macro how_to_play} /// {@macro character_selected}
const HowToPlay(); const CharacterSelected();
@override @override
List<Object> get props => []; List<Object> get props => [];
} }
/// {@template play} /// {@template how_to_play_finished}
/// Play event. /// How to play finished event.
/// {@endtemplate} /// {@endtemplate}
class Play extends StartGameEvent { class HowToPlayFinished extends StartGameEvent {
/// {@macro play} /// {@macro how_to_play_finished}
const Play(); const HowToPlayFinished();
@override @override
List<Object> get props => []; List<Object> get props => [];

@ -2,11 +2,11 @@ part of 'start_game_bloc.dart';
/// Defines status of start game flow. /// Defines status of start game flow.
enum StartGameStatus { enum StartGameStatus {
/// Starting status. /// Initial status.
initial, initial,
/// Selection characters status. /// Selection characters status.
startGame, selectCharacter,
/// How to play status. /// How to play status.
howToPlay, howToPlay,

@ -0,0 +1 @@
export 'bloc/start_game_bloc.dart';

@ -21,24 +21,24 @@ void main() {
group('StartGameBloc', () { group('StartGameBloc', () {
blocTest<StartGameBloc, StartGameState>( blocTest<StartGameBloc, StartGameState>(
'on StartGame changes status to StartGame', 'on PlayTapped changes status to selectCharacter',
build: () => StartGameBloc( build: () => StartGameBloc(
game: pinballGame, game: pinballGame,
), ),
act: (bloc) => bloc.add(const StartGame()), act: (bloc) => bloc.add(const PlayTapped()),
expect: () => [ expect: () => [
const StartGameState( const StartGameState(
status: StartGameStatus.startGame, status: StartGameStatus.selectCharacter,
) )
], ],
); );
blocTest<StartGameBloc, StartGameState>( blocTest<StartGameBloc, StartGameState>(
'on HowToPlay changes status to howToPlay', 'on CharacterSelected changes status to howToPlay',
build: () => StartGameBloc( build: () => StartGameBloc(
game: pinballGame, game: pinballGame,
), ),
act: (bloc) => bloc.add(const HowToPlay()), act: (bloc) => bloc.add(const CharacterSelected()),
expect: () => [ expect: () => [
const StartGameState( const StartGameState(
status: StartGameStatus.howToPlay, status: StartGameStatus.howToPlay,
@ -47,11 +47,11 @@ void main() {
); );
blocTest<StartGameBloc, StartGameState>( blocTest<StartGameBloc, StartGameState>(
'on Play changes status to play', 'on HowToPlayFinished changes status to play',
build: () => StartGameBloc( build: () => StartGameBloc(
game: pinballGame, game: pinballGame,
), ),
act: (bloc) => bloc.add(const Play()), act: (bloc) => bloc.add(const HowToPlayFinished()),
expect: () => [ expect: () => [
const StartGameState( const StartGameState(
status: StartGameStatus.play, status: StartGameStatus.play,

@ -5,24 +5,24 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart';
void main() { void main() {
group('StartGameEvent', () { group('StartGameEvent', () {
test('StartGame supports value equality', () { test('PlayTapped supports value equality', () {
expect( expect(
StartGame(), PlayTapped(),
equals(StartGame()), equals(PlayTapped()),
); );
}); });
test('HowToPlay supports value equality', () { test('CharacterSelected supports value equality', () {
expect( expect(
HowToPlay(), CharacterSelected(),
equals(HowToPlay()), equals(CharacterSelected()),
); );
}); });
test('Play supports value equality', () { test('HowToPlayFinished supports value equality', () {
expect( expect(
Play(), HowToPlayFinished(),
equals(Play()), equals(HowToPlayFinished()),
); );
}); });
}); });

@ -6,7 +6,7 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart';
void main() { void main() {
group('StartGameState', () { group('StartGameState', () {
final testState = StartGameState( final testState = StartGameState(
status: StartGameStatus.startGame, status: StartGameStatus.selectCharacter,
); );
test('initial state has correct values', () { test('initial state has correct values', () {
@ -19,7 +19,7 @@ void main() {
test('supports value equality', () { test('supports value equality', () {
final secondState = StartGameState( final secondState = StartGameState(
status: StartGameStatus.startGame, status: StartGameStatus.selectCharacter,
); );
expect(testState, secondState); expect(testState, secondState);
@ -35,7 +35,7 @@ void main() {
expect( expect(
testState.props, testState.props,
equals([ equals([
StartGameStatus.startGame, StartGameStatus.selectCharacter,
]), ]),
); );
}); });

Loading…
Cancel
Save