mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-28 17:25:54 +08:00
60de924b08
- 前端引入@tanstack/react-virtual虚拟列表库,重构PathTable与MergePreview组件,优化大量路径条目下的渲染性能 - 为后端注册表保存接口添加原始路径比对逻辑,防止并发修改导致的配置覆盖,同步更新前端保存逻辑传递原始路径参数 - 替换core模块手动编写的Windows API FFI声明为windows-sys官方库,简化代码维护 - 完善单元测试,新增空数组处理、边界场景的测试用例 - 更新项目依赖与锁定文件,将版本升级至v5.1.0 - 新增项目代码架构审查文档
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { render } from '@testing-library/react';
|
|
import { MergePreview } from '../../src/components/path-list/MergePreview';
|
|
|
|
vi.mock('@/store/app-store', () => ({
|
|
useAppStore: vi.fn((selector) => {
|
|
const state = {
|
|
sysPaths: [
|
|
{ path: 'C:\\Windows', enabled: true },
|
|
{ path: 'C:\\Disabled', enabled: false },
|
|
],
|
|
userPaths: [
|
|
{ path: 'D:\\UserApp', enabled: true },
|
|
],
|
|
searchQuery: '',
|
|
};
|
|
return selector(state);
|
|
}),
|
|
}));
|
|
|
|
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) },
|
|
}));
|
|
|
|
describe('MergePreview', () => {
|
|
it('合并显示系统+用户路径', () => {
|
|
const { container } = render(<MergePreview />);
|
|
const text = container.textContent || '';
|
|
expect(text).toContain('C:\\Windows');
|
|
expect(text).toContain('D:\\UserApp');
|
|
});
|
|
|
|
it('disabled 路径在表格中存在', () => {
|
|
const { container } = render(<MergePreview />);
|
|
const text = container.textContent || '';
|
|
expect(text).toContain('C:\\Disabled');
|
|
});
|
|
});
|