diff --git a/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts b/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts index a133f480c..ebe0dd9ea 100644 --- a/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts +++ b/apps/ai-game-creator-shell/tests/uiEditorPage.test.ts @@ -873,6 +873,67 @@ describe('UiEditorPage', () => { expect(screen.getByRole('button', { name: '已复制' })).toBeTruthy(); }); + it('shows a save-success modal without a generated path', async () => { + const stateStore: IUiDesignStateStore = { + load: vi.fn().mockResolvedValue(structuredClone(EMPTY_SNAPSHOT)), + save: vi.fn().mockResolvedValue({ + status: 'saved', + state: structuredClone(EMPTY_SNAPSHOT.state), + revision: 1, + committedProjectRevision: 1, + }), + generateCode: vi.fn().mockRejectedValue(new Error('not requested')), + }; + + 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: '仍然保存' })); + + const dialog = await screen.findByRole('dialog'); + expect(dialog.textContent).toContain('保存成功'); + expect(dialog.textContent).not.toContain('生成文件路径'); + }); + + it('reports partial success when saving succeeds but generation fails', async () => { + const stateStore: IUiDesignStateStore = { + load: vi.fn().mockResolvedValue(structuredClone(EMPTY_SNAPSHOT)), + save: vi.fn().mockResolvedValue({ + status: 'saved', + state: structuredClone(EMPTY_SNAPSHOT.state), + revision: 1, + committedProjectRevision: 1, + }), + generateCode: vi.fn().mockRejectedValue(new Error('生成服务不可用')), + }; + + 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: '仍然保存并生成' }), + ); + + const dialog = await screen.findByRole('dialog'); + expect(dialog.textContent).toContain('项目已保存,但代码生成失败'); + expect(dialog.textContent).toContain('生成服务不可用'); + expect(screen.getByRole('button', { name: '重试保存并生成' })).toBeTruthy(); + }); + it('shows a manual-copy hint when the native clipboard rejects a path', async () => { const stateStore: IUiDesignStateStore = { load: vi.fn().mockResolvedValue(structuredClone(EMPTY_SNAPSHOT)),