42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { jest } from '@jest/globals'
|
|
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation'
|
|
import { AutomationEvent } from '../../../../packages/application/ports/IAutomationEventPublisher'
|
|
|
|
describe('PlaywrightAutomationAdapter lifecycle events (unit)', () => {
|
|
test('emits panel-attached before action-started during wizard attach flow', async () => {
|
|
// Minimal mock page with needed shape
|
|
const mockPage: any = {
|
|
waitForSelector: async (s: string, o?: any) => {
|
|
return { asElement: () => ({}) }
|
|
},
|
|
evaluate: async () => {},
|
|
}
|
|
|
|
const adapter = new PlaywrightAutomationAdapter({} as any)
|
|
|
|
const received: AutomationEvent[] = []
|
|
adapter.onLifecycle?.((e: AutomationEvent) => {
|
|
received.push(e)
|
|
})
|
|
|
|
// run a method that triggers panel attach and action start; assume performAddCar exists
|
|
if (typeof adapter.performAddCar === 'function') {
|
|
// performAddCar may emit events internally
|
|
await adapter.performAddCar({ page: mockPage, actionId: 'add-car' } as any)
|
|
} else if (typeof adapter.attachPanel === 'function') {
|
|
await adapter.attachPanel(mockPage)
|
|
// simulate action start
|
|
await adapter.emitLifecycle?.({ type: 'action-started', actionId: 'add-car', timestamp: Date.now() } as any)
|
|
} else {
|
|
throw new Error('Adapter lacks expected methods for this test')
|
|
}
|
|
|
|
// ensure panel-attached appeared before action-started
|
|
const types = received.map((r) => r.type)
|
|
const panelIndex = types.indexOf('panel-attached')
|
|
const startIndex = types.indexOf('action-started')
|
|
expect(panelIndex).toBeGreaterThanOrEqual(0)
|
|
expect(startIndex).toBeGreaterThanOrEqual(0)
|
|
expect(panelIndex).toBeLessThanOrEqual(startIndex)
|
|
})
|
|
}) |