P0 致命Bug修复: - A1: openFolderDialog 类型/运行时崩溃(文件夹打开功能完全失效) - A2: SourceEditor 受控textarea手动改DOM反模式 - A3: tabStore.updateTabContent 内容相同时误标isModified 死代码清理: - B1: 删除menu:*/save/as/viewMode 三个永不触发的IPC通道 健壮性修复: - E1: rehypeFixImages 路径规范化+防越界加固 - E2: getFileName 尾斜杠返回正确文件名 - E3: EditorToolbar 行内代码按钮改用toggleInlineCodeCommand - E4: ErrorBoundary 内联样式抽为CSS类 功能增强: - D1: 标签页拖拽排序(tabStore.moveTab + TabBar DnD + CSS) - D2: Milkdown自动配对括号/引号(ProseMirror插件) - D3: 状态栏自动保存开关可点击 - D4: 文档大纲活跃标题高亮(useActiveHeading hook) - D5: 关闭窗口前flush防抖数据(flushSaveToDB) - D6: 搜索替换支持正则表达式 类型/架构: - C2: preload类型集中定义(ElectronAPI契约) - __pycache__ typo修复 文档/版本: - README/DESIGN同步为Milkdown + v0.3.10 - 项目结构树/技术栈/快捷键表更新 验证: typecheck(仅7预存), lint✅, test 96/96, vite build✅
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
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', () => {
|
|
expect(getFileName('/path/to/dir/')).toBe('dir')
|
|
})
|
|
|
|
|
|
it('should handle path with trailing backslash', () => {
|
|
expect(getFileName('C:\\Users\\test\\')).toBe('test')
|
|
})
|
|
|
|
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)
|
|
})
|
|
})
|
|
})
|