e31d8a2a5b
Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/199 Co-authored-by: Linghong <ink29535@proton.me> Co-committed-by: Linghong <ink29535@proton.me>
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { StrictMode } from 'react';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import type { AgentRuntimeUserInputRequest } from '../src/app/types';
|
|
import { AgentRuntimeUserInputCard } from '../src/features/agent-runtime/panels';
|
|
|
|
function clarificationRequest(): AgentRuntimeUserInputRequest {
|
|
return {
|
|
schemaVersion: 'agc.user_input_request.v1',
|
|
requestId: 'req-1',
|
|
agentId: 'project-supervisor',
|
|
taskId: 'task-1',
|
|
sessionId: 'session-1',
|
|
runId: 'run-1',
|
|
actionId: 'action-1',
|
|
status: 'pending',
|
|
questions: [
|
|
{
|
|
id: 'q1',
|
|
header: '第1轮·当前要决定:首版路线',
|
|
question: '这局游戏的重玩动力是什么?',
|
|
options: [
|
|
{ label: '分数驱动', description: '刷新纪录后重开' },
|
|
{ label: '成长驱动', description: '解锁新能力后重开' },
|
|
],
|
|
},
|
|
],
|
|
allowFreeform: true,
|
|
responseId: null,
|
|
requestedAt: 1,
|
|
updatedAt: 1,
|
|
};
|
|
}
|
|
|
|
describe('AgentRuntimeUserInputCard 澄清输入', () => {
|
|
it('手动输入自由回答不会让页面崩溃', () => {
|
|
render(
|
|
<StrictMode>
|
|
<AgentRuntimeUserInputCard
|
|
request={clarificationRequest()}
|
|
controlBusy={false}
|
|
/>
|
|
</StrictMode>,
|
|
);
|
|
|
|
const textarea = screen.getByLabelText(
|
|
'第1轮·当前要决定:首版路线 其他回答',
|
|
);
|
|
fireEvent.change(textarea, { target: { value: '玩家自己写的答案' } });
|
|
|
|
expect((textarea as HTMLTextAreaElement).value).toBe('玩家自己写的答案');
|
|
});
|
|
|
|
it('先选中选项再清空填充文本不会让页面崩溃', () => {
|
|
render(
|
|
<StrictMode>
|
|
<AgentRuntimeUserInputCard
|
|
request={clarificationRequest()}
|
|
controlBusy={false}
|
|
/>
|
|
</StrictMode>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByText('分数驱动'));
|
|
const textarea = screen.getByLabelText(
|
|
'第1轮·当前要决定:首版路线 其他回答',
|
|
) as HTMLTextAreaElement;
|
|
expect(textarea.value).toBe('分数驱动');
|
|
|
|
fireEvent.change(textarea, { target: { value: '' } });
|
|
expect(textarea.value).toBe('');
|
|
});
|
|
});
|