cc-haha/desktop/src/preview-agent/bridge.test.ts
程序员阿江(Relakkes) 36a3ffff34 feat(desktop): preview-agent bridge with ready/navigated reporting
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 17:40:45 +08:00

22 lines
938 B
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { createBridge } from './bridge'
describe('createBridge', () => {
it('reports ready and navigated via postToHost', () => {
const postToHost = vi.fn()
const bridge = createBridge({ postToHost, location: { href: 'http://x/a' } as Location, title: 'T' })
bridge.reportReady()
bridge.reportNavigated()
expect(JSON.parse(postToHost.mock.calls[0]![0]!)).toMatchObject({ type: 'ready' })
expect(JSON.parse(postToHost.mock.calls[1]![0]!)).toMatchObject({ type: 'navigated', url: 'http://x/a', title: 'T' })
})
it('dispatches host messages to registered handlers', () => {
const postToHost = vi.fn(); const onEnter = vi.fn()
const bridge = createBridge({ postToHost, location: {} as Location, title: '' })
bridge.on('enter-picker', onEnter)
bridge.handleHostRaw('{"v":1,"type":"enter-picker"}')
expect(onEnter).toHaveBeenCalled()
})
})