|
1 | 1 | import {LogEventType} from '../constants/internal'; |
2 | | -import {log} from '../utils/log'; |
| 2 | +import {step} from '../step'; |
| 3 | + |
| 4 | +import {waitForInterfaceStabilization} from './waitFor'; |
| 5 | + |
| 6 | +import type {Locator} from '@playwright/test'; |
3 | 7 |
|
4 | 8 | import type {Selector, WithStabilizationInterval} from '../types/internal'; |
5 | 9 |
|
6 | | -type Options = Record<string, unknown> & WithStabilizationInterval; |
| 10 | +type Options = Parameters<Locator['dispatchEvent']>[2] & |
| 11 | + WithStabilizationInterval & |
| 12 | + Readonly<{eventInit?: Parameters<Locator['dispatchEvent']>[1]}>; |
7 | 13 |
|
8 | 14 | /** |
9 | 15 | * Dispatches an event over a specified DOM element. |
10 | 16 | */ |
11 | 17 | export const dispatchEvent = ( |
12 | 18 | selector: Selector, |
13 | 19 | eventName: string, |
14 | | - {stabilizationInterval, ...options}: Options = {}, |
15 | | -): Promise<void> => { |
16 | | - log( |
17 | | - 'Dispatches an event over a specified element', |
18 | | - {...options, selector, stabilizationInterval}, |
19 | | - LogEventType.InternalAction, |
20 | | - ); |
| 20 | + {eventInit, stabilizationInterval, ...options}: Options = {}, |
| 21 | +): Promise<void> => |
| 22 | + step( |
| 23 | + `Dispatches an event "${eventName}" over a specified element`, |
| 24 | + async () => { |
| 25 | + await selector.getPlaywrightLocator().dispatchEvent(eventName, eventInit, options); |
21 | 26 |
|
22 | | - // TODO |
23 | | - return Promise.resolve(); |
24 | | -}; |
| 27 | + if (stabilizationInterval !== undefined && stabilizationInterval > 0) { |
| 28 | + await waitForInterfaceStabilization(stabilizationInterval); |
| 29 | + } |
| 30 | + }, |
| 31 | + { |
| 32 | + payload: {eventInit, ...options, selector, stabilizationInterval}, |
| 33 | + type: LogEventType.InternalAction, |
| 34 | + }, |
| 35 | + ); |
0 commit comments