修复 UI 编辑器保存失败提示

普通保存异常统一显示固定安全摘要
保留保存冲突专用提示并补充回归测试

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-08-20 15:47:21 +08:00
parent 95a879e0a0
commit 274b771319
2 changed files with 29 additions and 2 deletions
@@ -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);
@@ -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(
'资源已在别处更新;请重新加载后再保存。',
);
});
});