Files
prompt-optimizer/packages/ui/tests/unit/useFunctionMode.test.ts
linshen da789bbb0e refactor(ui): 重组 composables 目录结构并优化模式功能
**目录结构重构**:
- 将 41 个 composables 文件按功能分类到 10 个子目录
- model/ - 模型管理相关(5个文件)
- prompt/ - 提示词相关(6个文件)
- context/ - 上下文相关(2个文件)
- image/ - 图像相关(2个文件)
- ui/ - UI交互相关(11个文件)
- accessibility/ - 无障碍相关(3个文件)
- performance/ - 性能优化相关(4个文件)
- storage/ - 存储相关(3个文件)
- system/ - 系统相关(2个文件)
- mode/ - 功能模式相关(4个文件)

**技术实现**:
- 使用 git mv 保留文件历史
- 为每个子目录创建 barrel export (index.ts)
- 更新 120+ 处导入路径引用
- 修复测试文件中的导入路径

**功能优化**:
- 新增 useCurrentMode composable 提供只读模式访问
- 基础模式下隐藏变量相关UI组件
- 优化 TestAreaPanel 根据功能模式动态显示变量表单

**影响范围**:
- 移动文件:41个 composables
- 新增文件:10个 index.ts
- 更新导入:120+ 处导入路径
- 测试修复:3个测试文件路径更新
2025-10-26 11:46:26 +08:00

44 lines
1.5 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest'
import { ref } from 'vue'
import { useFunctionMode } from '../../src/composables/mode/useFunctionMode'
const makeServices = () => {
const store = new Map<string, any>()
const preferenceService = {
async get<T>(key: string, def: T): Promise<T> {
return (store.has(key) ? store.get(key) : def) as T
},
async set<T>(key: string, value: T) { store.set(key, value) },
async delete() {},
async keys() { return Array.from(store.keys()) },
async clear() { store.clear() },
async getAll() { const obj: Record<string,string> = {}; for (const [k,v] of store) obj[k]=String(v); return obj }
}
return ref({ preferenceService } as any)
}
describe('useFunctionMode', () => {
let services: any
beforeEach(() => { services = makeServices() })
it('defaults to basic when unset', async () => {
const { functionMode, ensureInitialized } = useFunctionMode(services)
await ensureInitialized()
expect(functionMode.value).toBe('basic')
})
it('can switch to pro and persist', async () => {
const { functionMode, setFunctionMode, ensureInitialized } = useFunctionMode(services)
await ensureInitialized()
await setFunctionMode('pro')
expect(functionMode.value).toBe('pro')
})
it('supports image mode', async () => {
const { functionMode, setFunctionMode, ensureInitialized } = useFunctionMode(services)
await ensureInitialized()
await setFunctionMode('image' as any)
expect(functionMode.value).toBe('image')
})
})