v0.2.0: 全面代码质量优化

- ESLint flat config + Prettier + EditorConfig
- Markdown处理器LRU缓存
- Zustand选择器优化减少重渲染
- CodeMirror Compartment主题热切换
- Preview防抖(150ms) + IndexedDB去抖(500ms)
- 组件拆分: App.tsx 310→104行, Sidebar.tsx 244→90行
- 统一错误处理 errorHandler.ts
- ConfirmDialog替代原生confirm
- LoadingSpinner加载状态
- Toast多条堆叠+类型区分
- 可访问性增强(ARIA属性、键盘导航)
- Vitest测试框架(78个测试用例)
- Git hooks(husky + lint-staged)
- 项目文档(README.md, CONTRIBUTING.md)
This commit is contained in:
thzxx
2026-06-03 22:13:32 +08:00
parent 3cecb0f9eb
commit 7a4e2b0a67
72 changed files with 5103 additions and 894 deletions
@@ -0,0 +1,96 @@
import { describe, it, expect } from 'vitest'
import { getFileName, isAllowedFile, getFileExtension } from '../fileUtils'
describe('fileUtils', () => {
describe('getFileName', () => {
it('should extract filename from Unix path', () => {
expect(getFileName('/home/user/documents/file.md')).toBe('file.md')
})
it('should extract filename from Windows path', () => {
expect(getFileName('C:\\Users\\test\\file.md')).toBe('file.md')
})
it('should return the input if it is already a filename', () => {
expect(getFileName('file.md')).toBe('file.md')
})
it('should handle path with trailing slash', () => {
// getFileName uses pop() || filePath, empty string is falsy so returns filePath
expect(getFileName('/path/to/dir/')).toBe('/path/to/dir/')
})
it('should handle mixed path separators', () => {
expect(getFileName('C:\\Users/test\\file.md')).toBe('file.md')
})
})
describe('getFileExtension', () => {
it('should return lowercase extension', () => {
expect(getFileExtension('file.MD')).toBe('.md')
})
it('should return .markdown extension', () => {
expect(getFileExtension('file.markdown')).toBe('.markdown')
})
it('should return .txt extension', () => {
expect(getFileExtension('notes.txt')).toBe('.txt')
})
it('should return empty string for no extension', () => {
expect(getFileExtension('Makefile')).toBe('')
})
it('should return empty string for hidden files starting with dot', () => {
expect(getFileExtension('.gitignore')).toBe('')
})
it('should extract extension from full path', () => {
expect(getFileExtension('/home/user/file.md')).toBe('.md')
})
it('should extract extension from Windows path', () => {
expect(getFileExtension('C:\\Users\\test\\file.MARKDOWN')).toBe('.markdown')
})
it('should handle file with multiple dots', () => {
expect(getFileExtension('my.file.md')).toBe('.md')
})
})
describe('isAllowedFile', () => {
it('should return true for .md files', () => {
expect(isAllowedFile('file.md')).toBe(true)
})
it('should return true for .markdown files', () => {
expect(isAllowedFile('file.markdown')).toBe(true)
})
it('should return true for .txt files', () => {
expect(isAllowedFile('file.txt')).toBe(true)
})
it('should return true for uppercase extensions', () => {
expect(isAllowedFile('file.MD')).toBe(true)
})
it('should return false for .js files', () => {
expect(isAllowedFile('file.js')).toBe(false)
})
it('should return false for .json files', () => {
expect(isAllowedFile('file.json')).toBe(false)
})
it('should return false for files without extension', () => {
expect(isAllowedFile('Makefile')).toBe(false)
})
it('should work with full paths', () => {
expect(isAllowedFile('/home/user/doc.md')).toBe(true)
expect(isAllowedFile('/home/user/script.py')).toBe(false)
})
})
})