chat-window.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { readFileSync } from 'fs'
  2. import { resolve } from 'path'
  3. import { describe, expect, it } from 'vitest'
  4. describe('desktop chat window', () => {
  5. it('creates one native-chrome BrowserWindow per session on the standalone chat route', () => {
  6. const mainSource = readFileSync(resolve('packages/desktop/src/main/index.ts'), 'utf8')
  7. const preloadSource = readFileSync(resolve('packages/desktop/src/preload/index.ts'), 'utf8')
  8. const routerSource = readFileSync(resolve('packages/client/src/router/index.ts'), 'utf8')
  9. const openChatWindowSource = mainSource.slice(
  10. mainSource.indexOf('async function openChatWindow'),
  11. mainSource.indexOf('async function initializeDesktopBrowser'),
  12. )
  13. expect(mainSource).toContain('const chatWindows = new Map<string, BrowserWindow>()')
  14. expect(mainSource).toContain("return webUiHashUrl(`/desktop-chat/${encodeURIComponent(sessionId)}${query}`)")
  15. expect(openChatWindowSource).not.toContain('frame: false')
  16. expect(openChatWindowSource).toContain('width: 620')
  17. expect(openChatWindowSource).toContain('height: 760')
  18. expect(openChatWindowSource).toContain("titleBarStyle: 'hiddenInset'")
  19. expect(openChatWindowSource).toContain('titleBarOverlay: { height: 46 }')
  20. expect(openChatWindowSource).toContain("additionalArguments: ['--hermes-window-kind=chat']")
  21. expect(mainSource).toContain("ipcMain.handle('hermes-desktop:open-chat-window'")
  22. expect(preloadSource).toContain("ipcRenderer.invoke('hermes-desktop:open-chat-window'")
  23. expect(routerSource).toContain("path: '/desktop-chat/:sessionId'")
  24. expect(routerSource).toContain('meta: { standaloneChat: true }')
  25. })
  26. it('targets window controls at the renderer that invoked them', () => {
  27. const source = readFileSync(resolve('packages/desktop/src/main/index.ts'), 'utf8')
  28. expect(source).toContain('const target = BrowserWindow.fromWebContents(event.sender)')
  29. expect(source).toContain('return handleWindowControl(target, action)')
  30. })
  31. })
粤ICP备19079148号