@testing-library/user-event 14.2.5 → 14.4.0
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/cjs/clipboard/copy.js +40 -0
- package/dist/cjs/clipboard/cut.js +40 -0
- package/dist/cjs/clipboard/index.js +13 -0
- package/dist/cjs/clipboard/paste.js +41 -0
- package/dist/cjs/convenience/click.js +40 -0
- package/dist/cjs/convenience/hover.js +37 -0
- package/dist/cjs/convenience/index.js +16 -0
- package/dist/cjs/convenience/tab.js +9 -0
- package/dist/cjs/document/index.js +74 -0
- package/dist/cjs/document/interceptor.js +30 -0
- package/dist/cjs/document/selection.js +107 -0
- package/dist/cjs/document/setRangeText.js +21 -0
- package/dist/cjs/document/value.js +125 -0
- package/dist/cjs/event/behavior/click.js +42 -0
- package/dist/cjs/event/behavior/cut.js +26 -0
- package/dist/cjs/event/behavior/index.js +15 -0
- package/dist/cjs/event/behavior/keydown.js +134 -0
- package/dist/cjs/event/behavior/keypress.js +58 -0
- package/dist/cjs/event/behavior/keyup.js +24 -0
- package/dist/cjs/event/behavior/paste.js +29 -0
- package/dist/cjs/event/behavior/registry.js +7 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +37 -0
- package/dist/cjs/event/dom-events.d.js +2 -0
- package/dist/cjs/event/eventMap.js +64 -0
- package/dist/cjs/event/index.js +24 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +11 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/keyboard/index.js +59 -0
- package/dist/cjs/keyboard/keyMap.js +158 -0
- package/dist/cjs/keyboard/parseKeyDef.js +58 -0
- package/dist/cjs/options.js +42 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +88 -0
- package/dist/cjs/pointer/keyMap.js +35 -0
- package/dist/cjs/pointer/parseKeyDef.js +39 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/config.js +7 -0
- package/dist/cjs/setup/directApi.js +77 -0
- package/dist/cjs/setup/index.js +15 -0
- package/dist/cjs/setup/setup.js +97 -0
- package/dist/cjs/setup/wrapAsync.js +13 -0
- package/dist/cjs/system/index.js +31 -0
- package/dist/cjs/system/keyboard.js +135 -0
- package/dist/cjs/system/pointer/buttons.js +71 -0
- package/dist/cjs/system/pointer/device.js +21 -0
- package/dist/cjs/system/pointer/index.js +146 -0
- package/dist/cjs/system/pointer/mouse.js +186 -0
- package/dist/cjs/system/pointer/pointer.js +114 -0
- package/dist/cjs/utility/clear.js +42 -0
- package/dist/cjs/utility/index.js +16 -0
- package/dist/cjs/utility/selectOptions.js +125 -0
- package/dist/cjs/utility/type.js +41 -0
- package/dist/cjs/utility/upload.js +72 -0
- package/dist/cjs/utils/click/isClickableInput.js +22 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +18 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +168 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +124 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +26 -0
- package/dist/cjs/utils/edit/buildTimeValue.js +36 -0
- package/dist/cjs/utils/edit/getValue.js +35 -0
- package/dist/cjs/utils/edit/input.js +162 -0
- package/dist/cjs/utils/edit/isContentEditable.js +20 -0
- package/dist/cjs/utils/edit/isEditable.js +35 -0
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +11 -0
- package/dist/cjs/utils/edit/maxLength.js +38 -0
- package/dist/cjs/utils/edit/setFiles.js +59 -0
- package/dist/cjs/utils/edit/walkRadio.js +28 -0
- package/dist/cjs/utils/focus/blur.js +16 -0
- package/dist/cjs/utils/focus/copySelection.js +46 -0
- package/dist/cjs/utils/focus/cursor.js +143 -0
- package/dist/cjs/utils/focus/focus.js +26 -0
- package/dist/cjs/utils/focus/getActiveElement.js +24 -0
- package/dist/cjs/utils/focus/getTabDestination.js +82 -0
- package/dist/cjs/utils/focus/isFocusable.js +11 -0
- package/dist/cjs/utils/focus/resolveCaretPosition.js +78 -0
- package/dist/cjs/utils/focus/selectAll.js +54 -0
- package/dist/cjs/utils/focus/selection.js +287 -0
- package/dist/cjs/utils/focus/selector.js +16 -0
- package/dist/cjs/utils/index.js +108 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +92 -0
- package/dist/cjs/utils/misc/cloneEvent.js +9 -0
- package/dist/cjs/utils/misc/dom-helpers.d.js +2 -0
- package/dist/cjs/utils/misc/eventWrapper.js +15 -0
- package/dist/cjs/utils/misc/findClosest.js +16 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +12 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +27 -0
- package/dist/cjs/utils/misc/getWindow.js +11 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +16 -0
- package/dist/cjs/utils/misc/isDisabled.js +34 -0
- package/dist/cjs/utils/misc/isElementType.js +22 -0
- package/dist/cjs/utils/misc/isVisible.js +21 -0
- package/dist/cjs/utils/misc/level.js +20 -0
- package/dist/cjs/utils/misc/wait.js +16 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +111 -0
- package/dist/esm/clipboard/copy.js +36 -0
- package/dist/esm/clipboard/cut.js +36 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +37 -0
- package/dist/esm/convenience/click.js +34 -0
- package/dist/esm/convenience/hover.js +32 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/index.js +66 -0
- package/dist/esm/document/interceptor.js +26 -0
- package/dist/esm/document/selection.js +99 -0
- package/dist/esm/document/setRangeText.js +17 -0
- package/dist/esm/document/value.js +115 -0
- package/dist/esm/event/behavior/click.js +40 -0
- package/dist/esm/event/behavior/cut.js +24 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +132 -0
- package/dist/esm/event/behavior/keypress.js +56 -0
- package/dist/esm/event/behavior/keyup.js +22 -0
- package/dist/esm/event/behavior/paste.js +27 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +189 -0
- package/dist/esm/event/dispatchEvent.js +33 -0
- package/dist/esm/event/dom-events.d.js +1 -0
- package/dist/esm/event/eventMap.js +57 -0
- package/dist/esm/event/index.js +19 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +54 -0
- package/dist/esm/keyboard/keyMap.js +154 -0
- package/dist/esm/keyboard/parseKeyDef.js +54 -0
- package/dist/esm/options.js +37 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +84 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +35 -0
- package/dist/esm/setup/api.js +12 -0
- package/dist/esm/setup/config.js +3 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +10 -0
- package/dist/esm/setup/setup.js +90 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +27 -0
- package/dist/esm/system/keyboard.js +131 -0
- package/dist/esm/system/pointer/buttons.js +63 -0
- package/dist/esm/system/pointer/device.js +17 -0
- package/dist/esm/system/pointer/index.js +141 -0
- package/dist/esm/system/pointer/mouse.js +182 -0
- package/dist/esm/system/pointer/pointer.js +110 -0
- package/dist/esm/utility/clear.js +38 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +120 -0
- package/dist/esm/utility/type.js +37 -0
- package/dist/esm/utility/upload.js +68 -0
- package/dist/esm/utils/click/isClickableInput.js +18 -0
- package/dist/esm/utils/dataTransfer/Blob.js +14 -0
- package/dist/esm/utils/dataTransfer/Clipboard.js +159 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +119 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/buildTimeValue.js +32 -0
- package/dist/esm/utils/edit/getValue.js +31 -0
- package/dist/esm/utils/edit/input.js +158 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +30 -0
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +7 -0
- package/dist/esm/utils/edit/maxLength.js +34 -0
- package/dist/esm/utils/edit/setFiles.js +55 -0
- package/dist/esm/utils/edit/walkRadio.js +24 -0
- package/dist/esm/utils/focus/blur.js +12 -0
- package/dist/esm/utils/focus/copySelection.js +42 -0
- package/dist/esm/utils/focus/cursor.js +139 -0
- package/dist/esm/utils/focus/focus.js +22 -0
- package/dist/esm/utils/focus/getActiveElement.js +19 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/resolveCaretPosition.js +74 -0
- package/dist/esm/utils/focus/selectAll.js +49 -0
- package/dist/esm/utils/focus/selection.js +274 -0
- package/dist/esm/utils/focus/selector.js +12 -0
- package/dist/esm/utils/index.js +36 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +88 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/dom-helpers.d.js +1 -0
- package/dist/esm/utils/misc/eventWrapper.js +11 -0
- package/dist/esm/utils/misc/findClosest.js +12 -0
- package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
- package/dist/esm/utils/misc/getTreeDiff.js +23 -0
- package/dist/esm/utils/misc/getWindow.js +7 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +30 -0
- package/dist/esm/utils/misc/isElementType.js +18 -0
- package/dist/esm/utils/misc/isVisible.js +17 -0
- package/dist/esm/utils/misc/level.js +15 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +106 -0
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/document/selection.d.ts +1 -0
- package/dist/types/document/value.d.ts +4 -5
- package/dist/types/event/createEvent.d.ts +2 -8
- package/dist/types/event/eventMap.d.ts +204 -181
- package/dist/types/event/index.d.ts +1 -2
- package/dist/types/event/types.d.ts +6 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/keyboard/index.d.ts +2 -6
- package/dist/types/keyboard/keyMap.d.ts +1 -1
- package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
- package/dist/types/options.d.ts +4 -4
- package/dist/types/pointer/index.d.ts +23 -5
- package/dist/types/pointer/keyMap.d.ts +1 -1
- package/dist/types/pointer/parseKeyDef.d.ts +1 -1
- package/dist/types/setup/config.d.ts +3 -7
- package/dist/types/setup/directApi.d.ts +21 -16
- package/dist/types/setup/index.d.ts +1 -2
- package/dist/types/setup/setup.d.ts +7 -1
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +53 -0
- package/dist/types/system/pointer/buttons.d.ts +23 -0
- package/dist/types/system/pointer/device.d.ts +8 -0
- package/dist/types/system/pointer/index.d.ts +39 -0
- package/dist/types/system/pointer/mouse.d.ts +26 -0
- package/dist/types/system/pointer/pointer.d.ts +30 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -1
- package/dist/types/utils/edit/walkRadio.d.ts +4 -0
- package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
- package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
- package/dist/types/utils/focus/selection.d.ts +28 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +6 -2
- package/package.json +9 -15
- package/dist/index.cjs +0 -3057
- package/dist/index.mjs +0 -3107
- package/dist/types/event/eventTypes.d.ts +0 -2
- package/dist/types/keyboard/keyboardAction.d.ts +0 -10
- package/dist/types/keyboard/modifiers.d.ts +0 -9
- package/dist/types/keyboard/types.d.ts +0 -73
- package/dist/types/pointer/firePointerEvents.d.ts +0 -11
- package/dist/types/pointer/pointerAction.d.ts +0 -7
- package/dist/types/pointer/pointerMove.d.ts +0 -6
- package/dist/types/pointer/pointerPress.d.ts +0 -8
- package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/types/pointer/types.d.ts +0 -62
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
- package/dist/types/utils/pointer/mouseButtons.d.ts +0 -12
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function isElementType(element, tag, props) {
|
|
6
|
+
if (element.namespaceURI && element.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
tag = Array.isArray(tag) ? tag : [
|
|
10
|
+
tag
|
|
11
|
+
];
|
|
12
|
+
// tagName is uppercase in HTMLDocument and lowercase in XMLDocument
|
|
13
|
+
if (!tag.includes(element.tagName.toLowerCase())) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (props) {
|
|
17
|
+
return Object.entries(props).every(([k, v])=>element[k] === v);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.isElementType = isElementType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var getWindow = require('./getWindow.js');
|
|
6
|
+
|
|
7
|
+
function isVisible(element) {
|
|
8
|
+
const window = getWindow.getWindow(element);
|
|
9
|
+
for(let el = element; el?.ownerDocument; el = el.parentElement){
|
|
10
|
+
const { display , visibility } = window.getComputedStyle(el);
|
|
11
|
+
if (display === 'none') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (visibility === 'hidden') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.isVisible = isVisible;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
exports.ApiLevel = void 0;
|
|
6
|
+
(function(ApiLevel) {
|
|
7
|
+
ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
|
|
8
|
+
ApiLevel[ApiLevel["Call"] = 1] = "Call";
|
|
9
|
+
})(exports.ApiLevel || (exports.ApiLevel = {}));
|
|
10
|
+
const Level = Symbol('Api level refs');
|
|
11
|
+
function setLevelRef(config, level) {
|
|
12
|
+
config[Level] ??= {};
|
|
13
|
+
config[Level][level] = {};
|
|
14
|
+
}
|
|
15
|
+
function getLevelRef(config, level) {
|
|
16
|
+
return config[Level]?.[level];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.getLevelRef = getLevelRef;
|
|
20
|
+
exports.setLevelRef = setLevelRef;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function wait(config) {
|
|
6
|
+
const delay = config.delay;
|
|
7
|
+
if (typeof delay !== 'number') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return Promise.all([
|
|
11
|
+
new Promise((resolve)=>globalThis.setTimeout(()=>resolve(), delay)),
|
|
12
|
+
config.advanceTimers(delay),
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.wait = wait;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var options = require('../../options.js');
|
|
6
|
+
require('../click/isClickableInput.js');
|
|
7
|
+
require('../dataTransfer/Clipboard.js');
|
|
8
|
+
require('../../event/eventMap.js');
|
|
9
|
+
require('../../event/behavior/click.js');
|
|
10
|
+
require('../../event/behavior/cut.js');
|
|
11
|
+
require('../../event/behavior/keydown.js');
|
|
12
|
+
require('../../event/behavior/keypress.js');
|
|
13
|
+
require('../../event/behavior/keyup.js');
|
|
14
|
+
require('../../event/behavior/paste.js');
|
|
15
|
+
require('@testing-library/dom');
|
|
16
|
+
require('../edit/maxLength.js');
|
|
17
|
+
require('../edit/isEditable.js');
|
|
18
|
+
var isElementType = require('../misc/isElementType.js');
|
|
19
|
+
var getWindow = require('../misc/getWindow.js');
|
|
20
|
+
require('../keyDef/readNextDescriptor.js');
|
|
21
|
+
var level = require('../misc/level.js');
|
|
22
|
+
|
|
23
|
+
function hasPointerEvents(config, element) {
|
|
24
|
+
return checkPointerEvents(config, element)?.pointerEvents !== 'none';
|
|
25
|
+
}
|
|
26
|
+
function closestPointerEventsDeclaration(element) {
|
|
27
|
+
const window = getWindow.getWindow(element);
|
|
28
|
+
for(let el = element, tree = []; el?.ownerDocument; el = el.parentElement){
|
|
29
|
+
tree.push(el);
|
|
30
|
+
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
31
|
+
if (pointerEvents && ![
|
|
32
|
+
'inherit',
|
|
33
|
+
'unset'
|
|
34
|
+
].includes(pointerEvents)) {
|
|
35
|
+
return {
|
|
36
|
+
pointerEvents,
|
|
37
|
+
tree
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const PointerEventsCheck = Symbol('Last check for pointer-events');
|
|
44
|
+
function checkPointerEvents(config, element) {
|
|
45
|
+
const lastCheck = element[PointerEventsCheck];
|
|
46
|
+
const needsCheck = config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(config, level.ApiLevel.Call) || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(config, level.ApiLevel.Trigger));
|
|
47
|
+
if (!needsCheck) {
|
|
48
|
+
return lastCheck?.result;
|
|
49
|
+
}
|
|
50
|
+
const declaration = closestPointerEventsDeclaration(element);
|
|
51
|
+
element[PointerEventsCheck] = {
|
|
52
|
+
[level.ApiLevel.Call]: level.getLevelRef(config, level.ApiLevel.Call),
|
|
53
|
+
[level.ApiLevel.Trigger]: level.getLevelRef(config, level.ApiLevel.Trigger),
|
|
54
|
+
result: declaration
|
|
55
|
+
};
|
|
56
|
+
return declaration;
|
|
57
|
+
}
|
|
58
|
+
function assertPointerEvents(config, element) {
|
|
59
|
+
const declaration = checkPointerEvents(config, element);
|
|
60
|
+
if (declaration?.pointerEvents === 'none') {
|
|
61
|
+
throw new Error([
|
|
62
|
+
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
|
|
63
|
+
'',
|
|
64
|
+
printTree(declaration.tree),
|
|
65
|
+
].join('\n'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function printTree(tree) {
|
|
69
|
+
return tree.reverse().map((el, i)=>[
|
|
70
|
+
''.padEnd(i),
|
|
71
|
+
el.tagName,
|
|
72
|
+
el.id && `#${el.id}`,
|
|
73
|
+
el.hasAttribute('data-testid') && `(testId=${el.getAttribute('data-testid')})`,
|
|
74
|
+
getLabelDescr(el),
|
|
75
|
+
tree.length > 1 && i === 0 && ' <-- This element declared `pointer-events: none`',
|
|
76
|
+
tree.length > 1 && i === tree.length - 1 && ' <-- Asserted pointer events here',
|
|
77
|
+
].filter(Boolean).join('')).join('\n');
|
|
78
|
+
}
|
|
79
|
+
function getLabelDescr(element) {
|
|
80
|
+
let label;
|
|
81
|
+
if (element.hasAttribute('aria-label')) {
|
|
82
|
+
label = element.getAttribute('aria-label');
|
|
83
|
+
} else if (element.hasAttribute('aria-labelledby')) {
|
|
84
|
+
label = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))?.textContent?.trim();
|
|
85
|
+
} else if (isElementType.isElementType(element, [
|
|
86
|
+
'button',
|
|
87
|
+
'input',
|
|
88
|
+
'meter',
|
|
89
|
+
'output',
|
|
90
|
+
'progress',
|
|
91
|
+
'select',
|
|
92
|
+
'textarea',
|
|
93
|
+
]) && element.labels?.length) {
|
|
94
|
+
label = Array.from(element.labels).map((el)=>el.textContent?.trim()).join('|');
|
|
95
|
+
} else if (isElementType.isElementType(element, 'button')) {
|
|
96
|
+
label = element.textContent?.trim();
|
|
97
|
+
}
|
|
98
|
+
label = label?.replace(/\n/g, ' ');
|
|
99
|
+
if (Number(label?.length) > 30) {
|
|
100
|
+
label = `${label?.substring(0, 29)}…`;
|
|
101
|
+
}
|
|
102
|
+
return label ? `(label=${label})` : '';
|
|
103
|
+
}
|
|
104
|
+
// With the eslint rule and prettier the bitwise operation isn't nice to read
|
|
105
|
+
function hasBitFlag(conf, flag) {
|
|
106
|
+
// eslint-disable-next-line no-bitwise
|
|
107
|
+
return (conf & flag) > 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.assertPointerEvents = assertPointerEvents;
|
|
111
|
+
exports.hasPointerEvents = hasPointerEvents;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '../setup/index.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../event/eventMap.js';
|
|
5
|
+
import '../event/behavior/click.js';
|
|
6
|
+
import '../event/behavior/cut.js';
|
|
7
|
+
import '../event/behavior/keydown.js';
|
|
8
|
+
import '../event/behavior/keypress.js';
|
|
9
|
+
import '../event/behavior/keyup.js';
|
|
10
|
+
import '../event/behavior/paste.js';
|
|
11
|
+
import '@testing-library/dom';
|
|
12
|
+
import '../utils/edit/maxLength.js';
|
|
13
|
+
import '../utils/edit/isEditable.js';
|
|
14
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
15
|
+
import { copySelection } from '../utils/focus/copySelection.js';
|
|
16
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
|
+
import '../utils/misc/level.js';
|
|
18
|
+
import '../options.js';
|
|
19
|
+
import { Config } from '../setup/config.js';
|
|
20
|
+
|
|
21
|
+
async function copy() {
|
|
22
|
+
const doc = this[Config].document;
|
|
23
|
+
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
24
|
+
const clipboardData = copySelection(target);
|
|
25
|
+
if (clipboardData.items.length === 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (this.dispatchUIEvent(target, 'copy', {
|
|
29
|
+
clipboardData
|
|
30
|
+
}) && this[Config].writeToClipboard) {
|
|
31
|
+
await writeDataTransferToClipboard(doc, clipboardData);
|
|
32
|
+
}
|
|
33
|
+
return clipboardData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { copy };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '../setup/index.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../event/eventMap.js';
|
|
5
|
+
import '../event/behavior/click.js';
|
|
6
|
+
import '../event/behavior/cut.js';
|
|
7
|
+
import '../event/behavior/keydown.js';
|
|
8
|
+
import '../event/behavior/keypress.js';
|
|
9
|
+
import '../event/behavior/keyup.js';
|
|
10
|
+
import '../event/behavior/paste.js';
|
|
11
|
+
import '@testing-library/dom';
|
|
12
|
+
import '../utils/edit/maxLength.js';
|
|
13
|
+
import '../utils/edit/isEditable.js';
|
|
14
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
15
|
+
import { copySelection } from '../utils/focus/copySelection.js';
|
|
16
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
|
+
import '../utils/misc/level.js';
|
|
18
|
+
import '../options.js';
|
|
19
|
+
import { Config } from '../setup/config.js';
|
|
20
|
+
|
|
21
|
+
async function cut() {
|
|
22
|
+
const doc = this[Config].document;
|
|
23
|
+
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
24
|
+
const clipboardData = copySelection(target);
|
|
25
|
+
if (clipboardData.items.length === 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (this.dispatchUIEvent(target, 'cut', {
|
|
29
|
+
clipboardData
|
|
30
|
+
}) && this[Config].writeToClipboard) {
|
|
31
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
32
|
+
}
|
|
33
|
+
return clipboardData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { cut };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import '../setup/index.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
|
|
4
|
+
import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
5
|
+
import '../event/eventMap.js';
|
|
6
|
+
import '../event/behavior/click.js';
|
|
7
|
+
import '../event/behavior/cut.js';
|
|
8
|
+
import '../event/behavior/keydown.js';
|
|
9
|
+
import '../event/behavior/keypress.js';
|
|
10
|
+
import '../event/behavior/keyup.js';
|
|
11
|
+
import '../event/behavior/paste.js';
|
|
12
|
+
import '@testing-library/dom';
|
|
13
|
+
import '../utils/edit/maxLength.js';
|
|
14
|
+
import '../utils/edit/isEditable.js';
|
|
15
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
16
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
|
+
import '../utils/misc/level.js';
|
|
18
|
+
import '../options.js';
|
|
19
|
+
import { Config } from '../setup/config.js';
|
|
20
|
+
|
|
21
|
+
async function paste(clipboardData) {
|
|
22
|
+
const doc = this[Config].document;
|
|
23
|
+
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
24
|
+
const dataTransfer = (typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) ?? await readDataTransferFromClipboard(doc).catch(()=>{
|
|
25
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
26
|
+
});
|
|
27
|
+
this.dispatchUIEvent(target, 'paste', {
|
|
28
|
+
clipboardData: dataTransfer
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function getClipboardDataFromString(doc, text) {
|
|
32
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
33
|
+
dt.setData('text', text);
|
|
34
|
+
return dt;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { paste };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import '../setup/index.js';
|
|
2
|
+
import { Config } from '../setup/config.js';
|
|
3
|
+
|
|
4
|
+
async function click(element) {
|
|
5
|
+
const pointerIn = [];
|
|
6
|
+
if (!this[Config].skipHover) {
|
|
7
|
+
pointerIn.push({
|
|
8
|
+
target: element
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
pointerIn.push({
|
|
12
|
+
keys: '[MouseLeft]',
|
|
13
|
+
target: element
|
|
14
|
+
});
|
|
15
|
+
return this.pointer(pointerIn);
|
|
16
|
+
}
|
|
17
|
+
async function dblClick(element) {
|
|
18
|
+
return this.pointer([
|
|
19
|
+
{
|
|
20
|
+
target: element
|
|
21
|
+
},
|
|
22
|
+
'[MouseLeft][MouseLeft]'
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
async function tripleClick(element) {
|
|
26
|
+
return this.pointer([
|
|
27
|
+
{
|
|
28
|
+
target: element
|
|
29
|
+
},
|
|
30
|
+
'[MouseLeft][MouseLeft][MouseLeft]'
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { click, dblClick, tripleClick };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import '../setup/index.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../event/eventMap.js';
|
|
5
|
+
import '../event/behavior/click.js';
|
|
6
|
+
import '../event/behavior/cut.js';
|
|
7
|
+
import '../event/behavior/keydown.js';
|
|
8
|
+
import '../event/behavior/keypress.js';
|
|
9
|
+
import '../event/behavior/keyup.js';
|
|
10
|
+
import '../event/behavior/paste.js';
|
|
11
|
+
import '@testing-library/dom';
|
|
12
|
+
import '../utils/edit/maxLength.js';
|
|
13
|
+
import '../utils/edit/isEditable.js';
|
|
14
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
15
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
16
|
+
import '../utils/misc/level.js';
|
|
17
|
+
import { assertPointerEvents } from '../utils/pointer/cssPointerEvents.js';
|
|
18
|
+
import { Config } from '../setup/config.js';
|
|
19
|
+
|
|
20
|
+
async function hover(element) {
|
|
21
|
+
return this.pointer({
|
|
22
|
+
target: element
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function unhover(element) {
|
|
26
|
+
assertPointerEvents(this[Config], this[Config].system.pointer.getMouseTarget(this[Config]));
|
|
27
|
+
return this.pointer({
|
|
28
|
+
target: element.ownerDocument.body
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { hover, unhover };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { dispatchUIEvent } from '../event/index.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
5
|
+
import '../utils/edit/isEditable.js';
|
|
6
|
+
import '@testing-library/dom';
|
|
7
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
8
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
9
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
10
|
+
import '../utils/misc/level.js';
|
|
11
|
+
import '../options.js';
|
|
12
|
+
import { prepareSelectionInterceptor } from './selection.js';
|
|
13
|
+
export { getUISelection, setUISelection } from './selection.js';
|
|
14
|
+
import { prepareRangeTextInterceptor } from './setRangeText.js';
|
|
15
|
+
import { getInitialValue, clearInitialValue, prepareValueInterceptor } from './value.js';
|
|
16
|
+
export { clearInitialValue, commitValueAfterInput, getUIValue, setUIValue } from './value.js';
|
|
17
|
+
|
|
18
|
+
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
19
|
+
function prepareDocument(document) {
|
|
20
|
+
if (document[isPrepared]) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
document.addEventListener('focus', (e)=>{
|
|
24
|
+
const el = e.target;
|
|
25
|
+
prepareElement(el);
|
|
26
|
+
}, {
|
|
27
|
+
capture: true,
|
|
28
|
+
passive: true
|
|
29
|
+
});
|
|
30
|
+
// Our test environment defaults to `document.body` as `activeElement`.
|
|
31
|
+
// In other environments this might be `null` when preparing.
|
|
32
|
+
// istanbul ignore else
|
|
33
|
+
if (document.activeElement) {
|
|
34
|
+
prepareElement(document.activeElement);
|
|
35
|
+
}
|
|
36
|
+
document.addEventListener('blur', (e)=>{
|
|
37
|
+
const el = e.target;
|
|
38
|
+
const initialValue = getInitialValue(el);
|
|
39
|
+
if (initialValue !== undefined) {
|
|
40
|
+
if (el.value !== initialValue) {
|
|
41
|
+
dispatchUIEvent({}, el, 'change');
|
|
42
|
+
}
|
|
43
|
+
clearInitialValue(el);
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
capture: true,
|
|
47
|
+
passive: true
|
|
48
|
+
});
|
|
49
|
+
document[isPrepared] = isPrepared;
|
|
50
|
+
}
|
|
51
|
+
function prepareElement(el) {
|
|
52
|
+
if (el[isPrepared]) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (isElementType(el, [
|
|
56
|
+
'input',
|
|
57
|
+
'textarea'
|
|
58
|
+
])) {
|
|
59
|
+
prepareValueInterceptor(el);
|
|
60
|
+
prepareSelectionInterceptor(el);
|
|
61
|
+
prepareRangeTextInterceptor(el);
|
|
62
|
+
}
|
|
63
|
+
el[isPrepared] = isPrepared;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { prepareDocument };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
2
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
3
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
4
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
5
|
+
const target = prototypeDescriptor?.set ? 'set' : 'value';
|
|
6
|
+
/* istanbul ignore if */ if (typeof prototypeDescriptor?.[target] !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
7
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
8
|
+
}
|
|
9
|
+
function intercept(...args) {
|
|
10
|
+
const { applyNative =false , realArgs , then , } = interceptorImpl.call(this, ...args);
|
|
11
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
12
|
+
if (target === 'set') {
|
|
13
|
+
realFunc.call(this, realArgs);
|
|
14
|
+
} else {
|
|
15
|
+
realFunc.call(this, ...realArgs);
|
|
16
|
+
}
|
|
17
|
+
then?.();
|
|
18
|
+
}
|
|
19
|
+
intercept[Interceptor] = Interceptor;
|
|
20
|
+
Object.defineProperty(element, propName, {
|
|
21
|
+
...objectDescriptor ?? prototypeDescriptor,
|
|
22
|
+
[target]: intercept
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { prepareInterceptor };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import '../utils/edit/maxLength.js';
|
|
4
|
+
import '../utils/edit/isEditable.js';
|
|
5
|
+
import '@testing-library/dom';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../utils/misc/level.js';
|
|
9
|
+
import '../options.js';
|
|
10
|
+
import '../event/eventMap.js';
|
|
11
|
+
import '../event/behavior/click.js';
|
|
12
|
+
import '../event/behavior/cut.js';
|
|
13
|
+
import '../event/behavior/keydown.js';
|
|
14
|
+
import '../event/behavior/keypress.js';
|
|
15
|
+
import '../event/behavior/keyup.js';
|
|
16
|
+
import '../event/behavior/paste.js';
|
|
17
|
+
import { prepareInterceptor } from './interceptor.js';
|
|
18
|
+
import { getUIValue } from './value.js';
|
|
19
|
+
|
|
20
|
+
const UISelection = Symbol('Displayed selection in UI');
|
|
21
|
+
function prepareSelectionInterceptor(element) {
|
|
22
|
+
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
|
|
23
|
+
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
24
|
+
if (!isUI) {
|
|
25
|
+
this[UISelection] = undefined;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
applyNative: !!isUI,
|
|
29
|
+
realArgs: [
|
|
30
|
+
Number(start),
|
|
31
|
+
...others
|
|
32
|
+
]
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
|
|
36
|
+
this[UISelection] = undefined;
|
|
37
|
+
return {
|
|
38
|
+
realArgs: v
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
|
|
42
|
+
this[UISelection] = undefined;
|
|
43
|
+
return {
|
|
44
|
+
realArgs: v
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
prepareInterceptor(element, 'select', function interceptorImpl() {
|
|
48
|
+
this[UISelection] = {
|
|
49
|
+
anchorOffset: 0,
|
|
50
|
+
focusOffset: getUIValue(element).length
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
realArgs: []
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function setUISelection(element, { focusOffset: focusOffsetParam , anchorOffset: anchorOffsetParam = focusOffsetParam }, mode = 'replace') {
|
|
58
|
+
const valueLength = getUIValue(element).length;
|
|
59
|
+
const sanitizeOffset = (o)=>Math.max(0, Math.min(valueLength, o));
|
|
60
|
+
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
61
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
62
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
63
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
64
|
+
element[UISelection] = {
|
|
65
|
+
anchorOffset,
|
|
66
|
+
focusOffset
|
|
67
|
+
};
|
|
68
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// eslint-disable-next-line no-new-wrappers
|
|
72
|
+
const startObj = new Number(startOffset);
|
|
73
|
+
startObj[UISelection] = UISelection;
|
|
74
|
+
try {
|
|
75
|
+
element.setSelectionRange(startObj, endOffset);
|
|
76
|
+
} catch {
|
|
77
|
+
// DOMException for invalid state is expected when calling this
|
|
78
|
+
// on an element without support for setSelectionRange
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getUISelection(element) {
|
|
82
|
+
const sel = element[UISelection] ?? {
|
|
83
|
+
anchorOffset: element.selectionStart ?? 0,
|
|
84
|
+
focusOffset: element.selectionEnd ?? 0
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
...sel,
|
|
88
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
89
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function hasUISelection(element) {
|
|
93
|
+
return !!element[UISelection];
|
|
94
|
+
}
|
|
95
|
+
/** Flag the IDL selection as clean. This does not change the selection. */ function setUISelectionClean(element) {
|
|
96
|
+
element[UISelection] = undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { getUISelection, hasUISelection, prepareSelectionInterceptor, setUISelection, setUISelectionClean };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { prepareInterceptor } from './interceptor.js';
|
|
2
|
+
import { setUISelectionClean } from './selection.js';
|
|
3
|
+
import { setUIValueClean } from './value.js';
|
|
4
|
+
|
|
5
|
+
function prepareRangeTextInterceptor(element) {
|
|
6
|
+
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
|
|
7
|
+
return {
|
|
8
|
+
realArgs,
|
|
9
|
+
then: ()=>{
|
|
10
|
+
setUIValueClean(element);
|
|
11
|
+
setUISelectionClean(element);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { prepareRangeTextInterceptor };
|