38 lines
1.3 KiB
Dart
38 lines
1.3 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);
|
|
});
|
|
}
|