Browse Source

适配 Bot 快照初始化的聊天删除回归测试

Samien 1 month ago
parent
commit
4066b41b01
1 changed files with 3 additions and 1 deletions
  1. 3 1
      tests/client/conversationSearchDelete.test.ts

+ 3 - 1
tests/client/conversationSearchDelete.test.ts

@@ -11,13 +11,15 @@ vi.mock('../../src/client/stores/auth', () => ({ useAuthStore: () => ({ user: {
 vi.mock('../../src/client/stores/theme', () => ({ useThemeStore: () => ({}) }))
 
 let wrapper: VueWrapper | undefined
-afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); vi.mocked(apiRequest).mockReset() })
+afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); vi.unstubAllGlobals(); vi.mocked(apiRequest).mockReset() })
 
 async function setup(kind: 'direct' | 'group', remove: () => Promise<void> = async () => {}, groups: WorkspaceLifecyclePreview['groups'] = [], initiallyArchived = true) {
   let archived = [{ id: 'archived', name: '旧聊天', kind, archived: initiallyArchived, memberIds: ['bot'], updatedAt: 1 }]
   const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/conversations/:id?', component: { template: '<div />' } }] })
   await router.push('/conversations'); await router.isReady()
+  vi.stubGlobal('EventSource', class { addEventListener() {} close() {} })
   vi.mocked(apiRequest).mockImplementation(async (path, options) => {
+    if (path === '/api/app/workspace/snapshot') return { agents: [{ id: 'bot', name: '旧聊天', archived: true }], conversations: archived, details: [], cursor: 1 } as never
     if (path.endsWith('/lifecycle')) {
       if (options?.method !== 'POST') return { name: '旧聊天', kind, groups, confirmationToken: 'a'.repeat(64) } as never
       await remove()