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