Files
Genarrative/src/components/image-editor/ImageCanvasMetadataModalView.test.tsx
T
k88936 a03f13d0a5
Project CI / Repository checks (push) Successful in 1m28s
Project CI / Frontend tests (push) Successful in 3m19s
Project CI / Backend tests (push) Successful in 4m3s
Project CI / Native shell tests (push) Successful in 13m58s
Fix/动作 前端展示下载+后端数据结构+精选 的问题 (#117)
原问题

```
历史角色动作是一个兼容例外:
后端允许它没有 editor_project_resource 资源行,只要布局自身保存了完整图片序列帧。
```

- 把生成动作的原视频asstetkind改为 video, 只把图片序列作为action
- db asset新增字段image_sequence_frames_json image_seq_duration_ms等, (原来动作的这些数据存在generation-input中,并不合适)
修改了externaljob,把这部分数据正确填写到数据库中。
- 为避免到处fallback,做了数据库迁移, 脚本: `scripts/spacetime-normalize-editor-character-actions.mjs`   手动进行过画布+素材库中动作序列帧+原始视频 迁移的测试

- 移除preview_video_path字段,  reason:
>preview video
    → separate resource/asset with assetKind="video"
  final transparent action
    → assetKind="character-animation"
    → source_resource_id points to the preview-video resource
    → image_sequence_frames_json contains the actual playable result
>
> So preview_video_path on the final action duplicates the source video resource’s image_src.
- 移除每个frame的index字段 原因: 这个只用于后端内部处理时有一个并发请求, 每个赋一个index方便收集, 后续没有再用到,且与数组本身重复

- 清除副产品preview video的generation_input_json,  因为会影响改造功能, 迁移后预览视频不提供改造(参数), 只有序列帧动作有改造

仍存在的共性问题: #134

- 导出:
下载改为完整序列帧, 封面不再作为fallback, 部分帧读取失败时行为:仍生成 ZIP,并记录失败帧, 不变

画布放置:
before:
![shotmd-1785207959-compressed.webp](/attachments/e56454f0-49a3-4a8a-951f-c21960975f99)
after:
![shotmd-1785231365-compressed.webp](/attachments/886f07df-c25b-4ecc-acc9-160e1795a991)
精选模块: 主页展示, 审核部分UI:
![shotmd-1785500046-compressed.webp](/attachments/9ec3b679-0045-494a-9f20-134f7e73fecf)
![shotmd-1785499780-compressed.webp](/attachments/42396e63-5f26-4853-a367-0f3c15111add)
这两处序列帧们的加载设计为惰式的, 只有hover和单独preview才会全部加载

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/117
Reviewed-by: 段舒康 <kdletters@qq.com>
Co-authored-by: 王德宇 <kvtodev@outlook.com>
Co-committed-by: 王德宇 <kvtodev@outlook.com>
2026-08-06 16:57:38 +08:00

269 lines
9.0 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen, within } from '@testing-library/react';
import type { ComponentProps, ReactNode } from 'react';
import { describe, expect, it, vi } from 'vitest';
import { AuthUiContext } from '../auth/AuthUiContext';
import type { CanvasLayer } from './ImageCanvasEditorTypes';
import { ImageCanvasMetadataModalView } from './ImageCanvasMetadataModalView';
const DARK_AUTH_UI_VALUE = {
platformTheme: 'dark',
} as ComponentProps<typeof AuthUiContext.Provider>['value'];
function withDarkAuthUi(children: ReactNode) {
return (
<AuthUiContext.Provider value={DARK_AUTH_UI_VALUE}>
{children}
</AuthUiContext.Provider>
);
}
function createLayer(overrides: Partial<CanvasLayer> = {}): CanvasLayer {
return {
id: 'layer-1',
resourceId: 'resource-1',
title: '生成主图',
src: 'data:image/png;base64,layer',
x: 0,
y: 0,
width: 320,
height: 240,
originalWidth: 1024,
originalHeight: 768,
zIndex: 1,
sourceType: 'generated',
...overrides,
};
}
describe('ImageCanvasMetadataModalView', () => {
it('renders generated layer metadata with generation inputs and references', () => {
render(
withDarkAuthUi(
<ImageCanvasMetadataModalView
layer={createLayer({
model: 'gpt-image-2',
provider: 'VectorEngine',
taskId: 'gpt-image-2-task-123',
objectKey: 'generated/object.png',
generationInputs: {
fields: [{ title: '生成提示词', value: '清爽游戏按钮' }],
references: [
{
title: '参考图',
label: '角色立绘',
refType: 'project-resource',
refId: 'resource-reference',
},
],
},
})}
onClose={vi.fn()}
/>,
),
);
const dialog = screen.getByRole('dialog', { name: '图片信息' });
expect(dialog.parentElement?.className).toContain('platform-theme--light');
expect(dialog.parentElement?.className).not.toContain(
'platform-theme--dark',
);
expect(within(dialog).queryByText('生成主图')).toBeNull();
expect(within(dialog).getByText('生成图片')).toBeTruthy();
expect(within(dialog).getByText('生成提示词')).toBeTruthy();
expect(within(dialog).getByText('清爽游戏按钮')).toBeTruthy();
expect(within(dialog).getByText('参考图')).toBeTruthy();
expect(within(dialog).getByText('角色立绘')).toBeTruthy();
expect(
within(dialog).getByText('项目资源 · resource-reference'),
).toBeTruthy();
expect(within(dialog).getByText('Model')).toBeTruthy();
expect(within(dialog).getByText('gpt-image-2')).toBeTruthy();
expect(within(dialog).getByText('1024 x 768 px')).toBeTruthy();
expect(within(dialog).queryByText('Provider')).toBeNull();
expect(within(dialog).queryByText(/VectorEngine/u)).toBeNull();
expect(within(dialog).queryByText(/task-/u)).toBeNull();
expect(within(dialog).getByText('123')).toBeTruthy();
});
it('keeps the generation model while hiding internal processing models', () => {
const generationInputsWithInternalMattingMetadata = {
fields: [
{ title: '处理阶段', value: '角色抠图' },
{ title: '处理模型', value: 'birefnet' },
],
references: [],
mattingProvider: 'Aliyun Matting',
mattingModel: 'segment-common-image',
};
const { rerender } = render(
<ImageCanvasMetadataModalView
layer={createLayer({
model: 'gpt-image-2',
generationInputs: generationInputsWithInternalMattingMetadata,
})}
onClose={vi.fn()}
/>,
);
const dialog = screen.getByRole('dialog', { name: '图片信息' });
expect(within(dialog).getByText('处理阶段')).toBeTruthy();
expect(within(dialog).getByText('角色抠图')).toBeTruthy();
expect(within(dialog).queryByText('处理模型')).toBeNull();
expect(within(dialog).getByText('Model')).toBeTruthy();
expect(within(dialog).getByText('gpt-image-2')).toBeTruthy();
expect(within(dialog).queryByText('birefnet')).toBeNull();
expect(within(dialog).queryByText('Aliyun Matting')).toBeNull();
expect(within(dialog).queryByText('segment-common-image')).toBeNull();
rerender(
<ImageCanvasMetadataModalView
layer={createLayer({
model: 'birefnet',
generationInputs: {
fields: [{ title: '处理阶段', value: '角色抠图' }],
references: [],
},
})}
onClose={vi.fn()}
/>,
);
expect(within(dialog).getByText('Model')).toBeTruthy();
expect(within(dialog).queryByText('birefnet')).toBeNull();
});
it('renders nanobanana2 instead of the raw Gemini image model id', () => {
render(
<ImageCanvasMetadataModalView
layer={createLayer({
model: 'gemini-3.1-flash-image-preview',
})}
onClose={vi.fn()}
/>,
);
const dialog = screen.getByRole('dialog', { name: '图片信息' });
expect(within(dialog).getByText('nanobanana2')).toBeTruthy();
expect(
within(dialog).queryByText('gemini-3.1-flash-image-preview'),
).toBeNull();
});
it('renders upload fallback values and closes through the modal shell', () => {
const onClose = vi.fn();
render(
<ImageCanvasMetadataModalView
layer={createLayer({
title: '上传素材',
sourceType: 'uploaded',
model: null,
provider: null,
taskId: null,
objectKey: null,
assetObjectId: 'asset-object-1',
generationInputs: null,
})}
onClose={onClose}
/>,
);
const dialog = screen.getByRole('dialog', { name: '图片信息' });
expect(within(dialog).queryByText('上传素材')).toBeNull();
expect(within(dialog).getByText('上传图片')).toBeTruthy();
expect(within(dialog).getAllByText('-').length).toBeGreaterThanOrEqual(3);
fireEvent.click(
within(dialog).getByRole('button', { name: '关闭图片信息' }),
);
expect(onClose).toHaveBeenCalledTimes(1);
});
it('renders generated video metadata with video labels and close action', () => {
const onClose = vi.fn();
render(
<ImageCanvasMetadataModalView
layer={createLayer({
title: '生成视频 1',
src: '/generated-editor-videos/video-task-1/preview.mp4',
mediaType: 'video',
assetKind: 'video',
originalWidth: 1280,
originalHeight: 720,
model: 'kling3.0-omni',
taskId: 'video-task-1',
generationInputs: {
fields: [{ title: '视频描述', value: '让角色向镜头挥手' }],
references: [],
},
})}
onClose={onClose}
/>,
);
const dialog = screen.getByRole('dialog', { name: '视频信息' });
expect(within(dialog).getByText('视频类型')).toBeTruthy();
expect(within(dialog).getByText('生成视频')).toBeTruthy();
expect(within(dialog).getByText('视频描述')).toBeTruthy();
expect(within(dialog).getByText('让角色向镜头挥手')).toBeTruthy();
expect(within(dialog).getByText('kling3.0-omni')).toBeTruthy();
expect(within(dialog).getByText('1280 x 720 px')).toBeTruthy();
fireEvent.click(
within(dialog).getByRole('button', { name: '关闭视频信息' }),
);
expect(onClose).toHaveBeenCalledTimes(1);
});
it('renders audio duration from generation inputs instead of layer metadata', () => {
render(
<ImageCanvasMetadataModalView
layer={createLayer({
title: '游戏背景音乐',
src: '/generated-character-drafts/editor-audios/music.wav',
mediaType: 'audio',
assetKind: 'background-music',
originalWidth: 420,
originalHeight: 120,
model: 'suno',
taskId: 'audio-task-75',
generationInputs: {
fields: [
{ title: '音乐描述', value: '紧张的地下城循环音乐' },
{ title: '时长', value: '75秒' },
],
references: [],
},
})}
onClose={vi.fn()}
/>,
);
const dialog = screen.getByRole('dialog', { name: '音频信息' });
expect(within(dialog).getByText('音频类型')).toBeTruthy();
expect(within(dialog).getByText('游戏背景音乐')).toBeTruthy();
expect(within(dialog).getByText('音乐描述')).toBeTruthy();
expect(within(dialog).getByText('紧张的地下城循环音乐')).toBeTruthy();
expect(within(dialog).getByText('时长')).toBeTruthy();
expect(within(dialog).getByText('75秒')).toBeTruthy();
expect(within(dialog).queryByText('Resolution')).toBeNull();
expect(within(dialog).queryByText('420 x 120 px')).toBeNull();
});
it('does not render a dialog when no layer is selected', () => {
render(<ImageCanvasMetadataModalView layer={null} onClose={vi.fn()} />);
expect(screen.queryByRole('dialog', { name: '图片信息' })).toBeNull();
});
});