fix(design): distinguish saved video settings from preparation needs

This commit is contained in:
2026-09-27 16:32:38 +08:00
parent 0eed70fa63
commit bbea6eba82
6 changed files with 203 additions and 28 deletions

View File

@@ -73,19 +73,25 @@ beforeEach(() => {
});
afterEach(cleanup);
it('reaches video confirmation through the real prepare-generation bridge', async () => {
it.each(['image', 'incomplete-video'])('reaches video confirmation from %s through the real prepare-generation bridge', async (start) => {
const incompleteVideo = start === 'incomplete-video';
const initial = serverStep(null, 'direct_edit', [
{ kind: 'set', path: 'intent.media', value: 'image' },
{ kind: 'set', path: 'intent.media', value: incompleteVideo ? 'video' : 'image' },
{ kind: 'set', path: 'content.concept', value: '沙漠里的小动物围圈玩游戏,天上的云在飘。' },
{ kind: 'set', path: 'output.aspect_ratio', value: '9:16' },
...(incompleteVideo ? [
{ kind: 'set', path: 'video.first_frame_asset_id', value: 'image-1' },
{ kind: 'set', path: 'references', value: [{ id: 'start', asset_id: 'image-1', role: 'first_frame' }] },
] satisfies DesignUserFieldOperation[] : []),
]);
let workspace = designWorkspaceFixture({ form: designFormFixture({
specification: initial.specification, activeQuotes: [],
}) });
}), assets: incompleteVideo ? [asset] : [] });
const commands: string[] = [];
expect(initial.ready).toBe(true);
expect(initial.ready).toBe(!incompleteVideo);
useImageWorkspaceStore.setState({
workspace, activeWorkspaceId: workspace.workspace.workspaceId, status: 'ready',
quoteBlockers: initial.blockers,
});
vi.mocked(uploadImageWorkspaceAsset).mockResolvedValue(asset);
vi.mocked(submitImageWorkspaceCommand).mockImplementation(async (command) => {
@@ -118,20 +124,34 @@ it('reaches video confirmation through the real prepare-generation bridge', asyn
return { workspace, runId: 'offline-run', clientOperationId: command.clientOperationId };
});
render(<LiveCard />);
fireEvent.change(screen.getByRole('combobox', { name: '类型' }), { target: { value: 'video' } });
await waitFor(() => expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.intent.media).toBe('video'));
fireEvent.change(screen.getByLabelText('选择参考图片'), {
target: { files: [new File(['offline-upload'], 'start.png', { type: 'image/png' })] },
});
await screen.findByText('已选用');
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.first_frame_asset_id).toBe('image-1');
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.shots.length).toBe(1);
if (incompleteVideo) {
expect(initial.blockers.map((issue) => issue.code)).toEqual(expect.arrayContaining([
'video_duration_required', 'video_shots_required',
]));
expect(screen.getByRole('combobox', { name: '时长' })).toHaveValue('');
expect(screen.getByRole('button', { name: '准备制作方案' })).toBeDisabled();
expect(screen.queryByText('至少写一个视频画面。')).not.toBeInTheDocument();
fireEvent.change(screen.getByRole('combobox', { name: '时长' }), { target: { value: '6' } });
await waitFor(() => expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.total_duration_seconds).toBe(6));
await waitFor(() => expect(screen.queryByText('先选择视频时长。')).not.toBeInTheDocument());
} else {
fireEvent.change(screen.getByRole('combobox', { name: '类型' }), { target: { value: 'video' } });
await waitFor(() => expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.intent.media).toBe('video'));
fireEvent.change(screen.getByLabelText('选择参考图片'), {
target: { files: [new File(['offline-upload'], 'start.png', { type: 'image/png' })] },
});
await screen.findByText('已选用');
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.first_frame_asset_id).toBe('image-1');
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.shots.length).toBe(1);
}
await waitFor(() => expect(screen.getByRole('button', { name: '准备制作方案' })).toBeEnabled());
fireEvent.click(screen.getByRole('button', { name: '准备制作方案' }));
await waitFor(() => expect(commands).toContain('request_quote'));
console.log('FLOW_COMMANDS', commands);
console.log('FLOW_BLOCKERS', useImageWorkspaceStore.getState().quoteBlockers.map((item) => item.code));
expect(commands.filter((kind) => kind === 'prepare_generation')).toHaveLength(3);
expect(commands.filter((kind) => kind === 'prepare_generation')).toHaveLength(incompleteVideo ? 1 : 3);
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.shots.length).toBe(1);
expect(useImageWorkspaceStore.getState().workspace?.form.specification.values.video.total_duration_seconds).toBe(6);
expect(useImageWorkspaceStore.getState().quoteBlockers).toEqual([]);
expect(screen.getByRole('button', { name: '确认并开始制作' })).toBeEnabled();
fireEvent.click(screen.getByRole('button', { name: '确认并开始制作' }));