diff --git a/test/game/bloc/game_bloc_test.dart b/test/game/bloc/game_bloc_test.dart index f4b79001..df0c8a6b 100644 --- a/test/game/bloc/game_bloc_test.dart +++ b/test/game/bloc/game_bloc_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer_const_constructors + import 'package:bloc_test/bloc_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/game/game.dart'; @@ -26,6 +28,7 @@ void main() { balls: 2, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), const GameState( @@ -33,6 +36,7 @@ void main() { balls: 1, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), const GameState( @@ -40,6 +44,7 @@ void main() { balls: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), ], @@ -60,6 +65,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), const GameState( @@ -67,6 +73,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), ], @@ -88,6 +95,7 @@ void main() { balls: 2, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), const GameState( @@ -95,6 +103,7 @@ void main() { balls: 1, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), const GameState( @@ -102,6 +111,7 @@ void main() { balls: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), ], @@ -122,6 +132,7 @@ void main() { balls: 3, activatedBonusLetters: [0], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -129,6 +140,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -136,6 +148,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1, 2], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), ], @@ -157,6 +170,7 @@ void main() { balls: 3, activatedBonusLetters: [0], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -164,6 +178,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -171,6 +186,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1, 2], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -178,6 +194,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1, 2, 3], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -185,6 +202,7 @@ void main() { balls: 3, activatedBonusLetters: [0, 1, 2, 3, 4], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -192,6 +210,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [GameBonus.word], ), GameState( @@ -199,6 +218,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [GameBonus.word], ), ], @@ -219,6 +239,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {'0'}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -226,6 +247,7 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {'0', '1'}, + activatedSparkyFires: {}, bonusHistory: [], ), GameState( @@ -233,10 +255,45 @@ void main() { balls: 3, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [GameBonus.dashNest], ), ], ); }); + + group('SparkyFireActivated', () { + const fireId = '0'; + + blocTest( + 'adds fireId to collection when activate', + build: GameBloc.new, + act: (bloc) => bloc..add(const SparkyFireActivated(fireId)), + expect: () => [ + isA() + ..having( + (state) => state.activatedSparkyFires, + 'activatedSparkyFires', + contains(fireId), + ), + ], + ); + + blocTest( + 'removes fireId from collection when deactivate', + build: GameBloc.new, + seed: () => + GameState.initial().copyWith(activatedSparkyFires: {fireId}), + act: (bloc) => bloc..add(const SparkyFireActivated(fireId)), + expect: () => [ + isA() + ..having( + (state) => state.activatedSparkyFires, + 'activatedSparkyFires', + isNot(contains(fireId)), + ), + ], + ); + }); }); } diff --git a/test/game/bloc/game_event_test.dart b/test/game/bloc/game_event_test.dart index af9f6148..8d0d622b 100644 --- a/test/game/bloc/game_event_test.dart +++ b/test/game/bloc/game_event_test.dart @@ -84,5 +84,22 @@ void main() { ); }); }); + + group('SparkyFireActivated', () { + test('can be instantiated', () { + expect(const SparkyFireActivated('0'), isNotNull); + }); + + test('supports value equality', () { + expect( + SparkyFireActivated('0'), + equals(SparkyFireActivated('0')), + ); + expect( + SparkyFireActivated('0'), + isNot(equals(SparkyFireActivated('1'))), + ); + }); + }); }); } diff --git a/test/game/bloc/game_state_test.dart b/test/game/bloc/game_state_test.dart index ed80d192..cd897291 100644 --- a/test/game/bloc/game_state_test.dart +++ b/test/game/bloc/game_state_test.dart @@ -12,6 +12,7 @@ void main() { balls: 0, activatedBonusLetters: const [], activatedDashNests: const {}, + activatedSparkyFires: const {}, bonusHistory: const [], ), equals( @@ -20,6 +21,7 @@ void main() { balls: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), ), @@ -34,6 +36,7 @@ void main() { balls: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ), isNotNull, @@ -51,6 +54,7 @@ void main() { score: 0, activatedBonusLetters: const [], activatedDashNests: const {}, + activatedSparkyFires: const {}, bonusHistory: const [], ), throwsAssertionError, @@ -68,6 +72,7 @@ void main() { score: -1, activatedBonusLetters: const [], activatedDashNests: const {}, + activatedSparkyFires: const {}, bonusHistory: const [], ), throwsAssertionError, @@ -84,6 +89,7 @@ void main() { score: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect(gameState.isGameOver, isTrue); @@ -97,6 +103,7 @@ void main() { score: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect(gameState.isGameOver, isFalse); @@ -112,6 +119,7 @@ void main() { score: 0, activatedBonusLetters: [1], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect(gameState.isLetterActivated(1), isTrue); @@ -126,6 +134,7 @@ void main() { score: 0, activatedBonusLetters: [1], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect(gameState.isLetterActivated(0), isFalse); @@ -143,6 +152,7 @@ void main() { score: 2, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect( @@ -161,6 +171,7 @@ void main() { score: 2, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); expect( @@ -179,6 +190,7 @@ void main() { balls: 0, activatedBonusLetters: [], activatedDashNests: {}, + activatedSparkyFires: {}, bonusHistory: [], ); final otherGameState = GameState( @@ -186,6 +198,7 @@ void main() { balls: gameState.balls + 1, activatedBonusLetters: const [0], activatedDashNests: const {'1'}, + activatedSparkyFires: const {'1'}, bonusHistory: const [GameBonus.word], ); expect(gameState, isNot(equals(otherGameState))); @@ -196,6 +209,7 @@ void main() { balls: otherGameState.balls, activatedBonusLetters: otherGameState.activatedBonusLetters, activatedDashNests: otherGameState.activatedDashNests, + activatedSparkyFires: otherGameState.activatedSparkyFires, bonusHistory: otherGameState.bonusHistory, ), equals(otherGameState),