mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
- Windows 上隐藏原生菜单栏和窗口装饰,前端渲染自定义窗口控制按钮(最小化/最大化/关闭) - macOS 保持原生菜单栏不变(条件编译) - Sidebar 在 Windows 上不再添加 macOS 红绿灯的额外顶部间距 - 新增 Windows 构建脚本和 NSIS 安装钩子 - 服务端 CORS、会话服务、对话服务改进及测试补充 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { createMock, listMock } = vi.hoisted(() => ({
|
|
createMock: vi.fn(),
|
|
listMock: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('../api/sessions', () => ({
|
|
sessionsApi: {
|
|
create: createMock,
|
|
list: listMock,
|
|
delete: vi.fn(),
|
|
rename: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
import { useSessionStore } from './sessionStore'
|
|
|
|
const initialState = useSessionStore.getState()
|
|
|
|
function delay(ms: number) {
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
}
|
|
|
|
describe('sessionStore', () => {
|
|
beforeEach(() => {
|
|
createMock.mockReset()
|
|
listMock.mockReset()
|
|
useSessionStore.setState({
|
|
...initialState,
|
|
sessions: [],
|
|
activeSessionId: null,
|
|
isLoading: false,
|
|
error: null,
|
|
selectedProjects: [],
|
|
availableProjects: [],
|
|
})
|
|
})
|
|
|
|
afterEach(() => {
|
|
useSessionStore.setState(initialState)
|
|
})
|
|
|
|
it('returns a new session id before the background refresh completes', async () => {
|
|
createMock.mockResolvedValue({ sessionId: 'session-optimistic-1' })
|
|
listMock.mockImplementation(() => new Promise(() => {}))
|
|
|
|
const result = await Promise.race([
|
|
useSessionStore.getState().createSession('D:/workspace/code/myself_code/cc-haha'),
|
|
delay(100).then(() => 'timed-out'),
|
|
])
|
|
|
|
expect(result).toBe('session-optimistic-1')
|
|
expect(useSessionStore.getState().activeSessionId).toBe('session-optimistic-1')
|
|
expect(useSessionStore.getState().sessions[0]).toMatchObject({
|
|
id: 'session-optimistic-1',
|
|
title: 'New Session',
|
|
workDir: 'D:/workspace/code/myself_code/cc-haha',
|
|
workDirExists: true,
|
|
})
|
|
expect(listMock).toHaveBeenCalledOnce()
|
|
})
|
|
})
|