Files
PathEditor/tests/unit/path-manager.test.ts
T
Serendipity 914b25f236 test: 所有测试适配 PathEntry[] 类型,新增 TOGGLE undo/redo 测试
- undo-redo.test.ts: 所有 11 项测试通过(含新增 TOGGLE 撤销/重做)
- app-store.test.ts: 断言改用 .map(e => e.path),待 Task 5 修复
- import-export.test.ts: sampleData 改用 pe(),导出断言适配
- path-manager.test.ts: 测试数据用 pe() 包裹,待 Task 3 修复
- validation.test.ts: 无需变更(纯 string 接口)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 13:42:21 +08:00

37 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { pathClean } from '../../src/core/path-manager';
import type { PathEntry } from '../../src/core/path-entry';
function pe(s: string, enabled: boolean = true): PathEntry {
return { path: s, enabled };
}
const alwaysValid = () => true;
const validateFn = (path: string) => !path.includes('Invalid');
describe('pathClean', () => {
it('移除无效路径', () => {
const [kept, removed] = pathClean([pe('C:\\Valid'), pe('C:\\Invalid'), pe('D:\\Valid')], validateFn as any);
expect(kept.map(e => e.path)).toEqual(['C:\\Valid', 'D:\\Valid']);
expect(removed.map(e => e.path)).toEqual(['C:\\Invalid']);
});
it('移除重复路径保留第一个', () => {
const [kept, removed] = pathClean([pe('C:\\Valid'), pe('C:\\Valid'), pe('D:\\Valid')], alwaysValid as any);
expect(kept.length).toBe(2);
expect(removed.length).toBe(1);
});
it('全部有效无变化', () => {
const [kept, removed] = pathClean([pe('C:\\a'), pe('D:\\b')], alwaysValid as any);
expect(kept.map(e => e.path)).toEqual(['C:\\a', 'D:\\b']);
expect(removed.length).toBe(0);
});
it('全部无效全部移除', () => {
const [kept, removed] = pathClean([pe('C:\\Invalid1'), pe('C:\\Invalid2')], validateFn as any);
expect(kept.length).toBe(0);
expect(removed.length).toBe(2);
});
});