test: fixed tests for game bloc

pull/213/head
RuiAlonso 3 years ago
parent a7ab9905fa
commit 1658c895f5

@ -65,25 +65,3 @@ class MultiplierIncreased extends GameEvent {
@override @override
List<Object?> get props => []; List<Object?> get props => [];
} }
/// {@template multiplier_applied_game_event}
/// Event added when multiplier is applied to score.
/// {@endtemplate}
class MultiplierApplied extends GameEvent {
/// {@macro multiplier_applied_game_event}
const MultiplierApplied();
@override
List<Object?> get props => [];
}
/// {@template multiplier_reset_game_event}
/// Event added when multiplier is reset.
/// {@endtemplate}
class MultiplierReset extends GameEvent {
/// {@macro multiplier_reset_game_event}
const MultiplierReset();
@override
List<Object?> get props => [];
}

@ -28,6 +28,48 @@ void main() {
), ),
], ],
); );
blocTest<GameBloc, GameState>(
'apply multiplier to score '
'when round is lost',
build: GameBloc.new,
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 1,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost(balls: 0));
},
expect: () => [
isA<GameState>()
..having((state) => state.score, 'score', 15)
..having((state) => state.rounds, 'rounds', 1),
],
);
blocTest<GameBloc, GameState>(
'resets multiplier '
'when round is lost',
build: GameBloc.new,
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 1,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost(balls: 0));
},
expect: () => [
isA<GameState>()
..having((state) => state.multiplier, 'multiplier', 1)
..having((state) => state.rounds, 'rounds', 1),
],
);
}); });
group('Scored', () { group('Scored', () {
@ -84,7 +126,7 @@ void main() {
const GameState( const GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0, balls: 1,
rounds: 0, rounds: 0,
bonusHistory: [], bonusHistory: [],
), ),
@ -154,57 +196,6 @@ void main() {
); );
}); });
group('MultiplierApplied', () {
blocTest<GameBloc, GameState>(
'apply multiplier to score',
build: GameBloc.new,
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 2,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const MultiplierApplied());
},
expect: () => [
const GameState(
score: 15,
multiplier: 3,
balls: 2,
rounds: 2,
bonusHistory: [],
),
],
);
});
group('MultiplierReset', () {
blocTest<GameBloc, GameState>(
'resets multiplier',
build: GameBloc.new,
seed: () => const GameState(
score: 0,
multiplier: 3,
balls: 2,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const MultiplierReset());
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
rounds: 2,
bonusHistory: [],
),
],
);
});
group( group(
'BonusActivated', 'BonusActivated',
() { () {
@ -218,15 +209,15 @@ void main() {
GameState( GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 3, balls: 1,
rounds: 2, rounds: 3,
bonusHistory: [GameBonus.googleWord], bonusHistory: [GameBonus.googleWord],
), ),
GameState( GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 3, balls: 1,
rounds: 2, rounds: 3,
bonusHistory: [GameBonus.googleWord, GameBonus.dashNest], bonusHistory: [GameBonus.googleWord, GameBonus.dashNest],
), ),
], ],

@ -58,32 +58,6 @@ void main() {
}); });
}); });
group('MultiplierApplied', () {
test('can be instantiated', () {
expect(const MultiplierApplied(), isNotNull);
});
test('supports value equality', () {
expect(
MultiplierApplied(),
equals(const MultiplierApplied()),
);
});
});
group('MultiplierReset', () {
test('can be instantiated', () {
expect(const MultiplierReset(), isNotNull);
});
test('supports value equality', () {
expect(
MultiplierReset(),
equals(const MultiplierReset()),
);
});
});
group('BonusActivated', () { group('BonusActivated', () {
test('can be instantiated', () { test('can be instantiated', () {
expect(const BonusActivated(GameBonus.dashNest), isNotNull); expect(const BonusActivated(GameBonus.dashNest), isNotNull);

Loading…
Cancel
Save