57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
import {
|
|
cleanup,
|
|
fireEvent,
|
|
render,
|
|
screen,
|
|
waitFor,
|
|
} from '@testing-library/react';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
|
|
import { getAgcModelCatalog, saveAgcModelCatalog } from '../api/adminApiClient';
|
|
import { AdminAgcModelsPage } from './AdminAgcModelsPage';
|
|
|
|
vi.mock('../api/adminApiClient', () => ({
|
|
getAgcModelCatalog: vi.fn(),
|
|
saveAgcModelCatalog: vi.fn(),
|
|
isAdminApiError: vi.fn(() => false),
|
|
formatAdminApiError: vi.fn(() => '保存失败'),
|
|
}));
|
|
vi.mock('../components/useAdminWriteConfirm', () => ({
|
|
useAdminWriteConfirm: () => ({
|
|
confirmWrite: async () => true,
|
|
confirmDialog: null,
|
|
}),
|
|
}));
|
|
afterEach(cleanup);
|
|
|
|
test('edits alias and upstream model without changing the stable identifier or revision', async () => {
|
|
const catalog = {
|
|
revision: 3,
|
|
defaultModelId: 'quality',
|
|
models: [
|
|
{ id: 'quality', alias: '高质量', modelId: 'gpt-6-astra', enabled: true },
|
|
],
|
|
};
|
|
vi.mocked(getAgcModelCatalog).mockResolvedValue(catalog);
|
|
vi.mocked(saveAgcModelCatalog).mockImplementation(async (_, input) => ({
|
|
...input,
|
|
revision: 4,
|
|
}));
|
|
render(<AdminAgcModelsPage token="test" onUnauthorized={vi.fn()} />);
|
|
await screen.findByDisplayValue('gpt-6-astra');
|
|
fireEvent.change(screen.getByLabelText('模型 1 别名'), {
|
|
target: { value: '精细创作' },
|
|
});
|
|
fireEvent.click(screen.getByRole('button', { name: '保存' }));
|
|
await waitFor(() =>
|
|
expect(saveAgcModelCatalog).toHaveBeenCalledWith('test', {
|
|
...catalog,
|
|
models: [{ ...catalog.models[0], alias: '精细创作' }],
|
|
}),
|
|
);
|
|
await waitFor(() => {
|
|
expect(screen.getAllByText('已保存').length).toBeGreaterThanOrEqual(2);
|
|
});
|
|
});
|