@testspectra/react 1.2.8 → 1.2.9
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 +44 -0
- package/dist/setup.js +33 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
// src/dom_driver_bridge.ts
|
|
2
2
|
import { userEvent } from "@testing-library/user-event";
|
|
3
3
|
|
|
4
|
+
// ../../core/worker-runtime/src/dsl/keyboard.ts
|
|
5
|
+
var SPECIAL_KEYS = {
|
|
6
|
+
Backspace: { code: "Backspace", windowsVirtualKeyCode: 8 },
|
|
7
|
+
Tab: { code: "Tab", windowsVirtualKeyCode: 9 },
|
|
8
|
+
Enter: { code: "Enter", windowsVirtualKeyCode: 13, text: "\r" },
|
|
9
|
+
Escape: { code: "Escape", windowsVirtualKeyCode: 27 },
|
|
10
|
+
Delete: { code: "Delete", windowsVirtualKeyCode: 46 },
|
|
11
|
+
ArrowLeft: { code: "ArrowLeft", windowsVirtualKeyCode: 37 },
|
|
12
|
+
ArrowUp: { code: "ArrowUp", windowsVirtualKeyCode: 38 },
|
|
13
|
+
ArrowRight: { code: "ArrowRight", windowsVirtualKeyCode: 39 },
|
|
14
|
+
ArrowDown: { code: "ArrowDown", windowsVirtualKeyCode: 40 },
|
|
15
|
+
Home: { code: "Home", windowsVirtualKeyCode: 36 },
|
|
16
|
+
End: { code: "End", windowsVirtualKeyCode: 35 },
|
|
17
|
+
PageUp: { code: "PageUp", windowsVirtualKeyCode: 33 },
|
|
18
|
+
PageDown: { code: "PageDown", windowsVirtualKeyCode: 34 },
|
|
19
|
+
" ": { code: "Space", windowsVirtualKeyCode: 32, text: " " },
|
|
20
|
+
Space: { code: "Space", windowsVirtualKeyCode: 32, text: " " }
|
|
21
|
+
};
|
|
22
|
+
function codeForChar(char) {
|
|
23
|
+
if (/^[a-zA-Z]$/.test(char)) return `Key${char.toUpperCase()}`;
|
|
24
|
+
if (/^[0-9]$/.test(char)) return `Digit${char}`;
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
function describePressKey(input) {
|
|
28
|
+
if (typeof input !== "string") return null;
|
|
29
|
+
if (input === "Space") return { key: " ", code: "Space", windowsVirtualKeyCode: 32, text: " " };
|
|
30
|
+
const special = SPECIAL_KEYS[input];
|
|
31
|
+
if (special) return { key: input, ...special };
|
|
32
|
+
if (input.length === 1) {
|
|
33
|
+
return {
|
|
34
|
+
key: input,
|
|
35
|
+
code: codeForChar(input),
|
|
36
|
+
windowsVirtualKeyCode: input.toUpperCase().charCodeAt(0),
|
|
37
|
+
text: input
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
4
43
|
// ../../core/worker-runtime/src/dsl/mock_intercept.ts
|
|
5
44
|
function matchesUrlPattern(pattern, url) {
|
|
6
45
|
if (!pattern || pattern === "*" || pattern === "**" || pattern === "ALL") {
|
|
@@ -815,6 +854,11 @@ var DomDriverBridge = class {
|
|
|
815
854
|
}
|
|
816
855
|
// ─── Gestures & Keys ─────────────────────────────────────────────────────
|
|
817
856
|
async pressKey(key) {
|
|
857
|
+
const desc = describePressKey(key);
|
|
858
|
+
if (desc) {
|
|
859
|
+
await getUser().keyboard(desc.code ? `{${desc.code}}` : desc.key);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
818
862
|
const active = document.activeElement || document.body;
|
|
819
863
|
const keyName = String(key);
|
|
820
864
|
active.dispatchEvent(new KeyboardEvent("keydown", { key: keyName, bubbles: true }));
|