fa2784519b
- daily claim: record the claim before granting boosters, so a crash mid-claim forfeits at most one reward instead of allowing a re-claim (booster farming) on next launch. - game screen: disarm the booster target synchronously before awaiting, so a rapid second board tap can't double-fire a use or stack a dialog. - new players: seed one of each booster once (idempotent persisted flag), fulfilling the spec's starting inventory. Wired in main(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
Dart
55 lines
1.9 KiB
Dart
import 'package:block_seasons/data/save_repository.dart';
|
|
import 'package:block_seasons/game/models/booster.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
Future<SaveRepository> fresh() async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
return SaveRepository(await SharedPreferences.getInstance());
|
|
}
|
|
|
|
test('booster counts start at zero', () async {
|
|
final repo = await fresh();
|
|
for (final t in BoosterType.values) {
|
|
expect(repo.boosterCount(t), 0);
|
|
}
|
|
});
|
|
|
|
test('grantBooster adds and persists across reload', () async {
|
|
final repo = await fresh();
|
|
await repo.grantBooster(BoosterType.hammer, 2);
|
|
expect(repo.boosterCount(BoosterType.hammer), 2);
|
|
|
|
final reloaded = SaveRepository(await SharedPreferences.getInstance());
|
|
expect(reloaded.boosterCount(BoosterType.hammer), 2);
|
|
});
|
|
|
|
test('consumeBooster decrements and returns false at zero', () async {
|
|
final repo = await fresh();
|
|
await repo.grantBooster(BoosterType.shuffle, 1);
|
|
expect(await repo.consumeBooster(BoosterType.shuffle), isTrue);
|
|
expect(repo.boosterCount(BoosterType.shuffle), 0);
|
|
expect(await repo.consumeBooster(BoosterType.shuffle), isFalse);
|
|
});
|
|
|
|
test('seedInitialBoosters grants 1 of each once, then is idempotent',
|
|
() async {
|
|
final repo = await fresh();
|
|
await repo.seedInitialBoostersIfNeeded();
|
|
for (final t in BoosterType.values) {
|
|
expect(repo.boosterCount(t), 1, reason: t.name);
|
|
}
|
|
|
|
// A second call (and a reload) must not grant again — the flag persists.
|
|
await repo.seedInitialBoostersIfNeeded();
|
|
final reloaded = SaveRepository(await SharedPreferences.getInstance());
|
|
await reloaded.seedInitialBoostersIfNeeded();
|
|
for (final t in BoosterType.values) {
|
|
expect(reloaded.boosterCount(t), 1, reason: '${t.name} after reload');
|
|
}
|
|
});
|
|
}
|