Files
Genarrative/src/hooks/rpg-runtime-story/storyContextBuilder.test.ts
2026-04-29 11:51:04 +08:00

58 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { AnimationState, type GameState, type StoryMoment } from '../../types';
import { buildStoryContextFromState } from './storyContextBuilder';
function createState(overrides: Partial<GameState> = {}): GameState {
return {
worldType: 'WUXIA',
runtimeSessionId: 'runtime-main',
runtimeActionVersion: 3,
runtimeMode: 'play',
runtimePersistenceDisabled: false,
playerHp: 30,
playerMaxHp: 40,
playerMana: 12,
playerMaxMana: 20,
inBattle: false,
playerX: 0,
playerFacing: 'right',
animationState: AnimationState.IDLE,
playerSkillCooldowns: {},
currentScenePreset: {
id: 'forest-trail',
name: '林间小径',
description: '风声穿过树梢。',
},
...overrides,
} as GameState;
}
describe('storyContextBuilder', () => {
it('keeps normal play context lightweight', () => {
const context = buildStoryContextFromState(createState());
expect(context.runtimeSessionId).toBe('runtime-main');
expect(context.runtimeSnapshot).toBeUndefined();
});
it('attaches transient snapshot for disabled persistence runtime', () => {
const state = createState({
runtimeSessionId: 'runtime-preview',
runtimePersistenceDisabled: true,
});
const currentStory: StoryMoment = {
text: '断桥客站在风口,等你先开口。',
options: [],
};
const context = buildStoryContextFromState(state, { currentStory });
expect(context.runtimeSnapshot).toEqual({
bottomTab: 'adventure',
gameState: state,
currentStory,
});
});
});