From 17fcbc19df571b47416484ed85d725e164336f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 4 Aug 2026 10:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B4=A0=E6=9D=90=E5=9B=BE?= =?UTF-8?q?=E5=B1=82=E5=88=9B=E5=BB=BA=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=AF=AF?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=8A=E4=BC=A0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将上传目录切换延后到素材图层构建成功之后。 构建失败时保持原目录并展示错误,补充回归测试。 --- .../useImageCanvasAssetCanvasBridge.test.tsx | 34 +++++++++++++++++++ .../useImageCanvasAssetCanvasBridge.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx b/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx index b1d3465cf..78815cf89 100644 --- a/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx +++ b/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx @@ -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({ 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( + , + ); + + 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( diff --git a/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts b/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts index a3ada2954..b4fc4d1e0 100644 --- a/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts +++ b/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts @@ -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]);