修复素材图层创建失败时误切换上传目录
将上传目录切换延后到素材图层构建成功之后。 构建失败时保持原目录并展示错误,补充回归测试。
This commit is contained in:
@@ -74,6 +74,7 @@ function AssetCanvasBridgeHarness({
|
||||
appendCanvasLayersWithResources = vi.fn(),
|
||||
captureCanvasHistory = vi.fn(),
|
||||
selectSingleLayer = vi.fn(),
|
||||
onAssetError = vi.fn(),
|
||||
}: {
|
||||
asset?: EditorAsset;
|
||||
resolveCanvasPoint?: (clientX: number, clientY: number) => {
|
||||
@@ -83,6 +84,7 @@ function AssetCanvasBridgeHarness({
|
||||
appendCanvasLayersWithResources?: (nextLayers: CanvasLayer[]) => void;
|
||||
captureCanvasHistory?: () => void;
|
||||
selectSingleLayer?: (layerId: string | null) => void;
|
||||
onAssetError?: (message: string) => void;
|
||||
}) {
|
||||
const assetPointerDragRef = useRef<AssetPointerDragState | null>({
|
||||
assetId: asset.id,
|
||||
@@ -128,6 +130,7 @@ function AssetCanvasBridgeHarness({
|
||||
appendCanvasLayersWithResources,
|
||||
selectSingleLayer,
|
||||
addUploadedFiles: vi.fn(),
|
||||
onAssetError,
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -224,6 +227,37 @@ describe('useImageCanvasAssetCanvasBridge', () => {
|
||||
expect(screen.getByTestId('hover').textContent).toBe('-');
|
||||
});
|
||||
|
||||
it('keeps the upload folder unchanged when layer creation fails', () => {
|
||||
const appendCanvasLayersWithResources = vi.fn();
|
||||
const captureCanvasHistory = vi.fn();
|
||||
const onAssetError = vi.fn();
|
||||
render(
|
||||
<AssetCanvasBridgeHarness
|
||||
asset={{
|
||||
...defaultAsset,
|
||||
folderId: 'characters',
|
||||
assetKind: 'character-animation',
|
||||
imageSequenceFrames: [],
|
||||
imageSequenceDurationMs: 1_000,
|
||||
}}
|
||||
appendCanvasLayersWithResources={appendCanvasLayersWithResources}
|
||||
captureCanvasHistory={captureCanvasHistory}
|
||||
onAssetError={onAssetError}
|
||||
/>,
|
||||
);
|
||||
|
||||
act(() => {
|
||||
screen.getByRole('button', { name: '添加到画布' }).click();
|
||||
});
|
||||
|
||||
expect(screen.getByTestId('folder').textContent).toBe('project');
|
||||
expect(onAssetError).toHaveBeenCalledWith(
|
||||
'角色动作素材“素材一”不完整:缺少可用序列帧。',
|
||||
);
|
||||
expect(captureCanvasHistory).not.toHaveBeenCalled();
|
||||
expect(appendCanvasLayersWithResources).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('delegates active pointer drops over the canvas into the layer path', () => {
|
||||
const appendCanvasLayersWithResources = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -156,7 +156,6 @@ export function useImageCanvasAssetCanvasBridge({
|
||||
}: UseImageCanvasAssetCanvasBridgeOptions) {
|
||||
const addAssetLayer = useCallback(
|
||||
(asset: EditorAsset, position?: CanvasPoint) => {
|
||||
setActiveUploadFolderId(asset.folderId);
|
||||
const nextLayerIndex = layerCounterRef.current + 1;
|
||||
let nextLayer: CanvasLayer;
|
||||
try {
|
||||
@@ -176,6 +175,7 @@ export function useImageCanvasAssetCanvasBridge({
|
||||
);
|
||||
return;
|
||||
}
|
||||
setActiveUploadFolderId(asset.folderId);
|
||||
layerCounterRef.current = nextLayerIndex;
|
||||
captureCanvasHistory({ type: 'add-image', count: 1 });
|
||||
appendCanvasLayersWithResources([nextLayer]);
|
||||
|
||||
Reference in New Issue
Block a user