Files
Genarrative/apps/ai-game-creator-shell/tests/uiDesignResourceBridge.test.ts
T
k88936 594063a1e0 测试:修正 AGC 测试文件的类型错误
- 按 vitest 0.34 的参数元组口径改写 mock 泛型
- 修正 noUncheckedIndexedAccess 下的下标访问
- 补齐与当前类型脱节的测试桩字段
- 按 scripts/*.mjs 的运行时契约补局部类型声明
2026-10-03 17:41:30 +08:00

52 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it, vi } from 'vitest';
import {
createUiDesignDocFromImages,
type UiDesignDocImageReference,
} from '../src/features/ui-editor/uiDesignResourceBridge';
describe('ui design resource bridge', () => {
it('rejects an empty image list without invoking the command', async () => {
const invoke = vi.fn();
await expect(
createUiDesignDocFromImages({
projectPath: '/project',
expectedProjectId: 'project-1',
images: [],
invoke,
}),
).rejects.toThrow('请至少选择一张界面图');
expect(invoke).not.toHaveBeenCalled();
});
it('creates a document through the command with the project identity injected', async () => {
const created = {
asset: { id: 'ui-1' },
manifest: { projectId: 'project-1' },
relativePath: 'ui/UI 设计 1.json',
imageIds: ['image-a'],
committedProjectRevision: 7,
};
const invoke = vi.fn().mockResolvedValue(created);
// 真实类型用「省略 path」表达没有路径,而本用例的调用断言固定了 `path: null`;
// 结构上无法用该联合类型表达,只能断言收敛,运行时载荷原样保留。
const images = [
{ assetId: 'image-a', path: null },
] as unknown as UiDesignDocImageReference[];
const result = await createUiDesignDocFromImages({
projectPath: '/project',
expectedProjectId: 'project-1',
images,
invoke,
});
expect(invoke).toHaveBeenCalledWith('create_ui_design_doc_from_images', {
input: {
projectPath: '/project',
expectedProjectId: 'project-1',
images: [{ assetId: 'image-a', path: null }],
},
});
expect(result).toBe(created);
});
});