feat(overlay-sync): wire OverlaySyncService into DI, IPC and renderer gating
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { jest } from '@jest/globals'
|
||||
import { OverlayAction } from '../../../../packages/application/ports/IOverlaySyncPort'
|
||||
import { IAutomationLifecycleEmitter, LifecycleCallback } from '../../../../packages/infrastructure/adapters/IAutomationLifecycleEmitter'
|
||||
import { OverlaySyncService } from '../../../../packages/application/services/OverlaySyncService'
|
||||
|
||||
class MockLifecycleEmitter implements IAutomationLifecycleEmitter {
|
||||
private callbacks: Set<LifecycleCallback> = new Set()
|
||||
onLifecycle(cb: LifecycleCallback): void {
|
||||
this.callbacks.add(cb)
|
||||
}
|
||||
offLifecycle(cb: LifecycleCallback): void {
|
||||
this.callbacks.delete(cb)
|
||||
}
|
||||
async emit(event: any) {
|
||||
for (const cb of Array.from(this.callbacks)) {
|
||||
cb(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('OverlaySyncService timeout (unit)', () => {
|
||||
test('startAction with short timeout resolves as tentative when no events', async () => {
|
||||
const emitter = new MockLifecycleEmitter()
|
||||
const svc = new OverlaySyncService({ lifecycleEmitter: emitter as any, logger: console as any, publisher: { publish: async () => {} } as any })
|
||||
|
||||
const action: OverlayAction = { id: 'add-car', label: 'Adding...', timeoutMs: 50 }
|
||||
|
||||
const start = Date.now()
|
||||
const ack = await svc.startAction(action)
|
||||
const elapsed = Date.now() - start
|
||||
|
||||
expect(ack.status).toBe('tentative')
|
||||
expect(ack.id).toBe('add-car')
|
||||
expect(elapsed).toBeGreaterThanOrEqual(40)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user