1
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-18 19:40:33 +08:00
parent 54b3d3c490
commit 8c3fbd9bcf
15 changed files with 904 additions and 65 deletions

View File

@@ -1,8 +1,8 @@
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import { AdventurePanel } from './AdventurePanel';
import { AnimationState, type Character, type StoryMoment, type StoryOption, WorldType } from '../types';
import { AdventurePanel } from './AdventurePanel';
function createCharacter(): Character {
return {
@@ -43,17 +43,29 @@ function createOption(functionId: string, actionText: string): StoryOption {
};
}
function renderPanel(currentStory: StoryMoment, displayedOptions: StoryOption[]) {
function renderPanel(
currentStory: StoryMoment,
displayedOptions: StoryOption[],
overrides: {
canRefreshOptions?: boolean;
hideOptions?: boolean;
isLoading?: boolean;
onSubmitNpcChatInput?: (input: string) => boolean;
onExitNpcChat?: () => boolean;
} = {},
) {
return renderToStaticMarkup(
<AdventurePanel
aiError={null}
currentStory={currentStory}
isLoading={false}
isLoading={overrides.isLoading ?? false}
displayedOptions={displayedOptions}
hideOptions={false}
canRefreshOptions={false}
hideOptions={overrides.hideOptions ?? false}
canRefreshOptions={overrides.canRefreshOptions ?? false}
onRefreshOptions={() => undefined}
onChoice={() => undefined}
onSubmitNpcChatInput={overrides.onSubmitNpcChatInput}
onExitNpcChat={overrides.onExitNpcChat}
onOpenCharacter={() => undefined}
onOpenInventory={() => undefined}
playerCharacter={createCharacter()}
@@ -129,3 +141,36 @@ test('adventure panel does not show deferred hint for non-continue options with
expect(html).not.toContain('剧情推理完成,继续后显示新的冒险选项');
});
test('adventure panel shows npc chat custom input and exit button in chat mode', () => {
const optionA = createOption('npc_chat', '先听对方把话说完');
const optionB = createOption('npc_chat', '顺着这个问题继续追问');
const optionC = createOption('npc_chat', '换个更轻松的语气回应');
const currentStory: StoryMoment = {
text: '你们的对话正在继续。',
displayMode: 'dialogue',
dialogue: [
{ speaker: 'player', text: '你刚才那句话是什么意思?' },
{ speaker: 'npc', speakerName: '柳无声', text: '意思是这件事还没结束。' },
{ speaker: 'system', text: '关系升温 好感 +3', affinityDelta: 3 },
],
options: [optionA, optionB, optionC],
npcChatState: {
npcId: 'npc-liu',
npcName: '柳无声',
turnCount: 2,
customInputPlaceholder: '输入你想对 TA 说的话',
},
};
const html = renderPanel(currentStory, [optionA, optionB, optionC], {
canRefreshOptions: true,
onSubmitNpcChatInput: () => true,
onExitNpcChat: () => true,
});
expect(html).toContain('退出聊天');
expect(html).toContain('输入你想对 TA 说的话');
expect(html).toContain('发送');
expect(html).not.toContain('换一换');
});