diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts b/apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts index da5894660..e25984e5b 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts +++ b/apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts @@ -1040,8 +1040,8 @@ export function useUiEditorSession( setSavedStateSignature(snapshotSignature); } return true; - } catch (error) { - setSaveError(error instanceof Error ? error.message : String(error)); + } catch { + setSaveError('保存失败,请稍后重试。'); return false; } finally { setIsSaving(false); diff --git a/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts b/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts index 2bfe26d0f..667e030f0 100644 --- a/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts +++ b/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts @@ -549,6 +549,9 @@ describe('UiEditorPage', () => { fireEvent.click(await screen.findByRole('button', { name: '仍然保存' })); expect((await screen.findByRole('alert')).textContent).toContain( + '保存失败,请稍后重试。', + ); + expect(screen.getByRole('alert').textContent).not.toContain( '临时存储不可用', ); expect(screen.getByRole('button', { name: '保存' })).toBeTruthy(); @@ -558,4 +561,28 @@ describe('UiEditorPage', () => { fireEvent.click(await screen.findByRole('button', { name: '仍然保存' })); expect(stateStore.save).toHaveBeenCalledTimes(2); }); + + it('keeps the dedicated message for a save conflict', async () => { + const stateStore: UiDesignStateStore = { + load: vi.fn().mockResolvedValue(structuredClone(EMPTY_SNAPSHOT)), + save: vi.fn().mockResolvedValue({ + status: 'conflict', + currentRevision: 1, + }), + }; + render( + createElement(UiEditorPage, { + projectPath: '/tmp/ui-editor', + resourceId: 'ui-resource', + stateStore, + }), + ); + + fireEvent.click(await screen.findByRole('button', { name: '保存' })); + fireEvent.click(await screen.findByRole('button', { name: '仍然保存' })); + + expect((await screen.findByRole('alert')).textContent).toContain( + '资源已在别处更新;请重新加载后再保存。', + ); + }); });