61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||
import { describe, expect, it, vi } from 'vitest';
|
||
import { AgentCreationDialog } from '@/components/coding/AgentCreationDialog';
|
||
import type { CodingProjectAgent } from '@/types/coding-project';
|
||
|
||
const agent: CodingProjectAgent = {
|
||
id: 'builder',
|
||
avatarId: 'avatar-01',
|
||
roleName: '实现者',
|
||
name: 'Builder',
|
||
builtIn: false,
|
||
enabled: true,
|
||
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
|
||
modelResolution: 'resolved',
|
||
skillIds: ['data-service'],
|
||
responsibility: {
|
||
mission: 'Implement changes', owns: [], boundaries: [], collaborators: [], principles: [],
|
||
},
|
||
prompt: '',
|
||
archivedAt: null,
|
||
pinned: false,
|
||
createdAt: '2026-08-27T00:00:00Z',
|
||
updatedAt: '2026-08-27T00:00:00Z',
|
||
};
|
||
|
||
describe('AgentCreationDialog plugin Skill availability', () => {
|
||
it('shows a retained disabled assignment as unavailable and persists it unchanged', async () => {
|
||
const onUpdate = vi.fn(async () => undefined);
|
||
render(<AgentCreationDialog
|
||
open
|
||
onOpenChange={vi.fn()}
|
||
agent={agent}
|
||
modelOptions={[{
|
||
key: JSON.stringify(['account-a', 'model-a']),
|
||
accountId: 'account-a',
|
||
modelId: 'model-a',
|
||
label: 'Account A / Model A',
|
||
availableThinkingLevels: null,
|
||
}]}
|
||
skills={[{
|
||
id: 'data-service',
|
||
name: 'Data Service',
|
||
description: 'Project data tools',
|
||
available: false,
|
||
effective: false,
|
||
}]}
|
||
onUpdate={onUpdate}
|
||
/>);
|
||
|
||
const checkbox = screen.getByRole('checkbox', { name: '绑定技能:Data Service' });
|
||
expect(checkbox).toBeChecked();
|
||
expect(checkbox).toBeDisabled();
|
||
expect(screen.getByText('插件未启用;现有分配会保留,但当前不可用。')).toBeVisible();
|
||
|
||
fireEvent.click(screen.getByRole('button', { name: '保存智能体' }));
|
||
await waitFor(() => expect(onUpdate).toHaveBeenCalledWith(
|
||
expect.objectContaining({ skillIds: ['data-service'] }),
|
||
));
|
||
});
|
||
});
|