ftmocks-utils 1.4.1 → 1.4.2
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/package.json +1 -1
- package/src/event-run-utils.js +75 -35
package/package.json
CHANGED
package/src/event-run-utils.js
CHANGED
|
@@ -162,8 +162,18 @@ const runEventsInPresentationMode = async (page, ftmocksConifg, testName) => {
|
|
|
162
162
|
currentEventIndex = currentEventIndex + 1;
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
+
await page.exposeFunction("focusOnBodyForPresentationMode", async () => {
|
|
166
|
+
await page.bringToFront();
|
|
167
|
+
});
|
|
168
|
+
|
|
165
169
|
// Inject keyboard listener into browser
|
|
166
170
|
await page.addInitScript(() => {
|
|
171
|
+
window.addEventListener("load", async () => {
|
|
172
|
+
console.log("➡ focus on body for presentation mode");
|
|
173
|
+
await window.focusOnBodyForPresentationMode();
|
|
174
|
+
window.focus();
|
|
175
|
+
document.body.focus();
|
|
176
|
+
});
|
|
167
177
|
window.addEventListener("keydown", (e) => {
|
|
168
178
|
if (e.key === "ArrowRight") {
|
|
169
179
|
console.log("➡ ArrowRight key pressed!");
|
|
@@ -232,14 +242,38 @@ const runEventsInTrainingMode = async (page, ftmocksConifg, testName) => {
|
|
|
232
242
|
popover.style.borderRadius = "8px";
|
|
233
243
|
popover.style.boxShadow = "0 2px 12px rgba(0,0,0,0.25)";
|
|
234
244
|
|
|
235
|
-
|
|
245
|
+
const highlighter = document.createElement("div");
|
|
246
|
+
highlighter.id = "ftmocks-highlighter-training-mode";
|
|
247
|
+
highlighter.style.position = "absolute";
|
|
248
|
+
highlighter.style.top = "0";
|
|
249
|
+
highlighter.style.left = "0";
|
|
250
|
+
highlighter.style.width = "100%";
|
|
251
|
+
highlighter.style.height = "100%";
|
|
252
|
+
highlighter.style.background = "rgba(0,0,0,0.5)";
|
|
253
|
+
highlighter.style.border = "2px solid #3fa9f5";
|
|
254
|
+
highlighter.style.display = "none";
|
|
255
|
+
highlighter.style.pointerEvents = "none";
|
|
256
|
+
|
|
257
|
+
function showPopover(eventInfo) {
|
|
236
258
|
if (!document.getElementById("ftmocks-popover-training-mode")) {
|
|
237
259
|
document.body.appendChild(popover);
|
|
238
260
|
}
|
|
239
|
-
popover.textContent =
|
|
261
|
+
popover.textContent = eventInfo.event.type;
|
|
240
262
|
popover.style.display = "block";
|
|
241
|
-
popover.style.left =
|
|
242
|
-
|
|
263
|
+
popover.style.left =
|
|
264
|
+
eventInfo.position.x + eventInfo.position.width / 2 + "px";
|
|
265
|
+
popover.style.top =
|
|
266
|
+
eventInfo.position.y + eventInfo.position.height + "px";
|
|
267
|
+
|
|
268
|
+
// Show highlighter
|
|
269
|
+
if (!document.getElementById("ftmocks-highlighter-training-mode")) {
|
|
270
|
+
document.body.appendChild(highlighter);
|
|
271
|
+
}
|
|
272
|
+
highlighter.style.display = "block";
|
|
273
|
+
highlighter.style.left = eventInfo.position.x + "px";
|
|
274
|
+
highlighter.style.top = eventInfo.position.y + "px";
|
|
275
|
+
highlighter.style.width = eventInfo.position.width + "px";
|
|
276
|
+
highlighter.style.height = eventInfo.position.height + "px";
|
|
243
277
|
}
|
|
244
278
|
|
|
245
279
|
function hidePopover() {
|
|
@@ -249,84 +283,90 @@ const runEventsInTrainingMode = async (page, ftmocksConifg, testName) => {
|
|
|
249
283
|
const initialEventRun = async () => {
|
|
250
284
|
currentEventInfo = await window.getNextEvent();
|
|
251
285
|
if (currentEventInfo) {
|
|
252
|
-
showPopover(currentEventInfo
|
|
286
|
+
showPopover(currentEventInfo);
|
|
253
287
|
}
|
|
254
288
|
};
|
|
255
289
|
|
|
290
|
+
const matchElement = (event, currentEventInfo) => {
|
|
291
|
+
console.log(
|
|
292
|
+
"➡ Matching element!",
|
|
293
|
+
event.target.isEqualNode(currentEventInfo?.element),
|
|
294
|
+
currentEventInfo?.element?.contains(event.target)
|
|
295
|
+
);
|
|
296
|
+
return (
|
|
297
|
+
event.target.isEqualNode(currentEventInfo?.element) ||
|
|
298
|
+
currentEventInfo?.element?.contains(event.target)
|
|
299
|
+
);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
window.addEventListener("load", async () => {
|
|
303
|
+
await initialEventRun();
|
|
304
|
+
});
|
|
305
|
+
|
|
256
306
|
window.addEventListener("click", async (event) => {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
event.target.isEqualNode(currentEventInfo?.element)
|
|
307
|
+
console.log(
|
|
308
|
+
"➡ Click event triggered!",
|
|
309
|
+
event.target.isEqualNode(currentEventInfo?.element),
|
|
260
310
|
currentEventInfo?.element?.contains(event.target)
|
|
311
|
+
);
|
|
312
|
+
if (
|
|
313
|
+
currentEventInfo?.event?.type === "click" &&
|
|
314
|
+
matchElement(event, currentEventInfo)
|
|
261
315
|
) {
|
|
262
316
|
currentEventInfo = await window.getNextEvent();
|
|
263
317
|
if (currentEventInfo) {
|
|
264
|
-
showPopover(currentEventInfo
|
|
318
|
+
showPopover(currentEventInfo);
|
|
265
319
|
} else {
|
|
266
320
|
hidePopover();
|
|
267
321
|
}
|
|
268
|
-
} else {
|
|
269
|
-
initialEventRun();
|
|
270
322
|
}
|
|
271
323
|
});
|
|
272
324
|
window.addEventListener("dblclick", async (event) => {
|
|
273
325
|
if (
|
|
274
|
-
currentEventInfo?.type === "dblclick" &&
|
|
275
|
-
event
|
|
276
|
-
currentEventInfo?.element?.contains(event.target)
|
|
326
|
+
currentEventInfo?.event?.type === "dblclick" &&
|
|
327
|
+
matchElement(event, currentEventInfo)
|
|
277
328
|
) {
|
|
278
329
|
currentEventInfo = await window.getNextEvent();
|
|
279
330
|
if (currentEventInfo) {
|
|
280
|
-
showPopover(currentEventInfo
|
|
331
|
+
showPopover(currentEventInfo);
|
|
281
332
|
} else {
|
|
282
333
|
hidePopover();
|
|
283
334
|
}
|
|
284
|
-
} else {
|
|
285
|
-
initialEventRun();
|
|
286
335
|
}
|
|
287
336
|
});
|
|
288
337
|
window.addEventListener("contextmenu", async (event) => {
|
|
289
338
|
if (
|
|
290
|
-
currentEventInfo?.type === "contextmenu" &&
|
|
291
|
-
event
|
|
292
|
-
currentEventInfo?.element?.contains(event.target)
|
|
339
|
+
currentEventInfo?.event?.type === "contextmenu" &&
|
|
340
|
+
matchElement(event, currentEventInfo)
|
|
293
341
|
) {
|
|
294
342
|
currentEventInfo = await window.getNextEvent();
|
|
295
343
|
if (currentEventInfo) {
|
|
296
|
-
showPopover(currentEventInfo
|
|
344
|
+
showPopover(currentEventInfo);
|
|
297
345
|
} else {
|
|
298
346
|
hidePopover();
|
|
299
347
|
}
|
|
300
|
-
} else {
|
|
301
|
-
initialEventRun();
|
|
302
348
|
}
|
|
303
349
|
});
|
|
304
350
|
window.addEventListener("input", async (event) => {
|
|
305
351
|
if (
|
|
306
|
-
currentEventInfo?.type === "input" &&
|
|
307
|
-
event
|
|
308
|
-
currentEventInfo?.element?.contains(event.target)
|
|
352
|
+
currentEventInfo?.event?.type === "input" &&
|
|
353
|
+
matchElement(event, currentEventInfo)
|
|
309
354
|
) {
|
|
310
355
|
currentEventInfo = await window.getNextEvent();
|
|
311
356
|
if (currentEventInfo) {
|
|
312
|
-
showPopover(currentEventInfo
|
|
357
|
+
showPopover(currentEventInfo);
|
|
313
358
|
}
|
|
314
|
-
} else {
|
|
315
|
-
initialEventRun();
|
|
316
359
|
}
|
|
317
360
|
});
|
|
318
361
|
window.addEventListener("keypress", async (event) => {
|
|
319
362
|
if (
|
|
320
|
-
currentEventInfo?.type === "keypress" &&
|
|
321
|
-
event
|
|
322
|
-
currentEventInfo?.element?.contains(event.target)
|
|
363
|
+
currentEventInfo?.event?.type === "keypress" &&
|
|
364
|
+
matchElement(event, currentEventInfo)
|
|
323
365
|
) {
|
|
324
366
|
currentEventInfo = await window.getNextEvent();
|
|
325
367
|
if (currentEventInfo) {
|
|
326
|
-
showPopover(currentEventInfo
|
|
368
|
+
showPopover(currentEventInfo);
|
|
327
369
|
}
|
|
328
|
-
} else {
|
|
329
|
-
initialEventRun();
|
|
330
370
|
}
|
|
331
371
|
});
|
|
332
372
|
});
|