mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
build, fix, feat, refactor: 优化长列表性能,新增注册表并发校验,升级v5.1.0
- 前端引入@tanstack/react-virtual虚拟列表库,重构PathTable与MergePreview组件,优化大量路径条目下的渲染性能 - 为后端注册表保存接口添加原始路径比对逻辑,防止并发修改导致的配置覆盖,同步更新前端保存逻辑传递原始路径参数 - 替换core模块手动编写的Windows API FFI声明为windows-sys官方库,简化代码维护 - 完善单元测试,新增空数组处理、边界场景的测试用例 - 更新项目依赖与锁定文件,将版本升级至v5.1.0 - 新增项目代码架构审查文档
This commit is contained in:
@@ -18,6 +18,21 @@ vi.mock('@/store/app-store', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@tanstack/react-virtual', () => ({
|
||||
useVirtualizer: (options: any) => ({
|
||||
getVirtualItems: () => {
|
||||
// return an array of objects to mock virtual items
|
||||
return Array.from({ length: options.count }).map((_, index) => ({
|
||||
index,
|
||||
start: index * 28,
|
||||
size: 28,
|
||||
key: `mock-key-${index}`,
|
||||
}));
|
||||
},
|
||||
getTotalSize: () => options.count * 28,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@/i18n', () => ({
|
||||
default: { t: vi.fn((key: string) => key) },
|
||||
}));
|
||||
|
||||
@@ -47,12 +47,25 @@ describe('pathClean', () => {
|
||||
expect(removed.length).toBe(1);
|
||||
});
|
||||
|
||||
it('保留第一个出现的 enabled 状态', () => {
|
||||
const [kept, removed] = pathClean([pe('C:\\Valid', false), pe('C:\\Valid', true)], alwaysValid);
|
||||
expect(kept.length).toBe(1);
|
||||
expect(kept[0].enabled).toBe(false); // 第一个状态
|
||||
expect(removed.length).toBe(1);
|
||||
});
|
||||
|
||||
it('全部有效无变化', () => {
|
||||
const [kept, removed] = pathClean([pe('C:\\a'), pe('D:\\b')], alwaysValid);
|
||||
expect(kept.map(e => e.path)).toEqual(['C:\\a', 'D:\\b']);
|
||||
expect(removed.length).toBe(0);
|
||||
});
|
||||
|
||||
it('空数组处理', () => {
|
||||
const [kept, removed] = pathClean([], alwaysValid);
|
||||
expect(kept.length).toBe(0);
|
||||
expect(removed.length).toBe(0);
|
||||
});
|
||||
|
||||
it('全部无效全部移除', () => {
|
||||
const [kept, removed] = pathClean([pe('C:\\Invalid1'), pe('C:\\Invalid2')], validateFn);
|
||||
expect(kept.length).toBe(0);
|
||||
|
||||
@@ -125,6 +125,26 @@ describe('UndoRedoManager', () => {
|
||||
expect(mgr.canRedo()).toBe(false);
|
||||
});
|
||||
|
||||
it('空历史栈的撤销与重做', () => {
|
||||
expect(mgr.undo(sys, user)).toBeNull();
|
||||
expect(mgr.redo(sys, user)).toBeNull();
|
||||
});
|
||||
|
||||
it('超出栈底/栈顶的安全处理', () => {
|
||||
mgr.push(makeRecord(OperationType.ADD, TargetType.SYSTEM, 2, 1, [], [pe('C:\\NewPath')]));
|
||||
sys.push(pe('C:\\NewPath'));
|
||||
|
||||
// undo一次
|
||||
mgr.undo(sys, user);
|
||||
// 再次undo,此时应到达底部返回null
|
||||
expect(mgr.undo(sys, user)).toBeNull();
|
||||
|
||||
// redo一次
|
||||
mgr.redo(sys, user);
|
||||
// 再次redo,应到达顶部返回null
|
||||
expect(mgr.redo(sys, user)).toBeNull();
|
||||
});
|
||||
|
||||
it('超出最大历史容量时移除最旧记录', () => {
|
||||
const small = new UndoRedoManager(3);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
|
||||
Reference in New Issue
Block a user