fix: apply code review

pull/184/head
arturplaczek 3 years ago
parent c180110c80
commit cfa6e5abc4

@ -6,7 +6,7 @@ part 'start_game_event.dart';
part 'start_game_state.dart'; part 'start_game_state.dart';
/// {@template start_game_bloc} /// {@template start_game_bloc}
/// Bloc which allows to control user state before launch the game. /// Bloc that manages the app flow before the game starts.
/// {@endtemplate} /// {@endtemplate}
class StartGameBloc extends Bloc<StartGameEvent, StartGameState> { class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
/// {@macro start_game_bloc} /// {@macro start_game_bloc}
@ -14,22 +14,22 @@ 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<SelectCharacter>(_onSelectCharacter); on<StartGame>(_onStartGame);
on<HowToPlay>(_onHowToPlay); on<HowToPlay>(_onHowToPlay);
on<Play>(_onPlay); on<Play>(_onPlay);
} }
final PinballGame _game; final PinballGame _game;
void _onSelectCharacter( void _onStartGame(
SelectCharacter event, StartGame event,
Emitter<StartGameState> emit, Emitter<StartGameState> emit,
) { ) {
_game.gameFlowController.start(); _game.gameFlowController.start();
emit( emit(
state.copyWith( state.copyWith(
status: StartGameStatus.selectCharacter, status: StartGameStatus.startGame,
), ),
); );
} }

@ -1,7 +1,7 @@
part of 'start_game_bloc.dart'; part of 'start_game_bloc.dart';
/// {@template start_game_event} /// {@template start_game_event}
/// Event added when user is staring the game. /// Event added during the start game flow.
/// {@endtemplate} /// {@endtemplate}
abstract class StartGameEvent extends Equatable { abstract class StartGameEvent extends Equatable {
/// {@macro start_game_event} /// {@macro start_game_event}
@ -11,9 +11,9 @@ abstract class StartGameEvent extends Equatable {
/// {@template select_character} /// {@template select_character}
/// Select character event. /// Select character event.
/// {@endtemplate} /// {@endtemplate}
class SelectCharacter extends StartGameEvent { class StartGame extends StartGameEvent {
/// {@macro select_character} /// {@macro select_character}
const SelectCharacter(); const StartGame();
@override @override
List<Object> get props => []; List<Object> get props => [];

@ -6,7 +6,7 @@ enum StartGameStatus {
initial, initial,
/// Selection characters status. /// Selection characters status.
selectCharacter, startGame,
/// How to play status. /// How to play status.
howToPlay, howToPlay,
@ -16,7 +16,7 @@ enum StartGameStatus {
} }
/// {@template start_game_state} /// {@template start_game_state}
/// Represents the state of flow before launch the game. /// Represents the state of flow before the game starts.
/// {@endtemplate} /// {@endtemplate}
class StartGameState extends Equatable { class StartGameState extends Equatable {
/// {@macro start_game_state} /// {@macro start_game_state}

@ -1,12 +1,10 @@
import 'package:bloc_test/bloc_test.dart'; import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/bloc/start_game_bloc.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball/start_game/bloc/start_game_bloc.dart';
class MockPinballGame extends Mock implements PinballGame {} import '../../helpers/helpers.dart';
class MockGameFlowController extends Mock implements GameFlowController {}
void main() { void main() {
late PinballGame pinballGame; late PinballGame pinballGame;
@ -23,14 +21,14 @@ void main() {
group('StartGameBloc', () { group('StartGameBloc', () {
blocTest<StartGameBloc, StartGameState>( blocTest<StartGameBloc, StartGameState>(
'on SelectCharacter changes status to selectCharacter', 'on StartGame changes status to StartGame',
build: () => StartGameBloc( build: () => StartGameBloc(
game: pinballGame, game: pinballGame,
), ),
act: (bloc) => bloc.add(const SelectCharacter()), act: (bloc) => bloc.add(const StartGame()),
expect: () => [ expect: () => [
const StartGameState( const StartGameState(
status: StartGameStatus.selectCharacter, status: StartGameStatus.startGame,
) )
], ],
); );

@ -1,14 +1,14 @@
// ignore_for_file: prefer_const_constructors // ignore_for_file: prefer_const_constructors
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/bloc/start_game_bloc.dart'; import 'package:pinball/start_game/bloc/start_game_bloc.dart';
void main() { void main() {
group('StartGameEvent', () { group('StartGameEvent', () {
test('SelectCharacter supports value equality', () { test('StartGame supports value equality', () {
expect( expect(
SelectCharacter(), StartGame(),
equals(SelectCharacter()), equals(StartGame()),
); );
}); });

@ -1,12 +1,12 @@
// ignore_for_file: prefer_const_constructors // ignore_for_file: prefer_const_constructors
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/bloc/start_game_bloc.dart'; 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.selectCharacter, status: StartGameStatus.startGame,
); );
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.selectCharacter, status: StartGameStatus.startGame,
); );
expect(testState, secondState); expect(testState, secondState);
@ -35,7 +35,7 @@ void main() {
expect( expect(
testState.props, testState.props,
equals([ equals([
StartGameStatus.selectCharacter, StartGameStatus.startGame,
]), ]),
); );
}); });
Loading…
Cancel
Save