mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
重构(应用状态存储): 调整savePaths返回结构化结果并更新所有调用处
- 新增SaveResult类型统一标准化保存操作的结果状态 - 修改savePaths函数返回结构化结果而非布尔值,完善长路径超限、部分失败等场景的处理逻辑,部分失败时重新加载路径避免状态偏移 - 更新useAppActions与ProfileDialog的保存逻辑,适配新API并添加长路径确认弹窗 - 补充相关测试用例,修正导入导出测试的版本号预期
This commit is contained in:
@@ -239,19 +239,26 @@ describe('savePaths', () => {
|
||||
|
||||
it('保存成功', async () => {
|
||||
mockedInvoke.mockResolvedValue(undefined);
|
||||
await useAppStore.getState().savePaths();
|
||||
const result = await useAppStore.getState().savePaths();
|
||||
expect(result).toEqual({ kind: 'success' });
|
||||
const s = useAppStore.getState();
|
||||
expect(s.isSaving).toBe(false);
|
||||
expect(s.isModified).toBe(false);
|
||||
expect(s.statusMessage).toBe('保存成功');
|
||||
});
|
||||
|
||||
it('部分失败时报告具体 hive', async () => {
|
||||
it('部分失败时报告具体 hive 并回读', async () => {
|
||||
mockedInvoke
|
||||
.mockResolvedValueOnce(undefined) // backup_registry
|
||||
.mockResolvedValueOnce(undefined) // save_system_paths
|
||||
.mockRejectedValueOnce('权限不足'); // save_user_paths
|
||||
await useAppStore.getState().savePaths();
|
||||
.mockRejectedValueOnce('权限不足') // save_user_paths
|
||||
// 以下为 partial 触发的 loadPaths 调用
|
||||
.mockResolvedValueOnce(['A']) // load_system_paths
|
||||
.mockResolvedValueOnce(['B']) // load_user_paths
|
||||
.mockResolvedValueOnce([[], []]); // load_disabled_state
|
||||
|
||||
const result = await useAppStore.getState().savePaths();
|
||||
expect(result.kind).toBe('partial');
|
||||
const s = useAppStore.getState();
|
||||
expect(s.isSaving).toBe(false);
|
||||
expect(s.statusMessage).toContain('用户 PATH 保存失败');
|
||||
@@ -268,8 +275,8 @@ describe('savePaths', () => {
|
||||
// 第二次调用应被 isSaving 守卫拦截(此时 isSaving=true)
|
||||
const r2 = useAppStore.getState().savePaths();
|
||||
|
||||
// 第二次调用同步返回 false(被守卫拦截)
|
||||
await expect(r2).resolves.toBe(false);
|
||||
// 第二次调用同步返回 blocked(被守卫拦截)
|
||||
await expect(r2).resolves.toEqual({ kind: 'blocked' });
|
||||
|
||||
// 放行第一次调用的所有 invoke
|
||||
resolveAll!(undefined);
|
||||
|
||||
Reference in New Issue
Block a user