镜像自地址
https://github.com/lhly/cloud-drive-renamer.git
已同步 2026-10-20 21:57:47 +08:00
添加了包括单元测试、集成测试和性能测试在内的全面测试套件,覆盖核心功能如批量重命名、崩溃恢复、冲突检测等。测试文件包括: 1. 单元测试:helpers、rules、storage、retry等核心模块 2. 集成测试:批量执行流程与网络恢复场景 3. 性能测试:100文件处理时间、内存占用等指标 4. E2E测试:扩展加载、批量重命名完整流程 所有测试遵循vitest和playwright规范,确保功能稳定性和性能达标
68 行
2.1 KiB
TypeScript
68 行
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { parseFileName, validateFileName, sanitizeFileName, formatTime } from '../../src/utils/helpers';
|
|
|
|
describe('helpers', () => {
|
|
describe('parseFileName', () => {
|
|
it('should parse file name with extension', () => {
|
|
const result = parseFileName('video.mp4');
|
|
expect(result).toEqual({ name: 'video', ext: '.mp4' });
|
|
});
|
|
|
|
it('should handle file name without extension', () => {
|
|
const result = parseFileName('README');
|
|
expect(result).toEqual({ name: 'README', ext: '' });
|
|
});
|
|
|
|
it('should handle file name with multiple dots', () => {
|
|
const result = parseFileName('archive.tar.gz');
|
|
expect(result).toEqual({ name: 'archive.tar', ext: '.gz' });
|
|
});
|
|
|
|
it('should handle hidden files', () => {
|
|
const result = parseFileName('.gitignore');
|
|
expect(result).toEqual({ name: '.gitignore', ext: '' });
|
|
});
|
|
});
|
|
|
|
describe('validateFileName', () => {
|
|
it('should validate legal file name', () => {
|
|
const result = validateFileName('normal_file-name.txt');
|
|
expect(result.valid).toBe(true);
|
|
expect(result.illegalChars).toBeUndefined();
|
|
});
|
|
|
|
it('should detect illegal characters', () => {
|
|
const result = validateFileName('file:name?.txt');
|
|
expect(result.valid).toBe(false);
|
|
expect(result.illegalChars).toEqual([':', '?']);
|
|
expect(result.sanitized).toBe('file_name_.txt');
|
|
});
|
|
});
|
|
|
|
describe('sanitizeFileName', () => {
|
|
it('should remove illegal characters', () => {
|
|
const result = sanitizeFileName('file<>:"/\\|?*.txt');
|
|
expect(result).toBe('file_________.txt');
|
|
});
|
|
|
|
it('should trim extra spaces', () => {
|
|
const result = sanitizeFileName(' file name .txt ');
|
|
expect(result).toBe('file name .txt');
|
|
});
|
|
});
|
|
|
|
describe('formatTime', () => {
|
|
it('should format seconds', () => {
|
|
expect(formatTime(30000)).toBe('30秒');
|
|
});
|
|
|
|
it('should format minutes', () => {
|
|
expect(formatTime(120000)).toBe('2分0秒');
|
|
});
|
|
|
|
it('should format hours', () => {
|
|
expect(formatTime(3660000)).toBe('1小时1分');
|
|
});
|
|
});
|
|
});
|