@testspectra/react 1.2.15 → 1.2.16
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/dist/index.js +41 -3
- package/dist/setup.js +33 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
// src/dom_driver_bridge.ts
|
|
2
2
|
import { userEvent } from "@testing-library/user-event";
|
|
3
3
|
|
|
4
|
+
// ../../core/worker-runtime/src/dsl/element_scope.ts
|
|
5
|
+
var ELEMENT_SCOPE = /* @__PURE__ */ Symbol("testspectra.elementScope");
|
|
6
|
+
function getElementScope(value) {
|
|
7
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
8
|
+
return value[ELEMENT_SCOPE];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// ../../core/worker-runtime/src/dsl/typed_value.ts
|
|
12
|
+
var MASKED_INPUT_TYPES = ["number", "date", "time", "color", "file", "range"];
|
|
13
|
+
var alphanumeric = (text) => text.replace(/[^\p{L}\p{N}]/gu, "");
|
|
14
|
+
function typedTextLanded(expected, actual, before) {
|
|
15
|
+
if (actual === null || before === null) return true;
|
|
16
|
+
return actual === expected || actual !== before || alphanumeric(actual) === alphanumeric(expected);
|
|
17
|
+
}
|
|
18
|
+
function typedTextError(selector, expected, actual) {
|
|
19
|
+
return new Error(`Typed text did not reach element "${selector}": expected "${expected}", got "${actual}"`);
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
// ../../core/worker-runtime/src/dsl/keyboard.ts
|
|
5
23
|
var SPECIAL_KEYS = {
|
|
6
24
|
Backspace: { code: "Backspace", windowsVirtualKeyCode: 8 },
|
|
@@ -499,6 +517,12 @@ function isFormEl(el) {
|
|
|
499
517
|
const tag = el.tagName;
|
|
500
518
|
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT";
|
|
501
519
|
}
|
|
520
|
+
function readTypedValue(el) {
|
|
521
|
+
if (el.tagName !== "INPUT" && el.tagName !== "TEXTAREA") return null;
|
|
522
|
+
const field = el;
|
|
523
|
+
if (field.tagName === "INPUT" && MASKED_INPUT_TYPES.includes(field.type)) return null;
|
|
524
|
+
return typeof field.value === "string" ? field.value : null;
|
|
525
|
+
}
|
|
502
526
|
var DomDriverBridge = class {
|
|
503
527
|
mockRules = [];
|
|
504
528
|
consoleErrors = [];
|
|
@@ -571,10 +595,20 @@ var DomDriverBridge = class {
|
|
|
571
595
|
if (el.tagName === "INPUT" && el.type === "file") {
|
|
572
596
|
return this.upload(selector, value, index);
|
|
573
597
|
}
|
|
598
|
+
const text = String(value);
|
|
574
599
|
const u = getUser();
|
|
575
600
|
await u.clear(el);
|
|
576
|
-
|
|
577
|
-
|
|
601
|
+
const before = readTypedValue(el);
|
|
602
|
+
if (text.length > 0) {
|
|
603
|
+
await u.type(el, text);
|
|
604
|
+
if (typedTextLanded(text, readTypedValue(el), before)) return;
|
|
605
|
+
el.focus();
|
|
606
|
+
await u.clear(el);
|
|
607
|
+
await u.type(el, text);
|
|
608
|
+
const retried = readTypedValue(el);
|
|
609
|
+
if (!typedTextLanded(text, retried, before)) {
|
|
610
|
+
throw typedTextError(selectorText(selector), text, retried ?? "");
|
|
611
|
+
}
|
|
578
612
|
}
|
|
579
613
|
}
|
|
580
614
|
async upload(selector, files, index = null) {
|
|
@@ -876,7 +910,11 @@ var DomDriverBridge = class {
|
|
|
876
910
|
}
|
|
877
911
|
async execute(fn, ...args) {
|
|
878
912
|
if (typeof fn === "function") {
|
|
879
|
-
|
|
913
|
+
const resolved = args.map((arg) => {
|
|
914
|
+
const scope = getElementScope(arg);
|
|
915
|
+
return scope ? resolveScopedEl(scope, null) : arg;
|
|
916
|
+
});
|
|
917
|
+
return fn(...resolved);
|
|
880
918
|
}
|
|
881
919
|
return new Function(`return (${fn});`)();
|
|
882
920
|
}
|