feat(save): persist booster inventory
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user