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';
/// {@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}
class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
/// {@macro start_game_bloc}
@ -14,22 +14,22 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
required PinballGame game,
}) : _game = game,
super(const StartGameState.initial()) {
on<SelectCharacter>(_onSelectCharacter);
on<StartGame>(_onStartGame);
on<HowToPlay>(_onHowToPlay);
on<Play>(_onPlay);
}
final PinballGame _game;
void _onSelectCharacter(
SelectCharacter event,
void _onStartGame(
StartGame event,
Emitter<StartGameState> emit,
) {
_game.gameFlowController.start();
emit(
state.copyWith(
status: StartGameStatus.selectCharacter,
status: StartGameStatus.startGame,
),
);
}

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

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

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

@ -1,14 +1,14 @@
// ignore_for_file: prefer_const_constructors
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() {
group('StartGameEvent', () {
test('SelectCharacter supports value equality', () {
test('StartGame supports value equality', () {
expect(
SelectCharacter(),
equals(SelectCharacter()),
StartGame(),
equals(StartGame()),
);
});

@ -1,12 +1,12 @@
// ignore_for_file: prefer_const_constructors
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() {
group('StartGameState', () {
final testState = StartGameState(
status: StartGameStatus.selectCharacter,
status: StartGameStatus.startGame,
);
test('initial state has correct values', () {
@ -19,7 +19,7 @@ void main() {
test('supports value equality', () {
final secondState = StartGameState(
status: StartGameStatus.selectCharacter,
status: StartGameStatus.startGame,
);
expect(testState, secondState);
@ -35,7 +35,7 @@ void main() {
expect(
testState.props,
equals([
StartGameStatus.selectCharacter,
StartGameStatus.startGame,
]),
);
});
Loading…
Cancel
Save