feat: 초기 커밋
- Progress Quest 6.4 Flutter 포팅 프로젝트 - 게임 루프, 상태 관리, UI 구현 - 캐릭터 생성, 인벤토리, 장비, 주문 시스템 - 시장/판매/구매 메커니즘
This commit is contained in:
143
test/features/game_session_controller_test.dart
Normal file
143
test/features/game_session_controller_test.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
import 'package:askiineverdie/src/core/engine/game_mutations.dart';
|
||||
import 'package:askiineverdie/src/core/engine/progress_service.dart';
|
||||
import 'package:askiineverdie/src/core/engine/reward_service.dart';
|
||||
import 'package:askiineverdie/src/core/model/game_state.dart';
|
||||
import 'package:askiineverdie/src/core/model/pq_config.dart';
|
||||
import 'package:askiineverdie/src/core/storage/save_manager.dart';
|
||||
import 'package:askiineverdie/src/core/storage/save_repository.dart';
|
||||
import 'package:askiineverdie/src/core/storage/save_service.dart';
|
||||
import 'package:askiineverdie/src/features/game/game_session_controller.dart';
|
||||
import 'package:fake_async/fake_async.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class FakeSaveManager implements SaveManager {
|
||||
final List<GameState> savedStates = [];
|
||||
(SaveOutcome, GameState?) Function(String?)? onLoad;
|
||||
SaveOutcome saveOutcome = const SaveOutcome.success();
|
||||
|
||||
@override
|
||||
Future<SaveOutcome> saveState(GameState state, {String? fileName}) async {
|
||||
savedStates.add(state);
|
||||
return saveOutcome;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<(SaveOutcome, GameState?)> loadState({String? fileName}) async {
|
||||
if (onLoad != null) {
|
||||
return onLoad!(fileName);
|
||||
}
|
||||
return (const SaveOutcome.success(), null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SaveFileInfo>> listSaves() async => [];
|
||||
}
|
||||
|
||||
void main() {
|
||||
const config = PqConfig();
|
||||
final mutations = GameMutations(config);
|
||||
final progressService = ProgressService(
|
||||
config: config,
|
||||
mutations: mutations,
|
||||
rewards: RewardService(mutations),
|
||||
);
|
||||
|
||||
GameSessionController buildController(
|
||||
FakeAsync async,
|
||||
FakeSaveManager saveManager,
|
||||
) {
|
||||
return GameSessionController(
|
||||
progressService: progressService,
|
||||
saveManager: saveManager,
|
||||
tickInterval: const Duration(milliseconds: 10),
|
||||
now: () =>
|
||||
DateTime.fromMillisecondsSinceEpoch(async.elapsed.inMilliseconds),
|
||||
);
|
||||
}
|
||||
|
||||
GameState sampleState() {
|
||||
return GameState.withSeed(
|
||||
seed: 1,
|
||||
traits: const Traits(
|
||||
name: 'Hero',
|
||||
race: 'Human',
|
||||
klass: 'Fighter',
|
||||
level: 1,
|
||||
motto: '',
|
||||
guild: '',
|
||||
),
|
||||
stats: const Stats(
|
||||
str: 5,
|
||||
con: 5,
|
||||
dex: 5,
|
||||
intelligence: 5,
|
||||
wis: 5,
|
||||
cha: 5,
|
||||
hpMax: 10,
|
||||
mpMax: 8,
|
||||
),
|
||||
progress: const ProgressState(
|
||||
task: ProgressBarState(position: 0, max: 50),
|
||||
quest: ProgressBarState(position: 0, max: 1000),
|
||||
plot: ProgressBarState(position: 0, max: 1000),
|
||||
exp: ProgressBarState(position: 0, max: 9999),
|
||||
encumbrance: ProgressBarState(position: 0, max: 1),
|
||||
currentTask: TaskInfo(caption: 'Battle', type: TaskType.kill),
|
||||
plotStageCount: 1,
|
||||
questCount: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
test('startNew runs loop and publishes state updates', () {
|
||||
fakeAsync((async) {
|
||||
final saveManager = FakeSaveManager();
|
||||
final controller = buildController(async, saveManager);
|
||||
|
||||
controller.startNew(sampleState(), isNewGame: false);
|
||||
async.flushMicrotasks();
|
||||
|
||||
expect(controller.status, GameSessionStatus.running);
|
||||
expect(controller.state, isNotNull);
|
||||
|
||||
async.elapse(const Duration(milliseconds: 30));
|
||||
async.flushMicrotasks();
|
||||
|
||||
expect(controller.state!.progress.task.position, greaterThan(0));
|
||||
|
||||
controller.pause();
|
||||
async.flushMicrotasks();
|
||||
expect(controller.status, GameSessionStatus.idle);
|
||||
});
|
||||
});
|
||||
|
||||
test('loadAndStart surfaces save load errors', () {
|
||||
fakeAsync((async) {
|
||||
final saveManager = FakeSaveManager()
|
||||
..onLoad = (_) => (const SaveOutcome.failure('boom'), null);
|
||||
final controller = buildController(async, saveManager);
|
||||
|
||||
controller.loadAndStart(fileName: 'bad.pqf');
|
||||
async.flushMicrotasks();
|
||||
|
||||
expect(controller.status, GameSessionStatus.error);
|
||||
expect(controller.error, 'boom');
|
||||
});
|
||||
});
|
||||
|
||||
test('pause saves on stop when requested', () {
|
||||
fakeAsync((async) {
|
||||
final saveManager = FakeSaveManager();
|
||||
final controller = buildController(async, saveManager);
|
||||
|
||||
controller.startNew(sampleState(), isNewGame: false);
|
||||
async.flushMicrotasks();
|
||||
|
||||
controller.pause(saveOnStop: true);
|
||||
async.flushMicrotasks();
|
||||
|
||||
expect(controller.status, GameSessionStatus.idle);
|
||||
expect(saveManager.savedStates.length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user