53 lines
3.1 KiB
TypeScript
53 lines
3.1 KiB
TypeScript
import { useState } from 'react';
|
|
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
|
|
import { afterEach, expect, it, vi } from 'vitest';
|
|
import { ConfigurationFields } from '@/pages/CloudAgents/ConfigurationFields';
|
|
import { EMPTY_CLOUD_CONFIGURATION, type CloudAgentConfiguration } from '../../shared/cloud-agents';
|
|
|
|
const api = vi.hoisted(() => ({ call: vi.fn() }));
|
|
vi.mock('@/lib/cloud-agents-api', () => ({ cloudAgentsApi: api }));
|
|
afterEach(() => { cleanup(); vi.resetAllMocks(); });
|
|
|
|
it('removes subagent selection while other capability edits preserve historical bindings', async () => {
|
|
api.call.mockImplementation(async operation => {
|
|
if (operation === 'catalog') return {
|
|
models: [{ id: 'old-model', name: '原模型' }, { id: 'new-model', name: '新模型' }],
|
|
resources: {
|
|
tools: [{ key: 'tool', name: '查询工具' }], skills: [{ key: 'skill', name: '研究手册' }],
|
|
mcps: [{ key: 'mcp', name: '资料连接' }], knowledges: [{ key: 'kb', name: '已有资料' }],
|
|
subagents: [{ key: 'historical-child', name: '调研探索员' }],
|
|
},
|
|
};
|
|
if (operation === 'knowledge') return { databases: [], models: [] };
|
|
throw new Error('Unexpected operation ' + operation);
|
|
});
|
|
const initial: CloudAgentConfiguration = {
|
|
...EMPTY_CLOUD_CONFIGURATION, model: 'old-model', subagents: ['historical-child', 'missing-child'],
|
|
max_execution_steps: 30, max_output_tokens: 2048, max_run_seconds: 300,
|
|
};
|
|
const changed = vi.fn();
|
|
function Harness() {
|
|
const [value, setValue] = useState(initial);
|
|
return <ConfigurationFields slug={'ml-' + 'a'.repeat(32)} value={value} disabled={false}
|
|
onChange={next => { changed(next); setValue(next); }} />;
|
|
}
|
|
render(<Harness />);
|
|
await screen.findByRole('option', { name: '新模型' });
|
|
expect(screen.queryByRole('group', { name: '子智能体', exact: true })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: '选择子智能体', exact: true })).not.toBeInTheDocument();
|
|
expect(screen.queryByText('调研探索员')).not.toBeInTheDocument();
|
|
expect(screen.queryByText(/missing-child/)).not.toBeInTheDocument();
|
|
expect(changed).not.toHaveBeenCalled();
|
|
fireEvent.change(screen.getByRole('combobox', { name: '模型' }), { target: { value: 'new-model' } });
|
|
for (const [button, checkbox] of [['选择工具箱', '查询工具'], ['选择做事手册', '研究手册'], ['选择MCP 服务', '资料连接']]) {
|
|
fireEvent.click(screen.getByRole('button', { name: button, exact: true }));
|
|
fireEvent.click(screen.getByRole('checkbox', { name: checkbox, exact: true }));
|
|
}
|
|
await within(screen.getByRole('combobox', { name: '选择知识库' })).findByRole('option', { name: '已有资料' });
|
|
fireEvent.change(screen.getByRole('combobox', { name: '选择知识库' }), { target: { value: 'kb' } });
|
|
expect(changed).toHaveBeenLastCalledWith({
|
|
...initial, model: 'new-model', tools: ['tool'], skills: ['skill'], mcps: ['mcp'], knowledges: ['kb'],
|
|
});
|
|
expect(api.call.mock.calls.every(([operation]) => ['catalog', 'knowledge'].includes(operation))).toBe(true);
|
|
});
|