-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/answer-word
- Loading branch information
Showing
12 changed files
with
508 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:api_client/api_client.dart'; | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:game_domain/game_domain.dart'; | ||
|
||
part 'game_intro_event.dart'; | ||
part 'game_intro_state.dart'; | ||
|
||
class GameIntroBloc extends Bloc<GameIntroEvent, GameIntroState> { | ||
GameIntroBloc({ | ||
required LeaderboardResource leaderboardResource, | ||
}) : _leaderboardResource = leaderboardResource, | ||
super(const GameIntroState()) { | ||
on<GameIntroPlayerCreated>(_onGameIntroPlayerCreated); | ||
} | ||
|
||
final LeaderboardResource _leaderboardResource; | ||
|
||
Future<void> _onGameIntroPlayerCreated( | ||
GameIntroPlayerCreated event, | ||
Emitter<GameIntroState> emit, | ||
) async { | ||
try { | ||
emit( | ||
const GameIntroState( | ||
status: GameIntroPlayerCreationStatus.inProgress, | ||
), | ||
); | ||
|
||
await _leaderboardResource.createScore( | ||
initials: event.initials, | ||
mascot: event.mascot!, | ||
); | ||
|
||
emit( | ||
const GameIntroState( | ||
status: GameIntroPlayerCreationStatus.success, | ||
), | ||
); | ||
} catch (error, stackTrace) { | ||
addError(error, stackTrace); | ||
emit( | ||
const GameIntroState( | ||
status: GameIntroPlayerCreationStatus.failure, | ||
), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
part of 'game_intro_bloc.dart'; | ||
|
||
abstract class GameIntroEvent extends Equatable { | ||
const GameIntroEvent(); | ||
} | ||
|
||
class GameIntroPlayerCreated extends GameIntroEvent { | ||
const GameIntroPlayerCreated({ | ||
required this.initials, | ||
required this.mascot, | ||
}); | ||
|
||
final String initials; | ||
final Mascots? mascot; | ||
|
||
@override | ||
List<Object?> get props => [initials, mascot]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
part of 'game_intro_bloc.dart'; | ||
|
||
enum GameIntroPlayerCreationStatus { | ||
initial, | ||
inProgress, | ||
success, | ||
failure, | ||
} | ||
|
||
class GameIntroState extends Equatable { | ||
const GameIntroState({ | ||
this.status = GameIntroPlayerCreationStatus.initial, | ||
}); | ||
|
||
final GameIntroPlayerCreationStatus status; | ||
|
||
@override | ||
List<Object?> get props => [status]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
|
||
import 'package:api_client/api_client.dart'; | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:game_domain/game_domain.dart'; | ||
import 'package:io_crossword/game_intro/bloc/game_intro_bloc.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
class _MockLeaderboardResource extends Mock implements LeaderboardResource {} | ||
|
||
void main() { | ||
group('$GameIntroBloc', () { | ||
late LeaderboardResource leaderboardResource; | ||
late GameIntroBloc bloc; | ||
|
||
setUp(() { | ||
leaderboardResource = _MockLeaderboardResource(); | ||
bloc = GameIntroBloc( | ||
leaderboardResource: leaderboardResource, | ||
); | ||
}); | ||
|
||
group('$GameIntroPlayerCreated', () { | ||
blocTest<GameIntroBloc, GameIntroState>( | ||
'emits [inProgress, success]', | ||
setUp: () { | ||
when( | ||
() => leaderboardResource.createScore( | ||
initials: 'ABC', | ||
mascot: Mascots.android, | ||
), | ||
).thenAnswer((_) async => []); | ||
}, | ||
build: () => bloc, | ||
act: (bloc) => bloc.add( | ||
GameIntroPlayerCreated( | ||
initials: 'ABC', | ||
mascot: Mascots.android, | ||
), | ||
), | ||
expect: () => [ | ||
GameIntroState( | ||
status: GameIntroPlayerCreationStatus.inProgress, | ||
), | ||
GameIntroState( | ||
status: GameIntroPlayerCreationStatus.success, | ||
), | ||
], | ||
); | ||
|
||
blocTest<GameIntroBloc, GameIntroState>( | ||
'emits [inProgress, failure] when createScore throws exception', | ||
setUp: () { | ||
when( | ||
() => leaderboardResource.createScore( | ||
initials: 'ABC', | ||
mascot: Mascots.android, | ||
), | ||
).thenThrow(Exception()); | ||
}, | ||
build: () => bloc, | ||
act: (bloc) => bloc.add( | ||
GameIntroPlayerCreated( | ||
initials: 'ABC', | ||
mascot: Mascots.android, | ||
), | ||
), | ||
expect: () => [ | ||
GameIntroState( | ||
status: GameIntroPlayerCreationStatus.inProgress, | ||
), | ||
GameIntroState( | ||
status: GameIntroPlayerCreationStatus.failure, | ||
), | ||
], | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:game_domain/game_domain.dart'; | ||
import 'package:io_crossword/game_intro/bloc/game_intro_bloc.dart'; | ||
|
||
void main() { | ||
group('$GameIntroEvent', () { | ||
group('$GameIntroPlayerCreated', () { | ||
test('supports equality', () { | ||
expect( | ||
GameIntroPlayerCreated(mascot: Mascots.android, initials: 'ABC'), | ||
equals( | ||
GameIntroPlayerCreated(mascot: Mascots.android, initials: 'ABC'), | ||
), | ||
); | ||
|
||
expect( | ||
GameIntroPlayerCreated(mascot: Mascots.android, initials: 'ABC'), | ||
isNot( | ||
equals( | ||
GameIntroPlayerCreated(mascot: Mascots.dash, initials: 'ABC'), | ||
), | ||
), | ||
); | ||
|
||
expect( | ||
GameIntroPlayerCreated(mascot: Mascots.android, initials: 'ABC'), | ||
isNot( | ||
equals( | ||
GameIntroPlayerCreated(mascot: Mascots.android, initials: 'CCC'), | ||
), | ||
), | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.