@testing-library/user-event 14.0.0-alpha.12 → 14.0.0-alpha.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/clipboard/copy.d.ts +2 -0
- package/dist/clipboard/copy.js +36 -0
- package/dist/clipboard/cut.d.ts +2 -0
- package/dist/clipboard/cut.js +42 -0
- package/dist/clipboard/index.d.ts +3 -0
- package/dist/clipboard/index.js +44 -0
- package/dist/clipboard/paste.d.ts +2 -0
- package/dist/clipboard/paste.js +47 -0
- package/dist/convenience/click.d.ts +4 -0
- package/dist/convenience/click.js +52 -0
- package/dist/convenience/hover.d.ts +3 -0
- package/dist/convenience/hover.js +31 -0
- package/dist/convenience/index.d.ts +3 -0
- package/dist/convenience/index.js +44 -0
- package/dist/convenience/tab.d.ts +4 -0
- package/dist/convenience/tab.js +12 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +7 -8
- package/dist/keyboard/index.d.ts +6 -17
- package/dist/keyboard/index.js +13 -41
- package/dist/keyboard/keyboardAction.d.ts +10 -0
- package/dist/keyboard/keyboardAction.js +156 -0
- package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -5
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/character.js +16 -10
- package/dist/keyboard/plugins/combination.js +3 -1
- package/dist/keyboard/plugins/functional.js +38 -20
- package/dist/keyboard/types.d.ts +3 -17
- package/dist/options.d.ts +102 -0
- package/dist/options.js +36 -0
- package/dist/pointer/index.d.ts +6 -14
- package/dist/pointer/index.js +8 -42
- package/dist/pointer/parseKeyDef.d.ts +2 -2
- package/dist/pointer/parseKeyDef.js +1 -3
- package/dist/pointer/pointerAction.d.ts +3 -2
- package/dist/pointer/pointerAction.js +9 -15
- package/dist/pointer/pointerMove.d.ts +2 -1
- package/dist/pointer/pointerPress.d.ts +2 -1
- package/dist/pointer/types.d.ts +0 -11
- package/dist/setup/api.d.ts +5 -0
- package/dist/setup/api.js +111 -0
- package/dist/setup/config.d.ts +10 -0
- package/dist/setup/config.js +8 -0
- package/dist/setup/directApi.d.ts +21 -0
- package/dist/setup/directApi.js +95 -0
- package/dist/setup/index.d.ts +30 -0
- package/dist/setup/index.js +27 -0
- package/dist/setup/setup.d.ts +74 -0
- package/dist/setup/setup.js +98 -0
- package/dist/setup/wrapAsync.d.ts +4 -0
- package/dist/setup/wrapAsync.js +15 -0
- package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
- package/dist/{clear.js → utility/clear.js} +2 -5
- package/dist/utility/index.d.ts +4 -0
- package/dist/utility/index.js +57 -0
- package/dist/utility/selectOptions.d.ts +3 -0
- package/dist/{selectOptions.js → utility/selectOptions.js} +15 -24
- package/dist/utility/type.d.ts +9 -0
- package/dist/utility/type.js +37 -0
- package/dist/utility/upload.d.ts +5 -0
- package/dist/{upload.js → utility/upload.js} +6 -6
- package/dist/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/utils/dataTransfer/Blob.js +21 -0
- package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/utils/dataTransfer/Clipboard.js +188 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/utils/dataTransfer/DataTransfer.js +158 -0
- package/dist/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/utils/dataTransfer/FileList.js +13 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +78 -0
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/package.json +1 -1
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -61
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -55
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -165
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/selectOptions.d.ts +0 -4
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -9
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseKeyDef = parseKeyDef;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse key defintions per `keyboardMap`
|
|
12
|
+
*
|
|
13
|
+
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
14
|
+
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
15
|
+
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
16
|
+
* Keeping the key pressed can be written as `{key>}`.
|
|
17
|
+
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
18
|
+
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
19
|
+
*/
|
|
20
|
+
function parseKeyDef(keyboardMap, text) {
|
|
21
|
+
const defs = [];
|
|
22
|
+
|
|
23
|
+
do {
|
|
24
|
+
var _keyboardMap$find;
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
type,
|
|
28
|
+
descriptor,
|
|
29
|
+
consumedLength,
|
|
30
|
+
releasePrevious,
|
|
31
|
+
releaseSelf = true,
|
|
32
|
+
repeat
|
|
33
|
+
} = (0, _utils.readNextDescriptor)(text);
|
|
34
|
+
const keyDef = (_keyboardMap$find = keyboardMap.find(def => {
|
|
35
|
+
if (type === '[') {
|
|
36
|
+
var _def$code;
|
|
37
|
+
|
|
38
|
+
return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
|
|
39
|
+
} else if (type === '{') {
|
|
40
|
+
var _def$key;
|
|
41
|
+
|
|
42
|
+
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return def.key === descriptor;
|
|
46
|
+
})) != null ? _keyboardMap$find : {
|
|
47
|
+
key: 'Unknown',
|
|
48
|
+
code: 'Unknown',
|
|
49
|
+
[type === '[' ? 'code' : 'key']: descriptor
|
|
50
|
+
};
|
|
51
|
+
defs.push({
|
|
52
|
+
keyDef,
|
|
53
|
+
releasePrevious,
|
|
54
|
+
releaseSelf,
|
|
55
|
+
repeat
|
|
56
|
+
});
|
|
57
|
+
text = text.slice(consumedLength);
|
|
58
|
+
} while (text);
|
|
59
|
+
|
|
60
|
+
return defs;
|
|
61
|
+
}
|
|
@@ -23,11 +23,13 @@ const keypressBehavior = [{
|
|
|
23
23
|
readOnly: false
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
|
-
handle: (keyDef, element,
|
|
27
|
-
|
|
26
|
+
handle: (keyDef, element, {
|
|
27
|
+
keyboardState
|
|
28
|
+
}) => {
|
|
29
|
+
var _keyboardState$carryV;
|
|
28
30
|
|
|
29
31
|
let newEntry = keyDef.key;
|
|
30
|
-
const textToBeTyped = ((
|
|
32
|
+
const textToBeTyped = ((_keyboardState$carryV = keyboardState.carryValue) != null ? _keyboardState$carryV : '') + newEntry;
|
|
31
33
|
const timeNewEntry = (0, _utils.buildTimeValue)(textToBeTyped);
|
|
32
34
|
|
|
33
35
|
if ((0, _utils.isValidInputTimeValue)(element, timeNewEntry)) {
|
|
@@ -56,7 +58,7 @@ const keypressBehavior = [{
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
(0, _shared.fireChangeForInputTimeIfValid)(element, prevValue, timeNewEntry);
|
|
59
|
-
|
|
61
|
+
keyboardState.carryValue = textToBeTyped;
|
|
60
62
|
}
|
|
61
63
|
}, {
|
|
62
64
|
matches: (keyDef, element) => {
|
|
@@ -67,11 +69,13 @@ const keypressBehavior = [{
|
|
|
67
69
|
readOnly: false
|
|
68
70
|
});
|
|
69
71
|
},
|
|
70
|
-
handle: (keyDef, element,
|
|
71
|
-
|
|
72
|
+
handle: (keyDef, element, {
|
|
73
|
+
keyboardState
|
|
74
|
+
}) => {
|
|
75
|
+
var _keyboardState$carryV2;
|
|
72
76
|
|
|
73
77
|
let newEntry = keyDef.key;
|
|
74
|
-
const textToBeTyped = ((
|
|
78
|
+
const textToBeTyped = ((_keyboardState$carryV2 = keyboardState.carryValue) != null ? _keyboardState$carryV2 : '') + newEntry;
|
|
75
79
|
const isValidToBeTyped = (0, _utils.isValidDateValue)(element, textToBeTyped);
|
|
76
80
|
|
|
77
81
|
if (isValidToBeTyped) {
|
|
@@ -107,7 +111,7 @@ const keypressBehavior = [{
|
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
keyboardState.carryValue = textToBeTyped;
|
|
111
115
|
}
|
|
112
116
|
}, {
|
|
113
117
|
matches: (keyDef, element) => {
|
|
@@ -158,10 +162,12 @@ const keypressBehavior = [{
|
|
|
158
162
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
159
163
|
readOnly: false
|
|
160
164
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
161
|
-
handle: (keyDef, element,
|
|
165
|
+
handle: (keyDef, element, {
|
|
166
|
+
keyboardState
|
|
167
|
+
}) => {
|
|
162
168
|
var _prepareInput2;
|
|
163
169
|
|
|
164
|
-
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !
|
|
170
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !keyboardState.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
165
171
|
}
|
|
166
172
|
}];
|
|
167
173
|
exports.keypressBehavior = keypressBehavior;
|
|
@@ -11,7 +11,9 @@ var _utils = require("../../utils");
|
|
|
11
11
|
* Default behavior for key combinations
|
|
12
12
|
*/
|
|
13
13
|
const keydownBehavior = [{
|
|
14
|
-
matches: (keyDef, element,
|
|
14
|
+
matches: (keyDef, element, {
|
|
15
|
+
keyboardState
|
|
16
|
+
}) => keyDef.code === 'KeyA' && keyboardState.modifiers.ctrl,
|
|
15
17
|
handle: (keyDef, element) => (0, _utils.selectAll)(element)
|
|
16
18
|
}];
|
|
17
19
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -26,31 +26,38 @@ const modifierKeys = {
|
|
|
26
26
|
const preKeydownBehavior = [// modifierKeys switch on the modifier BEFORE the keydown event
|
|
27
27
|
...Object.entries(modifierKeys).map(([key, modKey]) => ({
|
|
28
28
|
matches: keyDef => keyDef.key === key,
|
|
29
|
-
handle: (keyDef, element,
|
|
30
|
-
|
|
29
|
+
handle: (keyDef, element, {
|
|
30
|
+
keyboardState
|
|
31
|
+
}) => {
|
|
32
|
+
keyboardState.modifiers[modKey] = true;
|
|
31
33
|
}
|
|
32
34
|
})), // AltGraph produces an extra keydown for Control
|
|
33
35
|
// The modifier does not change
|
|
34
36
|
{
|
|
35
37
|
matches: keyDef => keyDef.key === 'AltGraph',
|
|
36
|
-
handle: (keyDef, element,
|
|
37
|
-
|
|
38
|
+
handle: (keyDef, element, {
|
|
39
|
+
keyboardMap,
|
|
40
|
+
keyboardState
|
|
41
|
+
}) => {
|
|
42
|
+
var _keyboardMap$find;
|
|
38
43
|
|
|
39
|
-
const ctrlKeyDef = (
|
|
44
|
+
const ctrlKeyDef = (_keyboardMap$find = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find :
|
|
40
45
|
/* istanbul ignore next */
|
|
41
46
|
{
|
|
42
47
|
key: 'Control',
|
|
43
48
|
code: 'Control'
|
|
44
49
|
};
|
|
45
50
|
|
|
46
|
-
_dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef,
|
|
51
|
+
_dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
|
|
47
52
|
}
|
|
48
53
|
}];
|
|
49
54
|
exports.preKeydownBehavior = preKeydownBehavior;
|
|
50
55
|
const keydownBehavior = [{
|
|
51
56
|
matches: keyDef => keyDef.key === 'CapsLock',
|
|
52
|
-
handle: (keyDef, element,
|
|
53
|
-
|
|
57
|
+
handle: (keyDef, element, {
|
|
58
|
+
keyboardState
|
|
59
|
+
}) => {
|
|
60
|
+
keyboardState.modifiers.caps = !keyboardState.modifiers.caps;
|
|
54
61
|
}
|
|
55
62
|
}, {
|
|
56
63
|
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
@@ -61,8 +68,10 @@ const keydownBehavior = [{
|
|
|
61
68
|
}
|
|
62
69
|
}, {
|
|
63
70
|
matches: keyDef => keyDef.key === 'Tab',
|
|
64
|
-
handle: (keyDef, element,
|
|
65
|
-
|
|
71
|
+
handle: (keyDef, element, {
|
|
72
|
+
keyboardState
|
|
73
|
+
}) => {
|
|
74
|
+
const dest = (0, _utils.getTabDestination)(element, keyboardState.modifiers.shift);
|
|
66
75
|
|
|
67
76
|
if (dest === element.ownerDocument.body) {
|
|
68
77
|
(0, _utils.blur)(element);
|
|
@@ -91,8 +100,10 @@ const keypressBehavior = [{
|
|
|
91
100
|
}, {
|
|
92
101
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isClickableInput)(element) || // Links with href defined should handle Enter the same as a click
|
|
93
102
|
(0, _utils.isElementType)(element, 'a') && Boolean(element.href)),
|
|
94
|
-
handle: (keyDef, element,
|
|
95
|
-
|
|
103
|
+
handle: (keyDef, element, {
|
|
104
|
+
keyboardState
|
|
105
|
+
}) => {
|
|
106
|
+
_dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
|
|
96
107
|
}
|
|
97
108
|
}, {
|
|
98
109
|
matches: (keyDef, element) => keyDef.key === 'Enter' && (0, _utils.isElementType)(element, 'input'),
|
|
@@ -108,15 +119,19 @@ exports.keypressBehavior = keypressBehavior;
|
|
|
108
119
|
const preKeyupBehavior = [// modifierKeys switch off the modifier BEFORE the keyup event
|
|
109
120
|
...Object.entries(modifierKeys).map(([key, modKey]) => ({
|
|
110
121
|
matches: keyDef => keyDef.key === key,
|
|
111
|
-
handle: (keyDef, element,
|
|
112
|
-
|
|
122
|
+
handle: (keyDef, element, {
|
|
123
|
+
keyboardState
|
|
124
|
+
}) => {
|
|
125
|
+
keyboardState.modifiers[modKey] = false;
|
|
113
126
|
}
|
|
114
127
|
}))];
|
|
115
128
|
exports.preKeyupBehavior = preKeyupBehavior;
|
|
116
129
|
const keyupBehavior = [{
|
|
117
130
|
matches: (keyDef, element) => keyDef.key === ' ' && (0, _utils.isClickableInput)(element),
|
|
118
|
-
handle: (keyDef, element,
|
|
119
|
-
|
|
131
|
+
handle: (keyDef, element, {
|
|
132
|
+
keyboardState
|
|
133
|
+
}) => {
|
|
134
|
+
_dom.fireEvent.click(element, (0, _getEventProps.getMouseEventProps)(keyboardState));
|
|
120
135
|
}
|
|
121
136
|
}];
|
|
122
137
|
exports.keyupBehavior = keyupBehavior;
|
|
@@ -124,17 +139,20 @@ const postKeyupBehavior = [// AltGraph produces an extra keyup for Control
|
|
|
124
139
|
// The modifier does not change
|
|
125
140
|
{
|
|
126
141
|
matches: keyDef => keyDef.key === 'AltGraph',
|
|
127
|
-
handle: (keyDef, element,
|
|
128
|
-
|
|
142
|
+
handle: (keyDef, element, {
|
|
143
|
+
keyboardMap,
|
|
144
|
+
keyboardState
|
|
145
|
+
}) => {
|
|
146
|
+
var _keyboardMap$find2;
|
|
129
147
|
|
|
130
|
-
const ctrlKeyDef = (
|
|
148
|
+
const ctrlKeyDef = (_keyboardMap$find2 = keyboardMap.find(k => k.key === 'Control')) != null ? _keyboardMap$find2 :
|
|
131
149
|
/* istanbul ignore next */
|
|
132
150
|
{
|
|
133
151
|
key: 'Control',
|
|
134
152
|
code: 'Control'
|
|
135
153
|
};
|
|
136
154
|
|
|
137
|
-
_dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef,
|
|
155
|
+
_dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(ctrlKeyDef, keyboardState));
|
|
138
156
|
}
|
|
139
157
|
}];
|
|
140
158
|
exports.postKeyupBehavior = postKeyupBehavior;
|
package/dist/keyboard/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Config } from '../setup';
|
|
2
2
|
/**
|
|
3
3
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
4
4
|
*/
|
|
@@ -39,20 +39,6 @@ export declare type keyboardState = {
|
|
|
39
39
|
E.g. ^1
|
|
40
40
|
*/
|
|
41
41
|
carryChar: string;
|
|
42
|
-
/**
|
|
43
|
-
Repeat keydown and keypress event
|
|
44
|
-
*/
|
|
45
|
-
repeatKey?: ReturnType<typeof getNextKeyDef>;
|
|
46
|
-
};
|
|
47
|
-
export declare type keyboardOptions = {
|
|
48
|
-
/** Document in which to perform the events */
|
|
49
|
-
document: Document;
|
|
50
|
-
/** Delay between keystrokes */
|
|
51
|
-
delay: number;
|
|
52
|
-
/** Add modifiers for given keys - not implemented yet */
|
|
53
|
-
autoModify: boolean;
|
|
54
|
-
/** Keyboard layout to use */
|
|
55
|
-
keyboardMap: keyboardKey[];
|
|
56
42
|
};
|
|
57
43
|
export declare enum DOM_KEY_LOCATION {
|
|
58
44
|
STANDARD = 0,
|
|
@@ -73,6 +59,6 @@ export interface keyboardKey {
|
|
|
73
59
|
shift?: boolean;
|
|
74
60
|
}
|
|
75
61
|
export interface behaviorPlugin {
|
|
76
|
-
matches: (keyDef: keyboardKey, element: Element,
|
|
77
|
-
handle: (keyDef: keyboardKey, element: Element,
|
|
62
|
+
matches: (keyDef: keyboardKey, element: Element, config: Config) => boolean;
|
|
63
|
+
handle: (keyDef: keyboardKey, element: Element, config: Config) => void;
|
|
78
64
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { keyboardKey } from './keyboard/types';
|
|
2
|
+
import type { pointerKey } from './pointer/types';
|
|
3
|
+
export interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* When using `userEvent.upload`, automatically discard files
|
|
6
|
+
* that don't match an `accept` property if it exists.
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
applyAccept?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* We intend to automatically apply modifier keys for printable characters in the future.
|
|
13
|
+
* I.e. `A` implying `{Shift>}a{/Shift}` if caps lock is not active.
|
|
14
|
+
*
|
|
15
|
+
* This options allows you to opt out of this change in foresight.
|
|
16
|
+
* The feature therefore will not constitute a breaking change.
|
|
17
|
+
*
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
autoModify?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Between some subsequent inputs like typing a series of characters
|
|
23
|
+
* the code execution is delayed per `setTimeout` for (at least) `delay` seconds.
|
|
24
|
+
* This moves the next changes at least to next macro task
|
|
25
|
+
* and allows other (asynchronous) code to run between events.
|
|
26
|
+
*
|
|
27
|
+
* `null` prevents `setTimeout` from being called.
|
|
28
|
+
*
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
delay?: number | null;
|
|
32
|
+
/**
|
|
33
|
+
* The document.
|
|
34
|
+
*
|
|
35
|
+
* This defaults to the owner document of an element if an API is called directly with an element and without setup.
|
|
36
|
+
* Otherwise it falls back to the global document.
|
|
37
|
+
*
|
|
38
|
+
* @default element.ownerDocument??global.document
|
|
39
|
+
*/
|
|
40
|
+
document?: Document;
|
|
41
|
+
/**
|
|
42
|
+
* An array of keyboard keys the keyboard device consists of.
|
|
43
|
+
*
|
|
44
|
+
* This allows to plug in different layouts / localizations.
|
|
45
|
+
*
|
|
46
|
+
* Defaults to a "standard" US-104-QWERTY keyboard.
|
|
47
|
+
*/
|
|
48
|
+
keyboardMap?: keyboardKey[];
|
|
49
|
+
/**
|
|
50
|
+
* An array of available pointer keys.
|
|
51
|
+
*
|
|
52
|
+
* This allows to plug in different pointer devices.
|
|
53
|
+
*/
|
|
54
|
+
pointerMap?: pointerKey[];
|
|
55
|
+
/**
|
|
56
|
+
* `userEvent.type` automatically releases any keys still pressed at the end of the call.
|
|
57
|
+
* This option allows to opt out of this feature.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
skipAutoClose?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* `userEvent.type` implys a click at the end of the element content/value.
|
|
64
|
+
* This option allows to opt out of this feature.
|
|
65
|
+
*
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
skipClick?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `userEvent.click` implys moving the cursor to the target element first.
|
|
71
|
+
* This options allows to opt out of this feature.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
skipHover?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Calling pointer related APIs on an element triggers a check if that element can receive pointer events.
|
|
78
|
+
* This check is known to be expensive.
|
|
79
|
+
* This option allows to skip the check.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
skipPointerEventsCheck?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Write selected data to Clipboard API when a `cut` or `copy` is triggered.
|
|
86
|
+
*
|
|
87
|
+
* The Clipboard API is usually not available to test code.
|
|
88
|
+
* Our `setup` replaces the `navigator.clipboard` property with a stub.
|
|
89
|
+
*
|
|
90
|
+
* Defaults to `false` when calling the APIs directly.
|
|
91
|
+
* Defaults to `true` when calling the APIs per `setup`.
|
|
92
|
+
*/
|
|
93
|
+
writeToClipboard?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Default options applied when API is called per `userEvent.anyApi()`
|
|
97
|
+
*/
|
|
98
|
+
export declare const defaultOptionsDirect: Required<Options>;
|
|
99
|
+
/**
|
|
100
|
+
* Default options applied when API is called per `userEvent().anyApi()`
|
|
101
|
+
*/
|
|
102
|
+
export declare const defaultOptionsSetup: Required<Options>;
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultOptionsSetup = exports.defaultOptionsDirect = void 0;
|
|
7
|
+
|
|
8
|
+
var _keyMap = require("./keyboard/keyMap");
|
|
9
|
+
|
|
10
|
+
var _keyMap2 = require("./pointer/keyMap");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default options applied when API is called per `userEvent.anyApi()`
|
|
14
|
+
*/
|
|
15
|
+
const defaultOptionsDirect = {
|
|
16
|
+
applyAccept: true,
|
|
17
|
+
autoModify: true,
|
|
18
|
+
delay: 0,
|
|
19
|
+
document: global.document,
|
|
20
|
+
keyboardMap: _keyMap.defaultKeyMap,
|
|
21
|
+
pointerMap: _keyMap2.defaultKeyMap,
|
|
22
|
+
skipAutoClose: false,
|
|
23
|
+
skipClick: false,
|
|
24
|
+
skipHover: false,
|
|
25
|
+
skipPointerEventsCheck: false,
|
|
26
|
+
writeToClipboard: false
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Default options applied when API is called per `userEvent().anyApi()`
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
exports.defaultOptionsDirect = defaultOptionsDirect;
|
|
33
|
+
const defaultOptionsSetup = { ...defaultOptionsDirect,
|
|
34
|
+
writeToClipboard: true
|
|
35
|
+
};
|
|
36
|
+
exports.defaultOptionsSetup = defaultOptionsSetup;
|
package/dist/pointer/index.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import { UserEvent } from '../setup';
|
|
1
2
|
import { PointerAction, PointerActionTarget } from './pointerAction';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
delay: 0;
|
|
5
|
-
} & inputDeviceState>): pointerState;
|
|
6
|
-
export declare function pointer(input: PointerInput, options: Partial<pointerOptions & {
|
|
7
|
-
delay: number;
|
|
8
|
-
} & inputDeviceState>): Promise<pointerState>;
|
|
3
|
+
import type { pointerState, pointerKey } from './types';
|
|
4
|
+
export type { pointerState, pointerKey };
|
|
9
5
|
declare type PointerActionInput = string | ({
|
|
10
6
|
keys: string;
|
|
11
7
|
} & PointerActionTarget) | PointerAction;
|
|
12
|
-
declare type PointerInput = PointerActionInput | Array<PointerActionInput>;
|
|
13
|
-
export declare function
|
|
14
|
-
|
|
15
|
-
pointerState: pointerState;
|
|
16
|
-
};
|
|
17
|
-
export declare function createPointerState(): pointerState;
|
|
18
|
-
export {};
|
|
8
|
+
export declare type PointerInput = PointerActionInput | Array<PointerActionInput>;
|
|
9
|
+
export declare function pointer(this: UserEvent, input: PointerInput): Promise<void>;
|
|
10
|
+
export declare function createPointerState(document: Document): pointerState;
|
package/dist/pointer/index.js
CHANGED
|
@@ -5,74 +5,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createPointerState = createPointerState;
|
|
7
7
|
exports.pointer = pointer;
|
|
8
|
-
exports.pointerImplementationWrapper = pointerImplementationWrapper;
|
|
9
8
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _keyboard = require("../keyboard");
|
|
9
|
+
var _setup = require("../setup");
|
|
13
10
|
|
|
14
11
|
var _parseKeyDef = require("./parseKeyDef");
|
|
15
12
|
|
|
16
|
-
var _keyMap = require("./keyMap");
|
|
17
|
-
|
|
18
13
|
var _pointerAction = require("./pointerAction");
|
|
19
14
|
|
|
20
|
-
function pointer(input
|
|
21
|
-
var _options$delay;
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
promise,
|
|
25
|
-
pointerState
|
|
26
|
-
} = pointerImplementationWrapper(input, options);
|
|
27
|
-
|
|
28
|
-
if (((_options$delay = options.delay) != null ? _options$delay : 0) > 0) {
|
|
29
|
-
return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => pointerState));
|
|
30
|
-
} else {
|
|
31
|
-
// prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
|
|
32
|
-
promise.catch(console.error);
|
|
33
|
-
return pointerState;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function pointerImplementationWrapper(input, config) {
|
|
15
|
+
async function pointer(input) {
|
|
38
16
|
const {
|
|
39
|
-
pointerState = createPointerState(),
|
|
40
|
-
keyboardState = (0, _keyboard.createKeyboardState)(),
|
|
41
|
-
delay = 0,
|
|
42
|
-
pointerMap = _keyMap.defaultKeyMap
|
|
43
|
-
} = config;
|
|
44
|
-
const options = {
|
|
45
|
-
delay,
|
|
46
17
|
pointerMap
|
|
47
|
-
};
|
|
18
|
+
} = this[_setup.Config];
|
|
48
19
|
const actions = [];
|
|
49
20
|
(Array.isArray(input) ? input : [input]).forEach(actionInput => {
|
|
50
21
|
if (typeof actionInput === 'string') {
|
|
51
|
-
actions.push(...(0, _parseKeyDef.parseKeyDef)(
|
|
22
|
+
actions.push(...(0, _parseKeyDef.parseKeyDef)(pointerMap, actionInput));
|
|
52
23
|
} else if ('keys' in actionInput) {
|
|
53
|
-
actions.push(...(0, _parseKeyDef.parseKeyDef)(actionInput.keys
|
|
24
|
+
actions.push(...(0, _parseKeyDef.parseKeyDef)(pointerMap, actionInput.keys).map(i => ({ ...actionInput,
|
|
54
25
|
...i
|
|
55
26
|
})));
|
|
56
27
|
} else {
|
|
57
28
|
actions.push(actionInput);
|
|
58
29
|
}
|
|
59
30
|
});
|
|
60
|
-
return
|
|
61
|
-
promise: (0, _pointerAction.pointerAction)(actions, options, {
|
|
62
|
-
pointerState,
|
|
63
|
-
keyboardState
|
|
64
|
-
}),
|
|
65
|
-
pointerState
|
|
66
|
-
};
|
|
31
|
+
return (0, _pointerAction.pointerAction)(this[_setup.Config], actions).then(() => undefined);
|
|
67
32
|
}
|
|
68
33
|
|
|
69
|
-
function createPointerState() {
|
|
34
|
+
function createPointerState(document) {
|
|
70
35
|
return {
|
|
71
36
|
pointerId: 1,
|
|
72
37
|
position: {
|
|
73
38
|
mouse: {
|
|
74
39
|
pointerType: 'mouse',
|
|
75
40
|
pointerId: 1,
|
|
41
|
+
target: document.body,
|
|
76
42
|
coords: {
|
|
77
43
|
clientX: 0,
|
|
78
44
|
clientY: 0,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { pointerKey
|
|
2
|
-
export declare function parseKeyDef(
|
|
1
|
+
import { pointerKey } from './types';
|
|
2
|
+
export declare function parseKeyDef(pointerMap: pointerKey[], keys: string): {
|
|
3
3
|
keyDef: pointerKey;
|
|
4
4
|
releasePrevious: boolean;
|
|
5
5
|
releaseSelf: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Config } from '../setup';
|
|
1
2
|
import { PointerMoveAction } from './pointerMove';
|
|
2
3
|
import { PointerPressAction } from './pointerPress';
|
|
3
|
-
import {
|
|
4
|
+
import { PointerTarget, SelectionTarget } from './types';
|
|
4
5
|
export declare type PointerActionTarget = Partial<PointerTarget> & Partial<SelectionTarget>;
|
|
5
6
|
export declare type PointerAction = PointerActionTarget & (Omit<PointerPressAction, 'target' | 'coords'> | Omit<PointerMoveAction, 'target' | 'coords'>);
|
|
6
|
-
export declare function pointerAction(actions: PointerAction[]
|
|
7
|
+
export declare function pointerAction(config: Config, actions: PointerAction[]): Promise<void>;
|
|
@@ -11,36 +11,30 @@ var _pointerMove = require("./pointerMove");
|
|
|
11
11
|
|
|
12
12
|
var _pointerPress = require("./pointerPress");
|
|
13
13
|
|
|
14
|
-
async function pointerAction(
|
|
15
|
-
const ret = [];
|
|
16
|
-
|
|
14
|
+
async function pointerAction(config, actions) {
|
|
17
15
|
for (let i = 0; i < actions.length; i++) {
|
|
18
16
|
var _action$target, _action$coords;
|
|
19
17
|
|
|
20
18
|
const action = actions[i];
|
|
21
19
|
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? action.keyDef.pointerType === 'touch' ? action.keyDef.name : action.keyDef.pointerType : 'mouse';
|
|
22
|
-
const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName,
|
|
23
|
-
const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in
|
|
24
|
-
|
|
20
|
+
const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, config.pointerState);
|
|
21
|
+
const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : undefined;
|
|
22
|
+
await ('keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
|
|
25
23
|
target,
|
|
26
24
|
coords
|
|
27
|
-
},
|
|
25
|
+
}, config) : (0, _pointerMove.pointerMove)({ ...action,
|
|
28
26
|
target,
|
|
29
27
|
coords
|
|
30
|
-
},
|
|
31
|
-
ret.push(promise);
|
|
32
|
-
|
|
33
|
-
if (options.delay > 0) {
|
|
34
|
-
await promise;
|
|
28
|
+
}, config));
|
|
35
29
|
|
|
30
|
+
if (typeof config.delay === 'number') {
|
|
36
31
|
if (i < actions.length - 1) {
|
|
37
|
-
await (0, _utils.wait)(
|
|
32
|
+
await (0, _utils.wait)(config.delay);
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
delete
|
|
43
|
-
return Promise.all(ret);
|
|
37
|
+
delete config.pointerState.activeClickCount;
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
function getPrevTarget(pointerName, state) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { inputDeviceState
|
|
1
|
+
import { inputDeviceState } from '../setup';
|
|
2
|
+
import { PointerTarget, SelectionTarget } from './types';
|
|
2
3
|
export interface PointerMoveAction extends PointerTarget, SelectionTarget {
|
|
3
4
|
pointerName?: string;
|
|
4
5
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { inputDeviceState } from '../setup';
|
|
2
|
+
import type { pointerKey, PointerTarget, SelectionTarget } from './types';
|
|
2
3
|
export interface PointerPressAction extends PointerTarget, SelectionTarget {
|
|
3
4
|
keyDef: pointerKey;
|
|
4
5
|
releasePrevious: boolean;
|
package/dist/pointer/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { keyboardState } from '../keyboard/types';
|
|
2
1
|
import { PointerCoords, MouseButton } from '../utils';
|
|
3
2
|
/**
|
|
4
3
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
@@ -34,12 +33,6 @@ export declare type pointerState = {
|
|
|
34
33
|
*/
|
|
35
34
|
pointerId: number;
|
|
36
35
|
};
|
|
37
|
-
export declare type pointerOptions = {
|
|
38
|
-
/** Delay between keystrokes */
|
|
39
|
-
delay: number;
|
|
40
|
-
/** Available pointer keys */
|
|
41
|
-
pointerMap: pointerKey[];
|
|
42
|
-
};
|
|
43
36
|
export interface pointerKey {
|
|
44
37
|
/** Name of the pointer key */
|
|
45
38
|
name: string;
|
|
@@ -66,7 +59,3 @@ export interface SelectionInputRange {
|
|
|
66
59
|
start: number;
|
|
67
60
|
end: number;
|
|
68
61
|
}
|
|
69
|
-
export interface inputDeviceState {
|
|
70
|
-
pointerState: pointerState;
|
|
71
|
-
keyboardState: keyboardState;
|
|
72
|
-
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { click, dblClick, tripleClick, hover, unhover, tab } from '../convenience';
|
|
2
|
+
export { keyboard } from '../keyboard';
|
|
3
|
+
export { copy, cut, paste } from '../clipboard';
|
|
4
|
+
export { pointer } from '../pointer';
|
|
5
|
+
export { clear, deselectOptions, selectOptions, type, upload } from '../utility';
|