mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:37:22 +08:00
test: 修复所有测试适配 PathEntry,全部通过
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -234,7 +234,7 @@ describe('savePaths', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
resetStore();
|
||||
useAppStore.setState({ sysPaths: ['A'], userPaths: ['B'] });
|
||||
useAppStore.setState({ sysPaths: [pe('A')], userPaths: [pe('B')] });
|
||||
});
|
||||
|
||||
it('保存成功', async () => {
|
||||
|
||||
@@ -22,10 +22,7 @@ const sampleData = {
|
||||
|
||||
describe('exportToJson', () => {
|
||||
it('导出结构化 JSON', () => {
|
||||
const json = exportToJson({
|
||||
system: sampleData.system.map(e => e.path),
|
||||
user: sampleData.user.map(e => e.path),
|
||||
});
|
||||
const json = exportToJson(sampleData);
|
||||
const parsed = JSON.parse(json);
|
||||
expect(parsed.version).toBe('1.0');
|
||||
expect(parsed.type).toBe('PathEditor');
|
||||
@@ -42,23 +39,20 @@ describe('importFromJson', () => {
|
||||
user: sampleData.user.map(e => e.path),
|
||||
});
|
||||
const result = importFromJson(json);
|
||||
expect(result.system).toEqual(sampleData.system.map(e => e.path));
|
||||
expect(result.user).toEqual(sampleData.user.map(e => e.path));
|
||||
expect(result.system).toEqual(sampleData.system);
|
||||
expect(result.user).toEqual(sampleData.user);
|
||||
});
|
||||
|
||||
it('过滤空字符串', () => {
|
||||
const json = JSON.stringify({ system: ['C:\\', '', ' '], user: [] });
|
||||
const result = importFromJson(json);
|
||||
expect(result.system).toEqual(['C:\\']);
|
||||
expect(result.system).toEqual([pe('C:\\')]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exportToCsv', () => {
|
||||
it('导出 CSV 含 BOM', () => {
|
||||
const csv = exportToCsv({
|
||||
system: sampleData.system.map(e => e.path),
|
||||
user: sampleData.user.map(e => e.path),
|
||||
});
|
||||
const csv = exportToCsv(sampleData);
|
||||
expect(csv.startsWith('')).toBe(true);
|
||||
expect(csv).toContain('type,path');
|
||||
expect(csv).toContain('system,C:\\Windows');
|
||||
@@ -66,13 +60,13 @@ describe('exportToCsv', () => {
|
||||
});
|
||||
|
||||
it('CSV 字段转义', () => {
|
||||
const data = { system: ['C:\\Path,with,commas'], user: [] };
|
||||
const data = { system: [pe('C:\\Path,with,commas')], user: [] };
|
||||
const csv = exportToCsv(data);
|
||||
expect(csv).toContain('"C:\\Path,with,commas"');
|
||||
});
|
||||
|
||||
it('CSV 双引号转义', () => {
|
||||
const data = { system: ['Path with "quotes"'], user: [] };
|
||||
const data = { system: [pe('Path with "quotes"')], user: [] };
|
||||
const csv = exportToCsv(data);
|
||||
expect(csv).toContain('"Path with ""quotes"""');
|
||||
});
|
||||
@@ -82,8 +76,8 @@ describe('importFromCsv', () => {
|
||||
it('正确导入 CSV', () => {
|
||||
const csv = 'type,path\nsystem,C:\\Windows\nuser,C:\\AppData\n';
|
||||
const result = importFromCsv(csv);
|
||||
expect(result.system).toEqual(['C:\\Windows']);
|
||||
expect(result.user).toEqual(['C:\\AppData']);
|
||||
expect(result.system).toEqual([pe('C:\\Windows')]);
|
||||
expect(result.user).toEqual([pe('C:\\AppData')]);
|
||||
});
|
||||
|
||||
it('跳过未知类型', () => {
|
||||
@@ -96,7 +90,7 @@ describe('importFromCsv', () => {
|
||||
it('处理带引号的 CSV 字段', () => {
|
||||
const csv = 'type,path\nsystem,"C:\\Path,With,Commas"';
|
||||
const result = importFromCsv(csv);
|
||||
expect(result.system).toEqual(['C:\\Path,With,Commas']);
|
||||
expect(result.system).toEqual([pe('C:\\Path,With,Commas')]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,13 +98,13 @@ describe('importFromTxt', () => {
|
||||
it('逐行导入,跳过注释和空行', () => {
|
||||
const txt = '# 这是注释\nC:\\Windows\n\nD:\\Projects\n# 另一个注释';
|
||||
const paths = importFromTxt(txt);
|
||||
expect(paths).toEqual(['C:\\Windows', 'D:\\Projects']);
|
||||
expect(paths).toEqual([pe('C:\\Windows'), pe('D:\\Projects')]);
|
||||
});
|
||||
|
||||
it('跳过 BOM', () => {
|
||||
const txt = 'C:\\Windows';
|
||||
const paths = importFromTxt(txt);
|
||||
expect(paths).toEqual(['C:\\Windows']);
|
||||
expect(paths).toEqual([pe('C:\\Windows')]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -120,9 +114,9 @@ describe('importFromContent', () => {
|
||||
const jsonContent = JSON.stringify({ system: ['C:\\Test'], user: [] });
|
||||
const txtContent = 'C:\\Test';
|
||||
|
||||
expect(importFromContent(csvContent, 'test.csv').system).toEqual(['C:\\Test']);
|
||||
expect(importFromContent(jsonContent, 'test.json').system).toEqual(['C:\\Test']);
|
||||
expect(importFromContent(txtContent, 'test.txt').system).toEqual(['C:\\Test']);
|
||||
expect(importFromContent(csvContent, 'test.csv').system).toEqual([pe('C:\\Test')]);
|
||||
expect(importFromContent(jsonContent, 'test.json').system).toEqual([pe('C:\\Test')]);
|
||||
expect(importFromContent(txtContent, 'test.txt').system).toEqual([pe('C:\\Test')]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -139,23 +133,23 @@ describe('detectExportFormat', () => {
|
||||
});
|
||||
|
||||
describe('flattenImportResult', () => {
|
||||
const data = { system: ['S1'], user: ['U1'] };
|
||||
const data = { system: [pe('S1')], user: [pe('U1')] };
|
||||
|
||||
it('仅系统', () => {
|
||||
const r = flattenImportResult(data, 'system');
|
||||
expect(r.system).toEqual(['S1']);
|
||||
expect(r.system).toEqual([pe('S1')]);
|
||||
expect(r.user).toEqual([]);
|
||||
});
|
||||
|
||||
it('仅用户', () => {
|
||||
const r = flattenImportResult(data, 'user');
|
||||
expect(r.system).toEqual([]);
|
||||
expect(r.user).toEqual(['U1']);
|
||||
expect(r.user).toEqual([pe('U1')]);
|
||||
});
|
||||
|
||||
it('两者都导入', () => {
|
||||
const r = flattenImportResult(data, 'both');
|
||||
expect(r.system).toEqual(['S1']);
|
||||
expect(r.user).toEqual(['U1']);
|
||||
expect(r.system).toEqual([pe('S1')]);
|
||||
expect(r.user).toEqual([pe('U1')]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user