@testim/testim-cli 3.274.0 → 3.278.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commons/testimServicesApi.js +21 -0
- package/npm-shrinkwrap.json +194 -104
- package/package.json +1 -1
- package/player/services/tabServiceMock.js +1 -0
- package/player/stepActions/dropFileStepAction.js +1 -2
- package/player/stepActions/scripts/dispatchEvents.js +100 -89
- package/player/stepActions/scripts/doClick.js +82 -84
- package/player/stepActions/scripts/doDragPath.js +84 -85
- package/player/stepActions/scripts/doubleClick.js +38 -36
- package/player/stepActions/scripts/dropEvent.js +27 -24
- package/player/stepActions/scripts/focusElement.js +9 -13
- package/player/stepActions/scripts/html5dragAction.js +15 -15
- package/player/stepActions/scripts/html5dragActionV2.js +44 -45
- package/player/stepActions/scripts/runCode.js +24 -33
- package/player/stepActions/scripts/scroll.js +27 -27
- package/player/stepActions/scripts/selectOption.js +6 -6
- package/player/stepActions/scripts/setText.js +111 -116
- package/player/stepActions/scripts/wheel.js +18 -16
- package/polyfills/index.js +4 -0
- package/testRunStatus.js +17 -35
- package/testimNpmDriver.js +1 -1
- package/workers/WorkerAppium.js +6 -1
- package/player/stepActions/scripts/createDropEventLegacy.js +0 -61
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const StepAction = require('./stepAction');
|
|
4
4
|
const logger = require('../../commons/logger').getLogger('drop-file-step-action');
|
|
5
5
|
const downloadFileAndFireDropEvent = require('./scripts/dropEvent');
|
|
6
|
-
const createDropEventLegacy = require('./scripts/createDropEventLegacy');
|
|
7
6
|
const { codeSnippets, utils } = require('../../commons/getSessionPlayerRequire');
|
|
8
7
|
const featureFlagService = require('../../commons/featureFlags');
|
|
9
8
|
|
|
@@ -21,7 +20,7 @@ class DropFileStepAction extends StepAction {
|
|
|
21
20
|
|
|
22
21
|
const dropFileCode = `
|
|
23
22
|
var getLocatedElement = ${codeSnippets.getLocatedElementCode};
|
|
24
|
-
var createDropEvent = ${
|
|
23
|
+
var createDropEvent = ${codeSnippets.createDropEvent.toString()};
|
|
25
24
|
var downloadFileAndFireDropEvent = ${downloadFileAndFireDropEvent.toString()};
|
|
26
25
|
return downloadFileAndFireDropEvent.apply(null, arguments)
|
|
27
26
|
`;
|
|
@@ -1,56 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const dispatchEvents = function (eventData, done) {
|
|
4
4
|
function getParents(el) {
|
|
5
5
|
return el ? [el].concat(getParents(el.parentNode)) : [];
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
function handleReactSelectFocusQuirk(context, event) {
|
|
9
9
|
function focusReactSelect(element) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return getParents(
|
|
13
|
-
return Array.apply(null, el.classList || []).indexOf("Select-control") !== -1;
|
|
14
|
-
})[0];
|
|
10
|
+
function getReactSelectRoot(_element) {
|
|
11
|
+
// eslint-disable-next-line prefer-spread
|
|
12
|
+
return getParents(_element).find((el) => Array.apply(null, el.classList || []).includes('Select-control'));
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
function getReactSelectInput(
|
|
18
|
-
|
|
19
|
-
return root ? root.querySelector(
|
|
15
|
+
function getReactSelectInput(_element) {
|
|
16
|
+
const root = getReactSelectRoot(_element);
|
|
17
|
+
return root ? root.querySelector('INPUT') : null;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
const reactSelectInput = getReactSelectInput(element);
|
|
23
21
|
if (reactSelectInput) {
|
|
24
22
|
reactSelectInput.focus();
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
if (event.type ===
|
|
26
|
+
const isReactSelectElement = context.quirks?.isReactSelect;
|
|
27
|
+
if (event.type === 'mousedown' && isReactSelectElement) {
|
|
30
28
|
focusReactSelect(context.element);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
function handleCKEditorQuirk(context, event) {
|
|
35
|
-
|
|
36
|
-
if (event.type ===
|
|
33
|
+
const isCKEditorFrame = context.quirks?.isCKEditorFrame;
|
|
34
|
+
if (event.type === 'click' && isCKEditorFrame) {
|
|
37
35
|
document.body.focus();
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
function dispatchMouseOver() {
|
|
42
|
-
|
|
40
|
+
const event = document.createEvent('Events');
|
|
43
41
|
event.initEvent('mouseover', true, true);
|
|
44
42
|
context.element.dispatchEvent(event);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
function dispatchMouseMove() {
|
|
48
|
-
|
|
46
|
+
const userEvent = {
|
|
49
47
|
event: 'mousemove',
|
|
50
48
|
modifiers: {},
|
|
51
|
-
button: 0
|
|
49
|
+
button: 0,
|
|
52
50
|
};
|
|
53
|
-
|
|
51
|
+
const event = createMouseEvent(userEvent);
|
|
54
52
|
context.element.dispatchEvent(event);
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -59,20 +57,20 @@ var dispatchEvents = function (eventData, done) {
|
|
|
59
57
|
return (point > start) && (point < end);
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return {x: clientX, y: clientY};
|
|
60
|
+
const pointerPosition = userEvent.pointerPosition || {};
|
|
61
|
+
const rect = element.getBoundingClientRect();
|
|
62
|
+
const clientX = pointerPosition.originX && isWithinBounds(rect.left, rect.left + rect.width, pointerPosition.originX) ? pointerPosition.originX : rect.left + (rect.width / 2);
|
|
63
|
+
const clientY = pointerPosition.originY && isWithinBounds(rect.top, rect.top + rect.height, pointerPosition.originY) ? pointerPosition.originY : rect.top + (rect.height / 2);
|
|
64
|
+
return { x: clientX, y: clientY };
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
function createMouseEvent(userEvent) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const position = getEventPosition(userEvent, context.element);
|
|
69
|
+
const modifiers = userEvent.modifiers || context.modifiers || {};
|
|
70
|
+
const button = userEvent.button || context.button || 0;
|
|
71
|
+
const eventType = userEvent.event;
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
const event = document.createEvent('MouseEvents');
|
|
76
74
|
event.initMouseEvent(
|
|
77
75
|
eventType,
|
|
78
76
|
true, /* bubbles */
|
|
@@ -94,12 +92,12 @@ var dispatchEvents = function (eventData, done) {
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
function createPointerEvent(userEvent) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
const position = getEventPosition(userEvent, context.element);
|
|
96
|
+
const modifiers = userEvent.modifiers || context.modifiers || {};
|
|
97
|
+
const eventType = userEvent.event;
|
|
100
98
|
|
|
101
99
|
if (!window.PointerEvent) {
|
|
102
|
-
return;
|
|
100
|
+
return undefined;
|
|
103
101
|
}
|
|
104
102
|
return new window.PointerEvent(eventType, {
|
|
105
103
|
screenX: 0,
|
|
@@ -113,13 +111,13 @@ var dispatchEvents = function (eventData, done) {
|
|
|
113
111
|
bubbles: true,
|
|
114
112
|
cancelable: true,
|
|
115
113
|
composed: true,
|
|
116
|
-
pointerType:
|
|
114
|
+
pointerType: 'mouse',
|
|
117
115
|
isPrimary: true,
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
function createFocusEvent(userEvent) {
|
|
122
|
-
|
|
120
|
+
const event = document.createEvent('FocusEvent');
|
|
123
121
|
// TODO we want to use new Event, but mootools (used by zuora which is used by jfrog)
|
|
124
122
|
// overrides window.Event and throws an error
|
|
125
123
|
event.initEvent(userEvent.event, true, false);
|
|
@@ -127,76 +125,74 @@ var dispatchEvents = function (eventData, done) {
|
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
function createEvent(userEvent) {
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
const eventType = userEvent.event;
|
|
129
|
+
const event = document.createEvent('HTMLEvents');
|
|
132
130
|
event.initEvent(eventType, true, false);
|
|
133
131
|
return event;
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
function dispatchSyncEvent(event) {
|
|
137
|
-
console.log("dispatching: " + event.type);
|
|
138
|
-
console.log(event);
|
|
139
|
-
|
|
140
|
-
context.element.dispatchEvent(event);
|
|
141
|
-
handleReactSelectFocusQuirk(context, event);
|
|
142
|
-
handleCKEditorQuirk(context, event);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
134
|
function dispatchSyncEventSequence() {
|
|
146
135
|
context.events
|
|
147
|
-
.map(
|
|
136
|
+
.map((userEvent) => {
|
|
148
137
|
try {
|
|
149
|
-
if(MOUSE_EVENTS.includes(userEvent.event)) {
|
|
138
|
+
if (MOUSE_EVENTS.includes(userEvent.event)) {
|
|
150
139
|
return createMouseEvent(userEvent);
|
|
151
|
-
}
|
|
140
|
+
} if (POINTER_EVENTS.includes(userEvent.event)) {
|
|
152
141
|
return createPointerEvent(userEvent);
|
|
153
|
-
}
|
|
142
|
+
} if (FOCUS_EVENTS.includes(userEvent.event)) {
|
|
154
143
|
return createFocusEvent(userEvent);
|
|
155
|
-
} else {
|
|
156
|
-
return createEvent(userEvent);
|
|
157
144
|
}
|
|
145
|
+
return createEvent(userEvent);
|
|
158
146
|
} catch (e) {
|
|
159
|
-
// pointer events not supported
|
|
160
|
-
return;
|
|
147
|
+
// pointer events not supported :shrug:
|
|
148
|
+
return undefined;
|
|
161
149
|
}
|
|
162
150
|
})
|
|
163
151
|
.filter(Boolean)
|
|
164
|
-
.forEach(
|
|
165
|
-
|
|
152
|
+
.forEach((event) => {
|
|
153
|
+
// eslint-disable-next-line no-console
|
|
154
|
+
console.log(`dispatching: ${event.type}`);
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.log(event);
|
|
157
|
+
|
|
158
|
+
context.element.dispatchEvent(event);
|
|
159
|
+
handleReactSelectFocusQuirk(context, event);
|
|
160
|
+
handleCKEditorQuirk(context, event);
|
|
166
161
|
});
|
|
167
162
|
|
|
168
163
|
if (window.__unloadNavigator) {
|
|
169
|
-
window.removeEventListener(
|
|
164
|
+
window.removeEventListener('unload', window.__unloadNavigator);
|
|
170
165
|
}
|
|
171
166
|
}
|
|
172
167
|
|
|
173
168
|
function findEffectiveActiveElement() {
|
|
174
|
-
|
|
175
|
-
while (activeElement.shadowRoot
|
|
169
|
+
let activeElement = document.activeElement;
|
|
170
|
+
while (activeElement.shadowRoot?.activeElement) {
|
|
176
171
|
activeElement = activeElement.shadowRoot.activeElement;
|
|
177
172
|
}
|
|
178
173
|
return activeElement;
|
|
179
174
|
}
|
|
180
175
|
|
|
181
176
|
function handleFocus() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
177
|
+
const oldActiveElement = findEffectiveActiveElement();
|
|
178
|
+
const quirks = context.quirks;
|
|
179
|
+
const isReactSelectElement = quirks?.isReactSelect;
|
|
180
|
+
const isCKEditorFrame = quirks?.isCKEditorFrame;
|
|
186
181
|
if (!isReactSelectElement && !isCKEditorFrame) {
|
|
182
|
+
// eslint-disable-next-line no-undef
|
|
187
183
|
dispatchFocus(eventData.elementToFocusLocatedElement, oldActiveElement);
|
|
188
184
|
}
|
|
189
185
|
}
|
|
190
186
|
|
|
191
187
|
function handleSelect() {
|
|
192
|
-
if(context.element.tagName !== OPTION_TAG_NAME) {
|
|
188
|
+
if (context.element.tagName !== OPTION_TAG_NAME) {
|
|
193
189
|
return;
|
|
194
190
|
}
|
|
195
191
|
|
|
196
|
-
|
|
197
|
-
if(context.element.parentElement.tagName === SELECT_TAG_NAME) {
|
|
192
|
+
let selectEl;
|
|
193
|
+
if (context.element.parentElement.tagName === SELECT_TAG_NAME) {
|
|
198
194
|
selectEl = context.element.parentElement;
|
|
199
|
-
} else if(context.element.parentElement.parentElement.tagName === SELECT_TAG_NAME) {
|
|
195
|
+
} else if (context.element.parentElement.parentElement.tagName === SELECT_TAG_NAME) {
|
|
200
196
|
selectEl = context.element.parentElement.parentElement;
|
|
201
197
|
}
|
|
202
198
|
selectEl.blur();
|
|
@@ -206,13 +202,13 @@ var dispatchEvents = function (eventData, done) {
|
|
|
206
202
|
|
|
207
203
|
function fulfill(success, status, result) {
|
|
208
204
|
result = result || {};
|
|
209
|
-
|
|
210
|
-
success
|
|
211
|
-
status
|
|
212
|
-
result
|
|
205
|
+
status = {
|
|
206
|
+
success,
|
|
207
|
+
status,
|
|
208
|
+
result,
|
|
213
209
|
};
|
|
214
210
|
|
|
215
|
-
if(isDoneFnSupplied) {
|
|
211
|
+
if (isDoneFnSupplied) {
|
|
216
212
|
return done(status);
|
|
217
213
|
}
|
|
218
214
|
|
|
@@ -227,35 +223,50 @@ var dispatchEvents = function (eventData, done) {
|
|
|
227
223
|
return fulfill(false, 'failed', result);
|
|
228
224
|
}
|
|
229
225
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
226
|
+
const OPTION_TAG_NAME = 'OPTION';
|
|
227
|
+
const SELECT_TAG_NAME = 'SELECT';
|
|
228
|
+
|
|
229
|
+
const MOUSE_EVENTS = [
|
|
230
|
+
'auxclick',
|
|
231
|
+
'click',
|
|
232
|
+
'contextmenu',
|
|
233
|
+
'dblclick',
|
|
234
|
+
'mousedown',
|
|
235
|
+
'mouseenter',
|
|
236
|
+
'mouseleave',
|
|
237
|
+
'mousemove',
|
|
238
|
+
'mouseover',
|
|
239
|
+
'mouseout',
|
|
240
|
+
'mouseup',
|
|
241
|
+
'pointerlockchange',
|
|
242
|
+
'pointerlockerror',
|
|
243
|
+
'select',
|
|
244
|
+
'wheel',
|
|
245
|
+
];
|
|
246
|
+
const POINTER_EVENTS = ['pointerover', 'pointerenter', 'pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'pointerout', 'pointerleave', 'gotpointercapture', 'lostpointercapture'];
|
|
247
|
+
const FOCUS_EVENTS = ['focus', 'blur', 'focusin', 'focusout'];
|
|
248
|
+
|
|
249
|
+
const isDoneFnSupplied = typeof done !== 'undefined';
|
|
240
250
|
|
|
241
251
|
window.__unloadNavigator = resolve;
|
|
242
|
-
window.addEventListener(
|
|
252
|
+
window.addEventListener('unload', window.__unloadNavigator);
|
|
243
253
|
|
|
244
|
-
|
|
254
|
+
// eslint-disable-next-line no-undef
|
|
255
|
+
const element = eventData.isRoot ? document.documentElement : getLocatedElement(eventData.locatedElement);
|
|
245
256
|
if (!element) {
|
|
246
|
-
return reject(
|
|
257
|
+
return reject('element not found');
|
|
247
258
|
}
|
|
248
259
|
|
|
249
|
-
|
|
250
|
-
element
|
|
260
|
+
const context = {
|
|
261
|
+
element,
|
|
251
262
|
events: eventData.events,
|
|
252
263
|
quirks: eventData.quirks,
|
|
253
264
|
modifiers: eventData.modifiers,
|
|
254
265
|
};
|
|
255
266
|
|
|
256
267
|
try {
|
|
257
|
-
|
|
258
|
-
if(doMousePreparation) {
|
|
268
|
+
const doMousePreparation = eventData.withMousePreparation ? eventData.withMousePreparation : true;
|
|
269
|
+
if (doMousePreparation) {
|
|
259
270
|
dispatchMouseOver();
|
|
260
271
|
dispatchMouseMove();
|
|
261
272
|
}
|
|
@@ -2,42 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const doClick = (eventData, done) => {
|
|
6
|
+
const eventConstructorSupported = typeof Event === 'function';
|
|
7
7
|
|
|
8
8
|
window.__unloadNavigator = resolve;
|
|
9
9
|
|
|
10
|
-
window.addEventListener(
|
|
10
|
+
window.addEventListener('unload', window.__unloadNavigator);
|
|
11
11
|
|
|
12
12
|
function handleReactSelectFocusQuirk(context, event) {
|
|
13
13
|
function focusReactSelect(element) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return getParents(
|
|
17
|
-
return Array.apply(null, el.classList || []).indexOf("Select-control") !== -1;
|
|
18
|
-
})[0];
|
|
14
|
+
function getReactSelectRoot(_element) {
|
|
15
|
+
// eslint-disable-next-line prefer-spread
|
|
16
|
+
return getParents(_element).find((el) => Array.apply(null, el.classList || []).includes('Select-control'));
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
function getReactSelectInput(
|
|
22
|
-
|
|
23
|
-
return root ? root.querySelector(
|
|
19
|
+
function getReactSelectInput(_element) {
|
|
20
|
+
const root = getReactSelectRoot(_element);
|
|
21
|
+
return root ? root.querySelector('INPUT') : null;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
const reactSelectInput = getReactSelectInput(element);
|
|
27
25
|
if (reactSelectInput) {
|
|
28
26
|
reactSelectInput.focus();
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
if (event.type ===
|
|
30
|
+
const isReactSelectElement = context.quirks?.isReactSelect;
|
|
31
|
+
if (event.type === 'mousedown' && isReactSelectElement) {
|
|
34
32
|
focusReactSelect(context.element);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
function handleCKEditorQuirk(context, event) {
|
|
39
|
-
|
|
40
|
-
if (event.type ===
|
|
37
|
+
const isCKEditorFrame = context.quirks?.isCKEditorFrame;
|
|
38
|
+
if (event.type === 'click' && isCKEditorFrame) {
|
|
41
39
|
document.body.focus();
|
|
42
40
|
}
|
|
43
41
|
}
|
|
@@ -47,13 +45,13 @@ var doClick = function (eventData, done) {
|
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
function resolve(result) {
|
|
50
|
-
|
|
48
|
+
const status = {
|
|
51
49
|
status: 'done',
|
|
52
|
-
result
|
|
53
|
-
success: true
|
|
50
|
+
result,
|
|
51
|
+
success: true,
|
|
54
52
|
};
|
|
55
53
|
if (context.isNonTextableElemnet) {
|
|
56
|
-
status.reason =
|
|
54
|
+
status.reason = 'Set text on non input element';
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
done(status);
|
|
@@ -61,29 +59,29 @@ var doClick = function (eventData, done) {
|
|
|
61
59
|
|
|
62
60
|
function reject(result) {
|
|
63
61
|
result = result || {};
|
|
64
|
-
|
|
62
|
+
const status = {
|
|
65
63
|
status: 'failed',
|
|
66
|
-
result
|
|
67
|
-
success: false
|
|
64
|
+
result,
|
|
65
|
+
success: false,
|
|
68
66
|
};
|
|
69
67
|
|
|
70
68
|
done(status);
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
function dispatchMouseOver(element) {
|
|
74
|
-
|
|
72
|
+
const event = eventConstructorSupported ? new Event('mouseover', { composed: true }) : document.createEvent('Events');
|
|
75
73
|
event.initEvent('mouseover', true, true);
|
|
76
74
|
element.dispatchEvent(event);
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
function dispatchMouseMove(element) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
const modifiers = {};
|
|
79
|
+
const rect = element.getBoundingClientRect();
|
|
80
|
+
const clientX = rect.left + (rect.width / 2);
|
|
81
|
+
const clientY = rect.top + (rect.height / 2);
|
|
82
|
+
const button = 0;
|
|
83
|
+
const eventType = 'mousemove';
|
|
84
|
+
const event = createMouseEvent(eventType, modifiers, clientX, clientY, button);
|
|
87
85
|
element.dispatchEvent(event);
|
|
88
86
|
}
|
|
89
87
|
|
|
@@ -92,81 +90,75 @@ var doClick = function (eventData, done) {
|
|
|
92
90
|
return (point > start) && (point < end);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return {x: clientX, y: clientY};
|
|
93
|
+
const pointerPosition = userEvent.pointerPosition || {};
|
|
94
|
+
const rect = element.getBoundingClientRect();
|
|
95
|
+
const clientX = pointerPosition.originX && isWithinBounds(rect.left, rect.left + rect.width, pointerPosition.originX) ? pointerPosition.originX : rect.left + (rect.width / 2);
|
|
96
|
+
const clientY = pointerPosition.originY && isWithinBounds(rect.top, rect.top + rect.height, pointerPosition.originY) ? pointerPosition.originY : rect.top + (rect.height / 2);
|
|
97
|
+
return { x: clientX, y: clientY };
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
function getEventDictionary(modifiers, clientX, clientY) {
|
|
103
101
|
return {
|
|
104
102
|
screenX: 0,
|
|
105
103
|
screenY: 0,
|
|
106
|
-
clientX
|
|
107
|
-
clientY
|
|
104
|
+
clientX,
|
|
105
|
+
clientY,
|
|
108
106
|
ctrlKey: Boolean(modifiers.ctrl),
|
|
109
107
|
altKey: Boolean(modifiers.alt),
|
|
110
108
|
shiftKey: Boolean(modifiers.shift),
|
|
111
109
|
metaKey: Boolean(modifiers.meta),
|
|
112
110
|
bubbles: true,
|
|
113
111
|
cancelable: true,
|
|
114
|
-
composed: true
|
|
112
|
+
composed: true,
|
|
115
113
|
};
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
function createPointerEvent(eventType, modifiers, clientX, clientY) {
|
|
119
117
|
if (!window.PointerEvent) {
|
|
120
|
-
return;
|
|
118
|
+
return undefined;
|
|
121
119
|
}
|
|
122
|
-
|
|
123
|
-
eventProperties.pointerType =
|
|
120
|
+
const eventProperties = getEventDictionary(modifiers, clientX, clientY);
|
|
121
|
+
eventProperties.pointerType = 'mouse';
|
|
124
122
|
eventProperties.isPrimary = true;
|
|
125
123
|
return new window.PointerEvent(eventType, eventProperties);
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
function createMouseEvent(eventType, modifiers, clientX, clientY, button) {
|
|
129
|
-
|
|
127
|
+
const event = eventConstructorSupported ? new MouseEvent('click', { composed: true }) : document.createEvent('MouseEvents');
|
|
130
128
|
event.initMouseEvent(
|
|
131
129
|
eventType,
|
|
132
|
-
true,
|
|
133
|
-
true,
|
|
134
|
-
document.defaultView,
|
|
135
|
-
1,
|
|
136
|
-
0,
|
|
137
|
-
0,
|
|
138
|
-
clientX,
|
|
139
|
-
clientY,
|
|
140
|
-
Boolean(modifiers.ctrl),
|
|
141
|
-
Boolean(modifiers.alt),
|
|
142
|
-
Boolean(modifiers.shift),
|
|
143
|
-
Boolean(modifiers.meta),
|
|
144
|
-
button,
|
|
130
|
+
true,
|
|
131
|
+
true,
|
|
132
|
+
document.defaultView,
|
|
133
|
+
1,
|
|
134
|
+
0,
|
|
135
|
+
0,
|
|
136
|
+
clientX,
|
|
137
|
+
clientY,
|
|
138
|
+
Boolean(modifiers.ctrl),
|
|
139
|
+
Boolean(modifiers.alt),
|
|
140
|
+
Boolean(modifiers.shift),
|
|
141
|
+
Boolean(modifiers.meta),
|
|
142
|
+
button,
|
|
145
143
|
document.body ? document.body.parentNode : document.documentElement);
|
|
146
144
|
return event;
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
function getMouseEvent(userEvent, context) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (pointerEvents.
|
|
148
|
+
const pointerEvents = ['pointerup', 'pointerdown', 'pointermove'];
|
|
149
|
+
const modifiers = context.modifiers || {};
|
|
150
|
+
const pos = getEventPosition(userEvent, context.element);
|
|
151
|
+
const button = context.button || 0;
|
|
152
|
+
const eventType = userEvent.event;
|
|
153
|
+
if (pointerEvents.includes(eventType)) {
|
|
156
154
|
return createPointerEvent(eventType, modifiers, pos.x, pos.y);
|
|
157
155
|
}
|
|
158
156
|
return createMouseEvent(eventType, modifiers, pos.x, pos.y, button);
|
|
159
157
|
}
|
|
160
158
|
|
|
161
|
-
function executeSyncEvent(event) {
|
|
162
|
-
context.element.dispatchEvent(event);
|
|
163
|
-
handleReactSelectFocusQuirk(context, event);
|
|
164
|
-
handleCKEditorQuirk(context, event);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
159
|
function findEffectiveActiveElement() {
|
|
168
|
-
|
|
169
|
-
while (activeElement.shadowRoot
|
|
160
|
+
let activeElement = document.activeElement;
|
|
161
|
+
while (activeElement.shadowRoot?.activeElement) {
|
|
170
162
|
activeElement = activeElement.shadowRoot.activeElement;
|
|
171
163
|
}
|
|
172
164
|
return activeElement;
|
|
@@ -174,49 +166,55 @@ var doClick = function (eventData, done) {
|
|
|
174
166
|
|
|
175
167
|
function executeSynchronousEventSequence(context) {
|
|
176
168
|
context.events
|
|
177
|
-
.map(
|
|
169
|
+
.map((userEvent) => {
|
|
178
170
|
try {
|
|
179
171
|
return getMouseEvent(userEvent, context);
|
|
180
172
|
} catch (e) {
|
|
181
|
-
// pointer events not supported
|
|
182
|
-
return;
|
|
173
|
+
// pointer events not supported :shrug:
|
|
174
|
+
return undefined;
|
|
183
175
|
}
|
|
184
176
|
})
|
|
185
177
|
.filter(Boolean)
|
|
186
|
-
.forEach(
|
|
178
|
+
.forEach((event) => {
|
|
179
|
+
context.element.dispatchEvent(event);
|
|
180
|
+
handleReactSelectFocusQuirk(context, event);
|
|
181
|
+
handleCKEditorQuirk(context, event);
|
|
182
|
+
});
|
|
187
183
|
|
|
188
184
|
if (window.__unloadNavigator) {
|
|
189
|
-
window.removeEventListener(
|
|
185
|
+
window.removeEventListener('unload', window.__unloadNavigator);
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
188
|
|
|
193
|
-
|
|
189
|
+
const element = eventData.isRoot ? document.documentElement : getLocatedElement(eventData.locatedElement);
|
|
190
|
+
// eslint-disable-next-line no-var
|
|
194
191
|
var context = {
|
|
195
|
-
element
|
|
192
|
+
element,
|
|
196
193
|
events: eventData.events,
|
|
197
194
|
quirks: eventData.quirks,
|
|
198
195
|
modifiers: eventData.modifiers,
|
|
199
|
-
button: eventData.button
|
|
196
|
+
button: eventData.button,
|
|
200
197
|
};
|
|
201
198
|
|
|
202
199
|
if (!context.element) {
|
|
203
|
-
|
|
200
|
+
reject('element not found');
|
|
201
|
+
return;
|
|
204
202
|
}
|
|
205
203
|
|
|
206
204
|
dispatchMouseOver(context.element);
|
|
207
205
|
dispatchMouseMove(context.element);
|
|
208
206
|
try {
|
|
209
207
|
executeSynchronousEventSequence(context);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
const oldActiveElement = findEffectiveActiveElement();
|
|
209
|
+
const quirks = context.quirks;
|
|
210
|
+
const isReactSelectElement = quirks?.isReactSelect;
|
|
211
|
+
const isCKEditorFrame = quirks?.isCKEditorFrame;
|
|
214
212
|
if (!isReactSelectElement && !isCKEditorFrame) {
|
|
215
213
|
dispatchFocus(eventData.elementToFocusLocatedElement, oldActiveElement);
|
|
216
214
|
}
|
|
217
215
|
resolve();
|
|
218
216
|
} catch (e) {
|
|
219
|
-
|
|
217
|
+
reject(e.toString());
|
|
220
218
|
}
|
|
221
219
|
};
|
|
222
220
|
|