Wire season flow: map screen, progress save, win recording, next stage
SaveRepository (versioned JSON over prefs) with best-result merging and unlock walking; ContentRepository loads the bundled pack; SeasonFlow/ Progress notifiers orchestrate stage start -> win record -> advance. Season map grid with stars/locks, Home -> Map -> Game navigation, close button, next-stage action on the win overlay. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import 'package:block_seasons/data/content_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('loads the bundled Season 1 pack with 60 calibrated stages', () async {
|
||||
final repo = ContentRepository();
|
||||
final pack = await repo.loadBundledSeason('season_001');
|
||||
expect(pack.seasonId, 'season_001');
|
||||
expect(pack.stages, hasLength(60));
|
||||
expect(pack.titleFor('ko'), '첫 개화');
|
||||
|
||||
// Sanity: every stage has a positive budget and at least one objective.
|
||||
for (final stage in pack.stages) {
|
||||
expect(stage.moveLimit, greaterThan(0), reason: stage.id);
|
||||
expect(stage.objectives, isNotEmpty, reason: stage.id);
|
||||
expect(stage.stars.threeMovesLeft, greaterThan(stage.stars.twoMovesLeft),
|
||||
reason: stage.id);
|
||||
}
|
||||
});
|
||||
|
||||
test('availableSeasons returns the bundled season', () async {
|
||||
final repo = ContentRepository();
|
||||
final seasons = await repo.availableSeasons();
|
||||
expect(seasons.map((s) => s.seasonId), contains('season_001'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:block_seasons/data/save_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
Future<SaveRepository> freshRepo() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
return SaveRepository(await SharedPreferences.getInstance());
|
||||
}
|
||||
|
||||
test('starts empty: no progress, zero stars, first stage unlocked', () async {
|
||||
final repo = await freshRepo();
|
||||
expect(repo.progressFor('season_001', 's1'), isNull);
|
||||
expect(repo.totalStars('season_001'), 0);
|
||||
expect(repo.highestUnlockedIndex('season_001', ['s1', 's2', 's3']), 0);
|
||||
});
|
||||
|
||||
test('records results and keeps the best', () async {
|
||||
final repo = await freshRepo();
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 2, score: 500);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 1, score: 900);
|
||||
final progress = repo.progressFor('season_001', 's1')!;
|
||||
expect(progress.stars, 2, reason: 'stars never downgrade');
|
||||
expect(progress.bestScore, 900, reason: 'best score upgrades');
|
||||
});
|
||||
|
||||
test('unlock walks forward through starred stages', () async {
|
||||
final repo = await freshRepo();
|
||||
final ids = ['s1', 's2', 's3', 's4'];
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 1, score: 100);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's2', stars: 3, score: 300);
|
||||
expect(repo.highestUnlockedIndex('season_001', ids), 2);
|
||||
// Completing the last stage caps the index at the end of the list.
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's3', stars: 1, score: 1);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's4', stars: 1, score: 1);
|
||||
expect(repo.highestUnlockedIndex('season_001', ids), 3);
|
||||
});
|
||||
|
||||
test('totals stars per season independently', () async {
|
||||
final repo = await freshRepo();
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 2, score: 1);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's2', stars: 3, score: 1);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_002', stageId: 's1', stars: 1, score: 1);
|
||||
expect(repo.totalStars('season_001'), 5);
|
||||
expect(repo.totalStars('season_002'), 1);
|
||||
});
|
||||
|
||||
test('persists across repository instances', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final first = SaveRepository(prefs);
|
||||
await first.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 3, score: 777);
|
||||
|
||||
final second = SaveRepository(prefs);
|
||||
expect(second.progressFor('season_001', 's1')!.stars, 3);
|
||||
expect(second.progressFor('season_001', 's1')!.bestScore, 777);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:block_seasons/data/save_repository.dart';
|
||||
import 'package:block_seasons/game/engine/game_engine.dart';
|
||||
import 'package:block_seasons/game/models/season.dart';
|
||||
import 'package:block_seasons/state/providers.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
SeasonPack _pack() => SeasonPack.fromJson({
|
||||
'schemaVersion': 1,
|
||||
'seasonId': 'season_test',
|
||||
'version': 1,
|
||||
'title': {'en': 'T', 'ko': 'T'},
|
||||
'theme': {'tileSet': 'spring', 'background': 'bg.webp'},
|
||||
'stages': [
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
'id': 'st_$i',
|
||||
'seed': 100 + i,
|
||||
'moveLimit': 20,
|
||||
'preset': const <Map<String, dynamic>>[],
|
||||
'objectives': [
|
||||
{'type': 'reachScore', 'target': 999999},
|
||||
],
|
||||
'stars': {
|
||||
'two': {'movesLeft': 5},
|
||||
'three': {'movesLeft': 10},
|
||||
},
|
||||
'generatorProfile': 'mid',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Future<ProviderContainer> _container() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final repo = SaveRepository(await SharedPreferences.getInstance());
|
||||
final container = ProviderContainer(
|
||||
overrides: [saveRepositoryProvider.overrideWithValue(repo)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
return container;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('starting a season stage spins up the game session', () async {
|
||||
final container = await _container();
|
||||
final flow = container.read(seasonFlowProvider.notifier);
|
||||
flow.startSeasonStage(_pack(), 0);
|
||||
|
||||
expect(container.read(seasonFlowProvider)!.index, 0);
|
||||
expect(container.read(seasonFlowProvider)!.hasNext, isTrue);
|
||||
final session = container.read(gameSessionProvider)!;
|
||||
expect(session.phase, GamePhase.playing);
|
||||
expect(session.movesLeft, 20);
|
||||
});
|
||||
|
||||
test('recordWin persists stars through the progress notifier', () async {
|
||||
final container = await _container();
|
||||
final flow = container.read(seasonFlowProvider.notifier);
|
||||
flow.startSeasonStage(_pack(), 1);
|
||||
await flow.recordWin(stars: 3, score: 1234);
|
||||
|
||||
final repo = container.read(saveRepositoryProvider);
|
||||
expect(repo.progressFor('season_test', 'st_1')!.stars, 3);
|
||||
expect(container.read(progressProvider)['season_test/st_1']!.stars, 3);
|
||||
});
|
||||
|
||||
test('nextStage advances and starts the following stage', () async {
|
||||
final container = await _container();
|
||||
final flow = container.read(seasonFlowProvider.notifier);
|
||||
flow.startSeasonStage(_pack(), 1);
|
||||
flow.nextStage();
|
||||
|
||||
expect(container.read(seasonFlowProvider)!.index, 2);
|
||||
expect(container.read(seasonFlowProvider)!.hasNext, isFalse);
|
||||
expect(container.read(gameSessionProvider)!.phase, GamePhase.playing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'package:block_seasons/data/save_repository.dart';
|
||||
import 'package:block_seasons/game/engine/game_engine.dart';
|
||||
import 'package:block_seasons/game/models/season.dart';
|
||||
import 'package:block_seasons/l10n/gen/app_localizations.dart';
|
||||
import 'package:block_seasons/state/providers.dart';
|
||||
import 'package:block_seasons/ui/screens/game_screen.dart';
|
||||
import 'package:block_seasons/ui/screens/season_map_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
// The real 60-stage bundled pack is covered by the content repository
|
||||
// tests; the widget test uses a small pack because the bundled one is big
|
||||
// enough that loadString decodes on an isolate, which fake-async test time
|
||||
// never completes.
|
||||
SeasonPack _pack() => SeasonPack.fromJson({
|
||||
'schemaVersion': 1,
|
||||
'seasonId': 'season_001',
|
||||
'version': 1,
|
||||
'title': {'en': 'First Bloom', 'ko': '첫 개화'},
|
||||
'theme': {'tileSet': 'spring', 'background': 'bg.webp'},
|
||||
'stages': [
|
||||
for (var i = 1; i <= 3; i++)
|
||||
{
|
||||
'id': 'season_001_00$i',
|
||||
'seed': 100 + i,
|
||||
'moveLimit': 20,
|
||||
'preset': const <Map<String, dynamic>>[],
|
||||
'objectives': [
|
||||
{'type': 'reachScore', 'target': 999999},
|
||||
],
|
||||
'stars': {
|
||||
'two': {'movesLeft': 5},
|
||||
'three': {'movesLeft': 10},
|
||||
},
|
||||
'generatorProfile': 'mid',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
void main() {
|
||||
testWidgets('map shows stars, locks ahead, and starts unlocked stages',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final repo = SaveRepository(await SharedPreferences.getInstance());
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001',
|
||||
stageId: 'season_001_001',
|
||||
stars: 2,
|
||||
score: 300,
|
||||
);
|
||||
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
saveRepositoryProvider.overrideWithValue(repo),
|
||||
seasonsProvider.overrideWith((ref) async => [_pack()]),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: SeasonMapScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('★ 2/9'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.lock), findsOneWidget); // stage 3 locked
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
expect(find.text('2'), findsOneWidget);
|
||||
|
||||
// Stage 1 is starred, so stage 2 is unlocked and playable.
|
||||
await tester.tap(find.text('2'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GameScreen), findsOneWidget);
|
||||
final session = container.read(gameSessionProvider);
|
||||
expect(session, isNotNull);
|
||||
expect(session!.phase, GamePhase.playing);
|
||||
expect(container.read(seasonFlowProvider)!.stage.id, 'season_001_002');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user