@testing-library/user-event 14.0.0-alpha.11 → 14.0.0-alpha.15
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/getNextKeyDef.d.ts +2 -3
- package/dist/keyboard/getNextKeyDef.js +6 -36
- package/dist/keyboard/index.d.ts +6 -17
- package/dist/keyboard/index.js +9 -43
- package/dist/keyboard/keyboardImplementation.d.ts +3 -3
- package/dist/keyboard/keyboardImplementation.js +47 -44
- 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 -12
- 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} +31 -41
- 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 -62
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- 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 -10
|
@@ -20,12 +20,15 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
20
20
|
|
|
21
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
22
|
|
|
23
|
-
async function keyboardImplementation(
|
|
24
|
-
var
|
|
23
|
+
async function keyboardImplementation(config, text) {
|
|
24
|
+
var _keyboardState$repeat;
|
|
25
25
|
|
|
26
26
|
const {
|
|
27
|
-
document
|
|
28
|
-
|
|
27
|
+
document,
|
|
28
|
+
keyboardState,
|
|
29
|
+
keyboardMap,
|
|
30
|
+
delay
|
|
31
|
+
} = config;
|
|
29
32
|
|
|
30
33
|
const getCurrentElement = () => getActive(document);
|
|
31
34
|
|
|
@@ -35,29 +38,29 @@ async function keyboardImplementation(text, options, state) {
|
|
|
35
38
|
releasePrevious,
|
|
36
39
|
releaseSelf,
|
|
37
40
|
repeat
|
|
38
|
-
} = (
|
|
39
|
-
const pressed =
|
|
41
|
+
} = (_keyboardState$repeat = keyboardState.repeatKey) != null ? _keyboardState$repeat : (0, _getNextKeyDef.getNextKeyDef)(keyboardMap, text);
|
|
42
|
+
const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
|
|
40
43
|
// Do not release the key on iterations on `state.repeatKey`.
|
|
41
44
|
|
|
42
|
-
if (pressed && !
|
|
43
|
-
keyup(keyDef, getCurrentElement,
|
|
45
|
+
if (pressed && !keyboardState.repeatKey) {
|
|
46
|
+
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
if (!releasePrevious) {
|
|
47
|
-
const unpreventedDefault = keydown(keyDef, getCurrentElement,
|
|
50
|
+
const unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
|
|
48
51
|
|
|
49
|
-
if (unpreventedDefault && hasKeyPress(keyDef,
|
|
50
|
-
keypress(keyDef, getCurrentElement,
|
|
52
|
+
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
53
|
+
await keypress(keyDef, getCurrentElement, config);
|
|
51
54
|
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
52
55
|
|
|
53
56
|
|
|
54
57
|
if (releaseSelf && repeat <= 1) {
|
|
55
|
-
keyup(keyDef, getCurrentElement,
|
|
58
|
+
await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
if (repeat > 1) {
|
|
60
|
-
|
|
63
|
+
keyboardState.repeatKey = {
|
|
61
64
|
// don't consume again on the next iteration
|
|
62
65
|
consumedLength: 0,
|
|
63
66
|
keyDef,
|
|
@@ -66,15 +69,15 @@ async function keyboardImplementation(text, options, state) {
|
|
|
66
69
|
repeat: repeat - 1
|
|
67
70
|
};
|
|
68
71
|
} else {
|
|
69
|
-
delete
|
|
72
|
+
delete keyboardState.repeatKey;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
if (text.length > consumedLength || repeat > 1) {
|
|
73
|
-
if (
|
|
74
|
-
await (0, _utils.wait)(
|
|
76
|
+
if (typeof delay === 'number') {
|
|
77
|
+
await (0, _utils.wait)(delay);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
return keyboardImplementation(text.slice(consumedLength)
|
|
80
|
+
return keyboardImplementation(config, text.slice(consumedLength));
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
return void undefined;
|
|
@@ -88,78 +91,78 @@ function getActive(document) {
|
|
|
88
91
|
document.body;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
function releaseAllKeys(
|
|
92
|
-
const getCurrentElement = () => getActive(
|
|
94
|
+
async function releaseAllKeys(config) {
|
|
95
|
+
const getCurrentElement = () => getActive(config.document);
|
|
93
96
|
|
|
94
|
-
for (const k of
|
|
95
|
-
keyup(k.keyDef, getCurrentElement,
|
|
97
|
+
for (const k of config.keyboardState.pressed) {
|
|
98
|
+
await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
function keydown(keyDef, getCurrentElement,
|
|
102
|
+
async function keydown(keyDef, getCurrentElement, config) {
|
|
100
103
|
const element = getCurrentElement(); // clear carried characters when focus is moved
|
|
101
104
|
|
|
102
|
-
if (element !==
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
if (element !== config.keyboardState.activeElement) {
|
|
106
|
+
config.keyboardState.carryValue = undefined;
|
|
107
|
+
config.keyboardState.carryChar = '';
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
|
|
108
|
-
applyPlugins(plugins.preKeydownBehavior, keyDef, element,
|
|
110
|
+
config.keyboardState.activeElement = element;
|
|
111
|
+
applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
|
|
109
112
|
|
|
110
|
-
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef,
|
|
113
|
+
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
config.keyboardState.pressed.push({
|
|
113
116
|
keyDef,
|
|
114
117
|
unpreventedDefault
|
|
115
118
|
});
|
|
116
119
|
|
|
117
120
|
if (unpreventedDefault) {
|
|
118
121
|
// all default behavior like keypress/submit etc is applied to the currentElement
|
|
119
|
-
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(),
|
|
122
|
+
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
return unpreventedDefault;
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
function keypress(keyDef, getCurrentElement,
|
|
128
|
+
async function keypress(keyDef, getCurrentElement, config) {
|
|
126
129
|
const element = getCurrentElement();
|
|
127
130
|
|
|
128
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef,
|
|
131
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
|
|
129
132
|
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
130
133
|
});
|
|
131
134
|
|
|
132
135
|
if (unpreventedDefault) {
|
|
133
|
-
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(),
|
|
136
|
+
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
function keyup(keyDef, getCurrentElement,
|
|
140
|
+
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
138
141
|
const element = getCurrentElement();
|
|
139
|
-
applyPlugins(plugins.preKeyupBehavior, keyDef, element,
|
|
142
|
+
applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
|
|
140
143
|
|
|
141
|
-
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef,
|
|
144
|
+
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
142
145
|
|
|
143
146
|
if (unprevented && unpreventedDefault) {
|
|
144
|
-
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(),
|
|
147
|
+
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
|
|
148
|
-
applyPlugins(plugins.postKeyupBehavior, keyDef, element,
|
|
150
|
+
config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
|
|
151
|
+
applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
function applyPlugins(pluginCollection, keyDef, element,
|
|
152
|
-
const plugin = pluginCollection.find(p => p.matches(keyDef, element,
|
|
154
|
+
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
155
|
+
const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
|
|
153
156
|
|
|
154
157
|
if (plugin) {
|
|
155
|
-
plugin.handle(keyDef, element,
|
|
158
|
+
plugin.handle(keyDef, element, config);
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
return !!plugin;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
|
-
function hasKeyPress(keyDef,
|
|
164
|
+
function hasKeyPress(keyDef, config) {
|
|
162
165
|
var _keyDef$key;
|
|
163
166
|
|
|
164
|
-
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !
|
|
167
|
+
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
|
|
165
168
|
}
|
|
@@ -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,3 +1,4 @@
|
|
|
1
|
+
import { Config } from '../setup';
|
|
1
2
|
import { getNextKeyDef } from './getNextKeyDef';
|
|
2
3
|
/**
|
|
3
4
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
@@ -44,16 +45,6 @@ export declare type keyboardState = {
|
|
|
44
45
|
*/
|
|
45
46
|
repeatKey?: ReturnType<typeof getNextKeyDef>;
|
|
46
47
|
};
|
|
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
|
-
};
|
|
57
48
|
export declare enum DOM_KEY_LOCATION {
|
|
58
49
|
STANDARD = 0,
|
|
59
50
|
LEFT = 1,
|
|
@@ -73,6 +64,6 @@ export interface keyboardKey {
|
|
|
73
64
|
shift?: boolean;
|
|
74
65
|
}
|
|
75
66
|
export interface behaviorPlugin {
|
|
76
|
-
matches: (keyDef: keyboardKey, element: Element,
|
|
77
|
-
handle: (keyDef: keyboardKey, element: Element,
|
|
67
|
+
matches: (keyDef: keyboardKey, element: Element, config: Config) => boolean;
|
|
68
|
+
handle: (keyDef: keyboardKey, element: Element, config: Config) => void;
|
|
78
69
|
}
|
|
@@ -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;
|