完善 UI 编辑器结果弹窗覆盖
增加普通保存成功与保存后生成失败的场景断言 验证路径弹窗和失败重试按钮的可见行为
This commit is contained in:
@@ -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)),
|
||||
|
||||
Reference in New Issue
Block a user