@testing-library/user-event 14.2.6 → 14.4.1

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.
Files changed (238) hide show
  1. package/dist/cjs/clipboard/copy.js +41 -0
  2. package/dist/cjs/clipboard/cut.js +41 -0
  3. package/dist/cjs/clipboard/index.js +13 -0
  4. package/dist/cjs/clipboard/paste.js +43 -0
  5. package/dist/cjs/convenience/click.js +40 -0
  6. package/dist/cjs/convenience/hover.js +37 -0
  7. package/dist/cjs/convenience/index.js +16 -0
  8. package/dist/cjs/convenience/tab.js +9 -0
  9. package/dist/cjs/document/index.js +74 -0
  10. package/dist/cjs/document/interceptor.js +30 -0
  11. package/dist/cjs/document/selection.js +108 -0
  12. package/dist/cjs/document/setRangeText.js +21 -0
  13. package/dist/cjs/document/value.js +127 -0
  14. package/dist/cjs/event/behavior/click.js +42 -0
  15. package/dist/cjs/event/behavior/cut.js +26 -0
  16. package/dist/cjs/event/behavior/index.js +15 -0
  17. package/dist/cjs/event/behavior/keydown.js +138 -0
  18. package/dist/cjs/event/behavior/keypress.js +58 -0
  19. package/dist/cjs/event/behavior/keyup.js +25 -0
  20. package/dist/cjs/event/behavior/paste.js +30 -0
  21. package/dist/cjs/event/behavior/registry.js +7 -0
  22. package/dist/cjs/event/createEvent.js +209 -0
  23. package/dist/cjs/event/dispatchEvent.js +38 -0
  24. package/dist/cjs/event/dom-events.d.js +2 -0
  25. package/dist/cjs/event/eventMap.js +64 -0
  26. package/dist/cjs/event/index.js +24 -0
  27. package/dist/cjs/event/types.js +2 -0
  28. package/dist/cjs/event/wrapEvent.js +11 -0
  29. package/dist/cjs/index.js +14 -0
  30. package/dist/cjs/keyboard/index.js +59 -0
  31. package/dist/cjs/keyboard/keyMap.js +158 -0
  32. package/dist/cjs/keyboard/parseKeyDef.js +61 -0
  33. package/dist/cjs/options.js +42 -0
  34. package/dist/cjs/package.json +3 -0
  35. package/dist/cjs/pointer/index.js +92 -0
  36. package/dist/cjs/pointer/keyMap.js +35 -0
  37. package/dist/cjs/pointer/parseKeyDef.js +39 -0
  38. package/dist/cjs/setup/api.js +35 -0
  39. package/dist/cjs/setup/config.js +7 -0
  40. package/dist/cjs/setup/directApi.js +77 -0
  41. package/dist/cjs/setup/index.js +15 -0
  42. package/dist/cjs/setup/setup.js +100 -0
  43. package/dist/cjs/setup/wrapAsync.js +13 -0
  44. package/dist/cjs/system/index.js +33 -0
  45. package/dist/cjs/system/keyboard.js +137 -0
  46. package/dist/cjs/system/pointer/buttons.js +73 -0
  47. package/dist/cjs/system/pointer/device.js +23 -0
  48. package/dist/cjs/system/pointer/index.js +154 -0
  49. package/dist/cjs/system/pointer/mouse.js +195 -0
  50. package/dist/cjs/system/pointer/pointer.js +115 -0
  51. package/dist/cjs/utility/clear.js +42 -0
  52. package/dist/cjs/utility/index.js +16 -0
  53. package/dist/cjs/utility/selectOptions.js +125 -0
  54. package/dist/cjs/utility/type.js +41 -0
  55. package/dist/cjs/utility/upload.js +76 -0
  56. package/dist/cjs/utils/click/isClickableInput.js +22 -0
  57. package/dist/cjs/utils/dataTransfer/Blob.js +18 -0
  58. package/dist/cjs/utils/dataTransfer/Clipboard.js +172 -0
  59. package/dist/cjs/utils/dataTransfer/DataTransfer.js +127 -0
  60. package/dist/cjs/utils/dataTransfer/FileList.js +26 -0
  61. package/dist/cjs/utils/edit/buildTimeValue.js +36 -0
  62. package/dist/cjs/utils/edit/getValue.js +35 -0
  63. package/dist/cjs/utils/edit/input.js +163 -0
  64. package/dist/cjs/utils/edit/isContentEditable.js +20 -0
  65. package/dist/cjs/utils/edit/isEditable.js +35 -0
  66. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +11 -0
  67. package/dist/cjs/utils/edit/maxLength.js +39 -0
  68. package/dist/cjs/utils/edit/setFiles.js +61 -0
  69. package/dist/cjs/utils/edit/walkRadio.js +28 -0
  70. package/dist/cjs/utils/focus/blur.js +16 -0
  71. package/dist/cjs/utils/focus/copySelection.js +46 -0
  72. package/dist/cjs/utils/focus/cursor.js +144 -0
  73. package/dist/cjs/utils/focus/focus.js +29 -0
  74. package/dist/cjs/utils/focus/getActiveElement.js +25 -0
  75. package/dist/cjs/utils/focus/getTabDestination.js +82 -0
  76. package/dist/cjs/utils/focus/isFocusable.js +11 -0
  77. package/dist/cjs/utils/focus/resolveCaretPosition.js +78 -0
  78. package/dist/cjs/utils/focus/selectAll.js +56 -0
  79. package/dist/cjs/utils/focus/selection.js +292 -0
  80. package/dist/cjs/utils/focus/selector.js +16 -0
  81. package/dist/cjs/utils/index.js +108 -0
  82. package/dist/cjs/utils/keyDef/readNextDescriptor.js +94 -0
  83. package/dist/cjs/utils/misc/cloneEvent.js +9 -0
  84. package/dist/cjs/utils/misc/dom-helpers.d.js +2 -0
  85. package/dist/cjs/utils/misc/eventWrapper.js +15 -0
  86. package/dist/cjs/utils/misc/findClosest.js +16 -0
  87. package/dist/cjs/utils/misc/getDocumentFromNode.js +12 -0
  88. package/dist/cjs/utils/misc/getTreeDiff.js +27 -0
  89. package/dist/cjs/utils/misc/getWindow.js +11 -0
  90. package/dist/cjs/utils/misc/isDescendantOrSelf.js +16 -0
  91. package/dist/cjs/utils/misc/isDisabled.js +35 -0
  92. package/dist/cjs/utils/misc/isElementType.js +22 -0
  93. package/dist/cjs/utils/misc/isVisible.js +21 -0
  94. package/dist/cjs/utils/misc/level.js +23 -0
  95. package/dist/cjs/utils/misc/wait.js +16 -0
  96. package/dist/cjs/utils/pointer/cssPointerEvents.js +118 -0
  97. package/dist/esm/clipboard/copy.js +37 -0
  98. package/dist/esm/clipboard/cut.js +37 -0
  99. package/dist/esm/clipboard/index.js +3 -0
  100. package/dist/esm/clipboard/paste.js +39 -0
  101. package/dist/esm/convenience/click.js +34 -0
  102. package/dist/esm/convenience/hover.js +32 -0
  103. package/dist/esm/convenience/index.js +3 -0
  104. package/dist/esm/convenience/tab.js +5 -0
  105. package/dist/esm/document/index.js +66 -0
  106. package/dist/esm/document/interceptor.js +26 -0
  107. package/dist/esm/document/selection.js +100 -0
  108. package/dist/esm/document/setRangeText.js +17 -0
  109. package/dist/esm/document/value.js +117 -0
  110. package/dist/esm/event/behavior/click.js +40 -0
  111. package/dist/esm/event/behavior/cut.js +24 -0
  112. package/dist/esm/event/behavior/index.js +7 -0
  113. package/dist/esm/event/behavior/keydown.js +136 -0
  114. package/dist/esm/event/behavior/keypress.js +56 -0
  115. package/dist/esm/event/behavior/keyup.js +23 -0
  116. package/dist/esm/event/behavior/paste.js +28 -0
  117. package/dist/esm/event/behavior/registry.js +3 -0
  118. package/dist/esm/event/createEvent.js +205 -0
  119. package/dist/esm/event/dispatchEvent.js +34 -0
  120. package/dist/esm/event/dom-events.d.js +1 -0
  121. package/dist/esm/event/eventMap.js +57 -0
  122. package/dist/esm/event/index.js +19 -0
  123. package/dist/esm/event/types.js +1 -0
  124. package/dist/esm/event/wrapEvent.js +7 -0
  125. package/dist/esm/index.js +2 -0
  126. package/dist/esm/keyboard/index.js +54 -0
  127. package/dist/esm/keyboard/keyMap.js +154 -0
  128. package/dist/esm/keyboard/parseKeyDef.js +57 -0
  129. package/dist/esm/options.js +37 -0
  130. package/dist/esm/package.json +3 -0
  131. package/dist/esm/pointer/index.js +88 -0
  132. package/dist/esm/pointer/keyMap.js +31 -0
  133. package/dist/esm/pointer/parseKeyDef.js +35 -0
  134. package/dist/esm/setup/api.js +12 -0
  135. package/dist/esm/setup/config.js +3 -0
  136. package/dist/esm/setup/directApi.js +58 -0
  137. package/dist/esm/setup/index.js +10 -0
  138. package/dist/esm/setup/setup.js +93 -0
  139. package/dist/esm/setup/wrapAsync.js +9 -0
  140. package/dist/esm/system/index.js +29 -0
  141. package/dist/esm/system/keyboard.js +133 -0
  142. package/dist/esm/system/pointer/buttons.js +65 -0
  143. package/dist/esm/system/pointer/device.js +19 -0
  144. package/dist/esm/system/pointer/index.js +149 -0
  145. package/dist/esm/system/pointer/mouse.js +191 -0
  146. package/dist/esm/system/pointer/pointer.js +111 -0
  147. package/dist/esm/utility/clear.js +38 -0
  148. package/dist/esm/utility/index.js +4 -0
  149. package/dist/esm/utility/selectOptions.js +120 -0
  150. package/dist/esm/utility/type.js +37 -0
  151. package/dist/esm/utility/upload.js +72 -0
  152. package/dist/esm/utils/click/isClickableInput.js +18 -0
  153. package/dist/esm/utils/dataTransfer/Blob.js +14 -0
  154. package/dist/esm/utils/dataTransfer/Clipboard.js +163 -0
  155. package/dist/esm/utils/dataTransfer/DataTransfer.js +122 -0
  156. package/dist/esm/utils/dataTransfer/FileList.js +22 -0
  157. package/dist/esm/utils/edit/buildTimeValue.js +32 -0
  158. package/dist/esm/utils/edit/getValue.js +31 -0
  159. package/dist/esm/utils/edit/input.js +159 -0
  160. package/dist/esm/utils/edit/isContentEditable.js +15 -0
  161. package/dist/esm/utils/edit/isEditable.js +30 -0
  162. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +7 -0
  163. package/dist/esm/utils/edit/maxLength.js +35 -0
  164. package/dist/esm/utils/edit/setFiles.js +57 -0
  165. package/dist/esm/utils/edit/walkRadio.js +24 -0
  166. package/dist/esm/utils/focus/blur.js +12 -0
  167. package/dist/esm/utils/focus/copySelection.js +42 -0
  168. package/dist/esm/utils/focus/cursor.js +140 -0
  169. package/dist/esm/utils/focus/focus.js +25 -0
  170. package/dist/esm/utils/focus/getActiveElement.js +20 -0
  171. package/dist/esm/utils/focus/getTabDestination.js +78 -0
  172. package/dist/esm/utils/focus/isFocusable.js +7 -0
  173. package/dist/esm/utils/focus/resolveCaretPosition.js +74 -0
  174. package/dist/esm/utils/focus/selectAll.js +51 -0
  175. package/dist/esm/utils/focus/selection.js +279 -0
  176. package/dist/esm/utils/focus/selector.js +12 -0
  177. package/dist/esm/utils/index.js +36 -0
  178. package/dist/esm/utils/keyDef/readNextDescriptor.js +90 -0
  179. package/dist/esm/utils/misc/cloneEvent.js +5 -0
  180. package/dist/esm/utils/misc/dom-helpers.d.js +1 -0
  181. package/dist/esm/utils/misc/eventWrapper.js +11 -0
  182. package/dist/esm/utils/misc/findClosest.js +12 -0
  183. package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
  184. package/dist/esm/utils/misc/getTreeDiff.js +23 -0
  185. package/dist/esm/utils/misc/getWindow.js +7 -0
  186. package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
  187. package/dist/esm/utils/misc/isDisabled.js +31 -0
  188. package/dist/esm/utils/misc/isElementType.js +18 -0
  189. package/dist/esm/utils/misc/isVisible.js +17 -0
  190. package/dist/esm/utils/misc/level.js +18 -0
  191. package/dist/esm/utils/misc/wait.js +12 -0
  192. package/dist/esm/utils/pointer/cssPointerEvents.js +113 -0
  193. package/dist/types/event/createEvent.d.ts +2 -8
  194. package/dist/types/event/eventMap.d.ts +204 -181
  195. package/dist/types/event/index.d.ts +1 -2
  196. package/dist/types/event/types.d.ts +6 -0
  197. package/dist/types/index.d.ts +2 -2
  198. package/dist/types/keyboard/index.d.ts +2 -6
  199. package/dist/types/keyboard/keyMap.d.ts +1 -1
  200. package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
  201. package/dist/types/options.d.ts +4 -4
  202. package/dist/types/pointer/index.d.ts +23 -5
  203. package/dist/types/pointer/keyMap.d.ts +1 -1
  204. package/dist/types/pointer/parseKeyDef.d.ts +1 -1
  205. package/dist/types/setup/config.d.ts +3 -7
  206. package/dist/types/setup/directApi.d.ts +21 -16
  207. package/dist/types/setup/index.d.ts +1 -2
  208. package/dist/types/setup/setup.d.ts +7 -1
  209. package/dist/types/system/index.d.ts +10 -0
  210. package/dist/types/system/keyboard.d.ts +53 -0
  211. package/dist/types/system/pointer/buttons.d.ts +23 -0
  212. package/dist/types/system/pointer/device.d.ts +8 -0
  213. package/dist/types/system/pointer/index.d.ts +39 -0
  214. package/dist/types/system/pointer/mouse.d.ts +26 -0
  215. package/dist/types/system/pointer/pointer.d.ts +30 -0
  216. package/dist/types/utils/click/isClickableInput.d.ts +15 -1
  217. package/dist/types/utils/edit/walkRadio.d.ts +4 -0
  218. package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
  219. package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
  220. package/dist/types/utils/focus/selection.d.ts +28 -1
  221. package/dist/types/utils/index.d.ts +3 -3
  222. package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
  223. package/package.json +9 -15
  224. package/dist/index.cjs +0 -3065
  225. package/dist/index.mjs +0 -3116
  226. package/dist/types/event/eventTypes.d.ts +0 -2
  227. package/dist/types/keyboard/keyboardAction.d.ts +0 -10
  228. package/dist/types/keyboard/modifiers.d.ts +0 -9
  229. package/dist/types/keyboard/types.d.ts +0 -73
  230. package/dist/types/pointer/firePointerEvents.d.ts +0 -11
  231. package/dist/types/pointer/pointerAction.d.ts +0 -7
  232. package/dist/types/pointer/pointerMove.d.ts +0 -6
  233. package/dist/types/pointer/pointerPress.d.ts +0 -8
  234. package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
  235. package/dist/types/pointer/types.d.ts +0 -62
  236. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
  237. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
  238. 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 === null || el === void 0 ? void 0 : 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,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _config, _Level;
6
+ exports.ApiLevel = void 0;
7
+ (function(ApiLevel) {
8
+ ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
9
+ ApiLevel[ApiLevel["Call"] = 1] = "Call";
10
+ })(exports.ApiLevel || (exports.ApiLevel = {}));
11
+ const Level = Symbol('Api level refs');
12
+ function setLevelRef(config, level) {
13
+ var ref;
14
+ (ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {};
15
+ config[Level][level] = {};
16
+ }
17
+ function getLevelRef(config, level) {
18
+ var ref;
19
+ return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level];
20
+ }
21
+
22
+ exports.getLevelRef = getLevelRef;
23
+ 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,118 @@
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
+ var ref;
25
+ return ((ref = checkPointerEvents(config, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none';
26
+ }
27
+ function closestPointerEventsDeclaration(element) {
28
+ const window = getWindow.getWindow(element);
29
+ for(let el = element, tree = []; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
30
+ tree.push(el);
31
+ const pointerEvents = window.getComputedStyle(el).pointerEvents;
32
+ if (pointerEvents && ![
33
+ 'inherit',
34
+ 'unset'
35
+ ].includes(pointerEvents)) {
36
+ return {
37
+ pointerEvents,
38
+ tree
39
+ };
40
+ }
41
+ }
42
+ return undefined;
43
+ }
44
+ const PointerEventsCheck = Symbol('Last check for pointer-events');
45
+ function checkPointerEvents(config, element) {
46
+ const lastCheck = element[PointerEventsCheck];
47
+ 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));
48
+ if (!needsCheck) {
49
+ return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result;
50
+ }
51
+ const declaration = closestPointerEventsDeclaration(element);
52
+ element[PointerEventsCheck] = {
53
+ [level.ApiLevel.Call]: level.getLevelRef(config, level.ApiLevel.Call),
54
+ [level.ApiLevel.Trigger]: level.getLevelRef(config, level.ApiLevel.Trigger),
55
+ result: declaration
56
+ };
57
+ return declaration;
58
+ }
59
+ function assertPointerEvents(config, element) {
60
+ const declaration = checkPointerEvents(config, element);
61
+ if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') {
62
+ throw new Error([
63
+ `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
64
+ '',
65
+ printTree(declaration.tree),
66
+ ].join('\n'));
67
+ }
68
+ }
69
+ function printTree(tree) {
70
+ return tree.reverse().map((el, i)=>[
71
+ ''.padEnd(i),
72
+ el.tagName,
73
+ el.id && `#${el.id}`,
74
+ el.hasAttribute('data-testid') && `(testId=${el.getAttribute('data-testid')})`,
75
+ getLabelDescr(el),
76
+ tree.length > 1 && i === 0 && ' <-- This element declared `pointer-events: none`',
77
+ tree.length > 1 && i === tree.length - 1 && ' <-- Asserted pointer events here',
78
+ ].filter(Boolean).join('')).join('\n');
79
+ }
80
+ function getLabelDescr(element) {
81
+ var ref;
82
+ let label;
83
+ if (element.hasAttribute('aria-label')) {
84
+ label = element.getAttribute('aria-label');
85
+ } else if (element.hasAttribute('aria-labelledby')) {
86
+ var ref1, ref2;
87
+ label = (ref1 = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.textContent) === null || ref2 === void 0 ? void 0 : ref2.trim();
88
+ } else if (isElementType.isElementType(element, [
89
+ 'button',
90
+ 'input',
91
+ 'meter',
92
+ 'output',
93
+ 'progress',
94
+ 'select',
95
+ 'textarea',
96
+ ]) && ((ref = element.labels) === null || ref === void 0 ? void 0 : ref.length)) {
97
+ label = Array.from(element.labels).map((el)=>{
98
+ var ref;
99
+ return (ref = el.textContent) === null || ref === void 0 ? void 0 : ref.trim();
100
+ }).join('|');
101
+ } else if (isElementType.isElementType(element, 'button')) {
102
+ var ref3;
103
+ label = (ref3 = element.textContent) === null || ref3 === void 0 ? void 0 : ref3.trim();
104
+ }
105
+ label = label === null || label === void 0 ? void 0 : label.replace(/\n/g, ' ');
106
+ if (Number(label === null || label === void 0 ? void 0 : label.length) > 30) {
107
+ label = `${label === null || label === void 0 ? void 0 : label.substring(0, 29)}…`;
108
+ }
109
+ return label ? `(label=${label})` : '';
110
+ }
111
+ // With the eslint rule and prettier the bitwise operation isn't nice to read
112
+ function hasBitFlag(conf, flag) {
113
+ // eslint-disable-next-line no-bitwise
114
+ return (conf & flag) > 0;
115
+ }
116
+
117
+ exports.assertPointerEvents = assertPointerEvents;
118
+ exports.hasPointerEvents = hasPointerEvents;
@@ -0,0 +1,37 @@
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
+ var _activeElement;
24
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
25
+ const clipboardData = copySelection(target);
26
+ if (clipboardData.items.length === 0) {
27
+ return;
28
+ }
29
+ if (this.dispatchUIEvent(target, 'copy', {
30
+ clipboardData
31
+ }) && this[Config].writeToClipboard) {
32
+ await writeDataTransferToClipboard(doc, clipboardData);
33
+ }
34
+ return clipboardData;
35
+ }
36
+
37
+ export { copy };
@@ -0,0 +1,37 @@
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
+ var _activeElement;
24
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
25
+ const clipboardData = copySelection(target);
26
+ if (clipboardData.items.length === 0) {
27
+ return;
28
+ }
29
+ if (this.dispatchUIEvent(target, 'cut', {
30
+ clipboardData
31
+ }) && this[Config].writeToClipboard) {
32
+ await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
33
+ }
34
+ return clipboardData;
35
+ }
36
+
37
+ export { cut };
@@ -0,0 +1,3 @@
1
+ export { copy } from './copy.js';
2
+ export { cut } from './cut.js';
3
+ export { paste } from './paste.js';
@@ -0,0 +1,39 @@
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
+ var _activeElement;
24
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
25
+ var ref;
26
+ const dataTransfer = (ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && ref !== void 0 ? ref : await readDataTransferFromClipboard(doc).catch(()=>{
27
+ throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
28
+ });
29
+ this.dispatchUIEvent(target, 'paste', {
30
+ clipboardData: dataTransfer
31
+ });
32
+ }
33
+ function getClipboardDataFromString(doc, text) {
34
+ const dt = createDataTransfer(getWindow(doc));
35
+ dt.setData('text', text);
36
+ return dt;
37
+ }
38
+
39
+ 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,3 @@
1
+ export { click, dblClick, tripleClick } from './click.js';
2
+ export { hover, unhover } from './hover.js';
3
+ export { tab } from './tab.js';
@@ -0,0 +1,5 @@
1
+ async function tab({ shift } = {}) {
2
+ return this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
3
+ }
4
+
5
+ export { tab };
@@ -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 === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
6
+ /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : 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 === null || then === void 0 ? void 0 : then();
18
+ }
19
+ intercept[Interceptor] = Interceptor;
20
+ Object.defineProperty(element, propName, {
21
+ ...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
22
+ [target]: intercept
23
+ });
24
+ }
25
+
26
+ export { prepareInterceptor };
@@ -0,0 +1,100 @@
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
+ var _selectionStart, _selectionEnd, _UISelection;
83
+ const sel = (_UISelection = element[UISelection]) !== null && _UISelection !== void 0 ? _UISelection : {
84
+ anchorOffset: (_selectionStart = element.selectionStart) !== null && _selectionStart !== void 0 ? _selectionStart : 0,
85
+ focusOffset: (_selectionEnd = element.selectionEnd) !== null && _selectionEnd !== void 0 ? _selectionEnd : 0
86
+ };
87
+ return {
88
+ ...sel,
89
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
90
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
91
+ };
92
+ }
93
+ function hasUISelection(element) {
94
+ return !!element[UISelection];
95
+ }
96
+ /** Flag the IDL selection as clean. This does not change the selection. */ function setUISelectionClean(element) {
97
+ element[UISelection] = undefined;
98
+ }
99
+
100
+ 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 };