test: 为utils/file添加测试用例
- 容量进制转换 - 文件拓展名获取与格式化
This commit is contained in:
36
tests/unit/utils/file.test.ts
Normal file
36
tests/unit/utils/file.test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import {
|
||||
formatFileSize,
|
||||
getFileExtension,
|
||||
formatFileExtension,
|
||||
} from '../../../app/utils/file';
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
/**
|
||||
* 单元测试: formatFileSize
|
||||
*/
|
||||
test('formatFileSize - format bytes correctly', () => {
|
||||
expect(formatFileSize(500)).toBe('500.00 B');
|
||||
});
|
||||
test('formatFileSize - format kilobytes correctly', () => {
|
||||
expect(formatFileSize(2048)).toBe('2.00 KB');
|
||||
});
|
||||
test('formatFileSize - format megabytes correctly', () => {
|
||||
expect(formatFileSize(5 * 1024 * 1024)).toBe('5.00 MB');
|
||||
});
|
||||
|
||||
/**
|
||||
* 单元测试: getFileExtension, formatFileExtension
|
||||
*/
|
||||
test('getFileExtension - extract extension from filename', () => {
|
||||
expect(getFileExtension('document.pdf')).toBe('pdf');
|
||||
});
|
||||
test('getFileExtension - handle filenames without extension', () => {
|
||||
expect(getFileExtension('README')).toBe('');
|
||||
});
|
||||
|
||||
test('formatFileExtension - format extension without dot', () => {
|
||||
expect(formatFileExtension('txt')).toBe('TXT');
|
||||
});
|
||||
test('formatFileExtension - format extension with dot', () => {
|
||||
expect(formatFileExtension('.jpg')).toBe('JPG');
|
||||
});
|
||||
Reference in New Issue
Block a user