@testing-library/user-event 14.0.0-alpha.1 → 14.0.0-alpha.13

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 (178) hide show
  1. package/dist/{src/clear.d.ts → clear.d.ts} +0 -0
  2. package/dist/clear.js +14 -27
  3. package/dist/{src/click.d.ts → click.d.ts} +3 -2
  4. package/dist/click.js +23 -7
  5. package/dist/document/index.d.ts +10 -0
  6. package/dist/document/index.js +8 -10
  7. package/dist/document/interceptor.d.ts +15 -0
  8. package/dist/document/interceptor.js +7 -4
  9. package/dist/document/selection.d.ts +27 -0
  10. package/dist/document/selection.js +51 -28
  11. package/dist/{src/document → document}/value.d.ts +5 -1
  12. package/dist/document/value.js +27 -6
  13. package/dist/{src/hover.d.ts → hover.d.ts} +2 -2
  14. package/dist/hover.js +2 -2
  15. package/dist/{src/index.d.ts → index.d.ts} +0 -2
  16. package/dist/index.js +0 -8
  17. package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -2
  18. package/dist/keyboard/getEventProps.js +1 -7
  19. package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -1
  20. package/dist/keyboard/getNextKeyDef.js +2 -32
  21. package/dist/{src/keyboard → keyboard}/index.d.ts +0 -1
  22. package/dist/keyboard/index.js +0 -8
  23. package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
  24. package/dist/keyboard/keyMap.js +26 -46
  25. package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
  26. package/dist/keyboard/keyboardImplementation.js +15 -17
  27. package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
  28. package/dist/keyboard/plugins/arrow.js +7 -12
  29. package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
  30. package/dist/keyboard/plugins/character.js +27 -45
  31. package/dist/keyboard/plugins/combination.d.ts +5 -0
  32. package/dist/keyboard/plugins/combination.js +17 -0
  33. package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
  34. package/dist/keyboard/plugins/control.js +4 -12
  35. package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
  36. package/dist/keyboard/plugins/functional.js +23 -11
  37. package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -1
  38. package/dist/keyboard/plugins/index.js +4 -11
  39. package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
  40. package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
  41. package/dist/{src/keyboard → keyboard}/types.d.ts +0 -2
  42. package/dist/paste.d.ts +6 -0
  43. package/dist/paste.js +40 -43
  44. package/dist/{src/pointer → pointer}/index.d.ts +0 -0
  45. package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
  46. package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
  47. package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
  48. package/dist/pointer/pointerAction.js +2 -26
  49. package/dist/pointer/pointerMove.d.ts +5 -0
  50. package/dist/pointer/pointerMove.js +49 -5
  51. package/dist/pointer/pointerPress.d.ts +7 -0
  52. package/dist/pointer/pointerPress.js +135 -29
  53. package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
  54. package/dist/pointer/resolveSelectionTarget.js +75 -0
  55. package/dist/{src/pointer → pointer}/types.d.ts +18 -4
  56. package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +2 -2
  57. package/dist/selectOptions.js +25 -26
  58. package/dist/{src/setup.d.ts → setup.d.ts} +5 -2
  59. package/dist/setup.js +32 -21
  60. package/dist/tab.d.ts +5 -0
  61. package/dist/tab.js +3 -132
  62. package/dist/{src/type.d.ts → type.d.ts} +0 -0
  63. package/dist/type.js +3 -19
  64. package/dist/{src/upload.d.ts → upload.d.ts} +0 -1
  65. package/dist/upload.js +1 -1
  66. package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
  67. package/dist/utils/dataTransfer/Blob.d.ts +1 -0
  68. package/dist/utils/dataTransfer/Blob.js +21 -0
  69. package/dist/utils/dataTransfer/Clipboard.d.ts +7 -0
  70. package/dist/utils/dataTransfer/Clipboard.js +143 -0
  71. package/dist/utils/dataTransfer/DataTransfer.d.ts +1 -0
  72. package/dist/utils/dataTransfer/DataTransfer.js +143 -0
  73. package/dist/utils/dataTransfer/FileList.d.ts +1 -0
  74. package/dist/utils/dataTransfer/FileList.js +13 -0
  75. package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
  76. package/dist/utils/edit/calculateNewValue.d.ts +14 -0
  77. package/dist/utils/edit/calculateNewValue.js +19 -21
  78. package/dist/utils/edit/editInputElement.d.ts +16 -0
  79. package/dist/utils/edit/editInputElement.js +53 -0
  80. package/dist/{src/utils → utils}/edit/getValue.d.ts +0 -0
  81. package/dist/utils/edit/getValue.js +1 -3
  82. package/dist/utils/edit/isContentEditable.d.ts +7 -0
  83. package/dist/utils/edit/isContentEditable.js +14 -0
  84. package/dist/{src/utils → utils}/edit/isEditable.d.ts +1 -0
  85. package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
  86. package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
  87. package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
  88. package/dist/utils/edit/prepareInput.d.ts +7 -0
  89. package/dist/utils/edit/prepareInput.js +77 -0
  90. package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
  91. package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
  92. package/dist/utils/focus/focus.js +3 -0
  93. package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
  94. package/dist/utils/focus/getTabDestination.d.ts +1 -0
  95. package/dist/utils/focus/getTabDestination.js +71 -0
  96. package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
  97. package/dist/utils/focus/selectAll.d.ts +5 -0
  98. package/dist/utils/focus/selectAll.js +51 -0
  99. package/dist/utils/focus/selection.d.ts +42 -0
  100. package/dist/utils/focus/selection.js +190 -0
  101. package/dist/{src/utils → utils}/focus/selector.d.ts +0 -0
  102. package/dist/{src/utils → utils}/index.d.ts +9 -5
  103. package/dist/utils/index.js +98 -46
  104. package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
  105. package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
  106. package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
  107. package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
  108. package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
  109. package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
  110. package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
  111. package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
  112. package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
  113. package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
  114. package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +13 -11
  115. package/dist/utils/pointer/firePointerEvents.js +62 -5
  116. package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
  117. package/package.json +2 -2
  118. package/dist/document/applyNative.js +0 -28
  119. package/dist/keyboard/specialCharMap.js +0 -30
  120. package/dist/src/document/applyNative.d.ts +0 -8
  121. package/dist/src/document/index.d.ts +0 -10
  122. package/dist/src/document/interceptor.d.ts +0 -5
  123. package/dist/src/document/selection.d.ts +0 -18
  124. package/dist/src/keyboard/specialCharMap.d.ts +0 -22
  125. package/dist/src/paste.d.ts +0 -7
  126. package/dist/src/pointer/pointerMove.d.ts +0 -5
  127. package/dist/src/pointer/pointerPress.d.ts +0 -7
  128. package/dist/src/tab.d.ts +0 -6
  129. package/dist/src/utils/edit/calculateNewValue.d.ts +0 -7
  130. package/dist/src/utils/edit/cursorPosition.d.ts +0 -2
  131. package/dist/src/utils/edit/fireInputEvent.d.ts +0 -8
  132. package/dist/src/utils/edit/isContentEditable.d.ts +0 -3
  133. package/dist/src/utils/edit/selectionRange.d.ts +0 -5
  134. package/dist/src/utils/misc/isDocument.d.ts +0 -1
  135. package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
  136. package/dist/tests/_helpers/custom-element.d.ts +0 -8
  137. package/dist/tests/_helpers/utils.d.ts +0 -73
  138. package/dist/tests/_setup-env.d.ts +0 -1
  139. package/dist/tests/clear.d.ts +0 -1
  140. package/dist/tests/click/click.d.ts +0 -1
  141. package/dist/tests/click/dblclick.d.ts +0 -1
  142. package/dist/tests/document/index.d.ts +0 -1
  143. package/dist/tests/document/selectionRange.d.ts +0 -1
  144. package/dist/tests/hover/hover.d.ts +0 -1
  145. package/dist/tests/hover/unhover.d.ts +0 -1
  146. package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
  147. package/dist/tests/keyboard/index.d.ts +0 -1
  148. package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
  149. package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
  150. package/dist/tests/keyboard/plugin/character.d.ts +0 -1
  151. package/dist/tests/keyboard/plugin/control.d.ts +0 -1
  152. package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
  153. package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
  154. package/dist/tests/paste.d.ts +0 -1
  155. package/dist/tests/pointer/index.d.ts +0 -1
  156. package/dist/tests/react/keyboard.d.ts +0 -1
  157. package/dist/tests/react/type.d.ts +0 -1
  158. package/dist/tests/selectOptions/deselect.d.ts +0 -1
  159. package/dist/tests/selectOptions/select.d.ts +0 -1
  160. package/dist/tests/setup.d.ts +0 -10
  161. package/dist/tests/tab.d.ts +0 -1
  162. package/dist/tests/type/index.d.ts +0 -1
  163. package/dist/tests/type/modifiers.d.ts +0 -1
  164. package/dist/tests/upload.d.ts +0 -1
  165. package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
  166. package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
  167. package/dist/tests/utils/focus/blur.d.ts +0 -1
  168. package/dist/tests/utils/focus/focus.d.ts +0 -1
  169. package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
  170. package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
  171. package/dist/tests/utils/misc/isElementType.d.ts +0 -1
  172. package/dist/tests/utils/misc/isVisible.d.ts +0 -1
  173. package/dist/utils/edit/cursorPosition.js +0 -35
  174. package/dist/utils/edit/fireInputEvent.js +0 -55
  175. package/dist/utils/edit/selectionRange.js +0 -64
  176. package/dist/utils/misc/dom-helpers.d.ts +0 -3
  177. package/dist/utils/misc/isDocument.js +0 -10
  178. package/dist/utils/pointer/fakeEvent.js +0 -82
@@ -1,5 +1,5 @@
1
1
  import { clear } from './clear';
2
- import { click, clickOptions, dblClick } from './click';
2
+ import { click, clickOptions, dblClick, tripleClick } from './click';
3
3
  import { hover, unhover } from './hover';
4
4
  import { keyboard, keyboardOptions } from './keyboard';
5
5
  import type { keyboardState } from './keyboard/types';
@@ -22,6 +22,7 @@ export declare const userEventApis: {
22
22
  pointer: typeof pointer;
23
23
  selectOptions: typeof selectOptions;
24
24
  tab: typeof tab;
25
+ tripleClick: typeof tripleClick;
25
26
  type: typeof type;
26
27
  unhover: typeof unhover;
27
28
  upload: typeof upload;
@@ -54,6 +55,7 @@ export declare function setup(options?: SetupOptions): {
54
55
  pointer: typeof pointer;
55
56
  selectOptions: typeof selectOptions;
56
57
  tab: typeof tab;
58
+ tripleClick: typeof tripleClick;
57
59
  type: typeof type;
58
60
  unhover: typeof unhover;
59
61
  upload: typeof upload;
@@ -72,12 +74,13 @@ export declare function setup(options?: SetupOptions): {
72
74
  pointer: typeof pointer;
73
75
  selectOptions: typeof selectOptions;
74
76
  tab: typeof tab;
77
+ tripleClick: typeof tripleClick;
75
78
  type: typeof type;
76
79
  unhover: typeof unhover;
77
80
  upload: typeof upload;
78
81
  } & any;
79
82
  };
80
- declare function _setup({ applyAccept, autoModify, delay, document, focusTrap, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
83
+ declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
81
84
  keyboardState: keyboardState;
82
85
  pointerState: pointerState;
83
86
  }): UserEventApis & {
package/dist/setup.js CHANGED
@@ -28,6 +28,8 @@ var _type = require("./type");
28
28
 
29
29
  var _upload = require("./upload");
30
30
 
31
+ var _utils = require("./utils");
32
+
31
33
  const userEventApis = {
32
34
  clear: _clear.clear,
33
35
  click: _click.click,
@@ -39,6 +41,7 @@ const userEventApis = {
39
41
  pointer: _pointer.pointer,
40
42
  selectOptions: _selectOptions.selectOptions,
41
43
  tab: _tab.tab,
44
+ tripleClick: _click.tripleClick,
42
45
  type: _type.type,
43
46
  unhover: _hover.unhover,
44
47
  upload: _upload.upload
@@ -50,9 +53,14 @@ exports.userEventApis = userEventApis;
50
53
  * All APIs returned by this function share an input device state and a default configuration.
51
54
  */
52
55
  function setup(options = {}) {
53
- var _options$document;
54
-
55
- (0, _document.prepareDocument)((_options$document = options.document) != null ? _options$document : document);
56
+ var _options$document, _doc$defaultView;
57
+
58
+ const doc = (_options$document = options.document) != null ? _options$document : document;
59
+ (0, _document.prepareDocument)(doc);
60
+ const view = (_doc$defaultView = doc.defaultView) != null ? _doc$defaultView :
61
+ /* istanbul ignore next */
62
+ window;
63
+ (0, _utils.attachClipboardStubToView)(view);
56
64
  return _setup(options, {
57
65
  keyboardState: (0, _keyboard.createKeyboardState)(),
58
66
  pointerState: (0, _pointer.createPointerState)()
@@ -64,7 +72,6 @@ function _setup({
64
72
  autoModify,
65
73
  delay = 0,
66
74
  document,
67
- focusTrap,
68
75
  keyboardMap,
69
76
  pointerMap,
70
77
  skipAutoClose,
@@ -91,8 +98,8 @@ function _setup({
91
98
  const clickDefaults = {
92
99
  skipHover
93
100
  };
94
- const tabDefaults = {
95
- focusTrap
101
+ const clipboardDefaults = {
102
+ document
96
103
  };
97
104
  const typeDefaults = {
98
105
  delay,
@@ -107,28 +114,28 @@ function _setup({
107
114
  return _clear.clear.call(userEvent, ...args);
108
115
  },
109
116
  click: (...args) => {
110
- args[2] = { ...pointerDefaults,
117
+ args[1] = { ...pointerDefaults,
111
118
  ...clickDefaults,
112
- ...args[2]
119
+ ...args[1]
113
120
  };
114
121
  return _click.click.call(userEvent, ...args);
115
122
  },
116
123
  dblClick: (...args) => {
117
- args[2] = { ...pointerDefaults,
124
+ args[1] = { ...pointerDefaults,
118
125
  ...clickDefaults,
119
- ...args[2]
126
+ ...args[1]
120
127
  };
121
128
  return _click.dblClick.call(userEvent, ...args);
122
129
  },
123
130
  deselectOptions: (...args) => {
124
- args[3] = { ...pointerDefaults,
125
- ...args[3]
131
+ args[2] = { ...pointerDefaults,
132
+ ...args[2]
126
133
  };
127
134
  return _selectOptions.deselectOptions.call(userEvent, ...args);
128
135
  },
129
136
  hover: (...args) => {
130
- args[2] = { ...pointerDefaults,
131
- ...args[2]
137
+ args[1] = { ...pointerDefaults,
138
+ ...args[1]
132
139
  };
133
140
  return _hover.hover.call(userEvent, ...args);
134
141
  },
@@ -144,7 +151,11 @@ function _setup({
144
151
  return ret.then(() => undefined);
145
152
  }
146
153
  },
154
+ // paste needs typecasting because of the overloading
147
155
  paste: (...args) => {
156
+ args[1] = { ...clipboardDefaults,
157
+ ...args[1]
158
+ };
148
159
  return _paste.paste.call(userEvent, ...args);
149
160
  },
150
161
  // pointer needs typecasting because of the overloading
@@ -161,8 +172,8 @@ function _setup({
161
172
  }
162
173
  },
163
174
  selectOptions: (...args) => {
164
- args[3] = { ...pointerDefaults,
165
- ...args[3]
175
+ args[2] = { ...pointerDefaults,
176
+ ...args[2]
166
177
  };
167
178
  return _selectOptions.selectOptions.call(userEvent, ...args);
168
179
  },
@@ -177,11 +188,11 @@ function _setup({
177
188
  });
178
189
  },
179
190
  tab: (...args) => {
180
- args[0] = { ...tabDefaults,
181
- ...args[0]
182
- };
183
191
  return _tab.tab.call(userEvent, ...args);
184
192
  },
193
+ tripleClick: (...args) => {
194
+ return _click.tripleClick.call(userEvent, ...args);
195
+ },
185
196
  // type needs typecasting because of the overloading
186
197
  type: (...args) => {
187
198
  args[2] = { ...typeDefaults,
@@ -190,8 +201,8 @@ function _setup({
190
201
  return _type.type.call(userEvent, ...args);
191
202
  },
192
203
  unhover: (...args) => {
193
- args[2] = { ...pointerDefaults,
194
- ...args[2]
204
+ args[1] = { ...pointerDefaults,
205
+ ...args[1]
195
206
  };
196
207
  return _hover.unhover.call(userEvent, ...args);
197
208
  },
package/dist/tab.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { UserEvent } from './setup';
2
+ export interface tabOptions {
3
+ shift?: boolean;
4
+ }
5
+ export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
package/dist/tab.js CHANGED
@@ -5,137 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.tab = tab;
7
7
 
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _utils = require("./utils");
11
-
12
- function getNextElement(currentIndex, shift, elements, focusTrap) {
13
- if ((0, _utils.isDocument)(focusTrap) && (currentIndex === 0 && shift || currentIndex === elements.length - 1 && !shift)) {
14
- return focusTrap.body;
15
- }
16
-
17
- const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
18
- const defaultIndex = shift ? elements.length - 1 : 0;
19
- return elements[nextIndex] || elements[defaultIndex];
20
- }
21
-
22
8
  function tab({
23
- shift = false,
24
- focusTrap
9
+ shift
25
10
  } = {}) {
26
- var _focusTrap$ownerDocum, _focusTrap;
27
-
28
- const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
29
- const previousElement = (0, _utils.getActiveElement)(doc);
30
-
31
- if (!focusTrap) {
32
- focusTrap = doc;
33
- }
34
-
35
- const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
36
- const enabledElements = Array.from(focusableElements).filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !(0, _utils.isDisabled)(el) && // Hidden elements are not tabable
37
- (0, _utils.isVisible)(el));
38
- if (enabledElements.length === 0) return;
39
- const orderedElements = enabledElements.map((el, idx) => ({
40
- el,
41
- idx
42
- })).sort((a, b) => {
43
- // tabindex has no effect if the active element has tabindex="-1"
44
- if (previousElement && previousElement.getAttribute('tabindex') === '-1') {
45
- return a.idx - b.idx;
46
- }
47
-
48
- const tabIndexA = Number(a.el.getAttribute('tabindex'));
49
- const tabIndexB = Number(b.el.getAttribute('tabindex'));
50
- const diff = tabIndexA - tabIndexB;
51
- return diff === 0 ? a.idx - b.idx : diff;
52
- }).map(({
53
- el
54
- }) => el); // TODO: verify/remove type casts
55
-
56
- const checkedRadio = {};
57
- let prunedElements = [];
58
- orderedElements.forEach(currentElement => {
59
- // For radio groups keep only the active radio
60
- // If there is no active radio, keep only the checked radio
61
- // If there is no checked radio, treat like everything else
62
- const el = currentElement;
63
-
64
- if (el.type === 'radio' && el.name) {
65
- // If the active element is part of the group, add only that
66
- const prev = previousElement;
67
-
68
- if (prev && prev.type === el.type && prev.name === el.name) {
69
- if (el === prev) {
70
- prunedElements.push(el);
71
- }
72
-
73
- return;
74
- } // If we stumble upon a checked radio, remove the others
75
-
76
-
77
- if (el.checked) {
78
- prunedElements = prunedElements.filter(e => e.type !== el.type || e.name !== el.name);
79
- prunedElements.push(el);
80
- checkedRadio[el.name] = el;
81
- return;
82
- } // If we already found the checked one, skip
83
-
84
-
85
- if (typeof checkedRadio[el.name] !== 'undefined') {
86
- return;
87
- }
88
- }
89
-
90
- prunedElements.push(el);
91
- });
92
- const index = prunedElements.findIndex(el => el === previousElement);
93
- const nextElement = getNextElement(index, shift, prunedElements, focusTrap);
94
- const shiftKeyInit = {
95
- key: 'Shift',
96
- keyCode: 16,
97
- shiftKey: true
98
- };
99
- const tabKeyInit = {
100
- key: 'Tab',
101
- keyCode: 9,
102
- shiftKey: shift
103
- };
104
- let continueToTab = true; // not sure how to make it so there's no previous element...
105
- // istanbul ignore else
106
-
107
- if (previousElement) {
108
- // preventDefault on the shift key makes no difference
109
- if (shift) _dom.fireEvent.keyDown(previousElement, { ...shiftKeyInit
110
- });
111
- continueToTab = _dom.fireEvent.keyDown(previousElement, { ...tabKeyInit
112
- });
113
- }
114
-
115
- const keyUpTarget = !continueToTab && previousElement ? previousElement : nextElement;
116
-
117
- if (continueToTab) {
118
- if (nextElement === doc.body) {
119
- /* istanbul ignore else */
120
- if (previousElement) {
121
- (0, _utils.blur)(previousElement);
122
- }
123
- } else {
124
- (0, _utils.focus)(nextElement);
125
- }
126
- }
127
-
128
- _dom.fireEvent.keyUp(keyUpTarget, { ...tabKeyInit
129
- });
130
-
131
- if (shift) {
132
- _dom.fireEvent.keyUp(keyUpTarget, { ...shiftKeyInit,
133
- shiftKey: false
134
- });
135
- }
136
- }
137
- /*
138
- eslint
139
- complexity: "off",
140
- max-statements: "off",
141
- */
11
+ this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
12
+ }
File without changes
package/dist/type.js CHANGED
@@ -47,26 +47,10 @@ async function typeImplementation(userEvent, element, text, {
47
47
  // TODO: properly type guard
48
48
  // we use this workaround for now to prevent changing behavior
49
49
  if (element.disabled) return;
50
- if (!skipClick) userEvent.click(element); // The focused element could change between each event, so get the currently active element each time
50
+ if (!skipClick) userEvent.click(element);
51
51
 
52
- const currentElement = () => (0, _utils.getActiveElement)(element.ownerDocument); // by default, a new element has its selection start and end at 0
53
- // but most of the time when people call "type", they expect it to type
54
- // at the end of the current input value. So, if the selection start
55
- // and end are both the default of 0, then we'll go ahead and change
56
- // them to the length of the current value.
57
- // the only time it would make sense to pass the initialSelectionStart or
58
- // initialSelectionEnd is if you have an input with a value and want to
59
- // explicitly start typing with the cursor at 0. Not super common.
60
-
61
-
62
- const value = (0, _utils.getValue)(currentElement());
63
- const {
64
- selectionStart,
65
- selectionEnd
66
- } = (0, _utils.getSelectionRange)(element);
67
-
68
- if (value != null && (selectionStart === null || selectionStart === 0) && (selectionEnd === null || selectionEnd === 0)) {
69
- (0, _utils.setSelectionRange)(currentElement(), initialSelectionStart != null ? initialSelectionStart : value.length, initialSelectionEnd != null ? initialSelectionEnd : value.length);
52
+ if (initialSelectionStart !== undefined) {
53
+ (0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
70
54
  }
71
55
 
72
56
  const {
@@ -1,6 +1,5 @@
1
1
  import type { UserEvent } from './setup';
2
2
  interface uploadInit {
3
- clickInit?: MouseEventInit;
4
3
  changeInit?: EventInit;
5
4
  }
6
5
  export interface uploadOptions {
package/dist/upload.js CHANGED
@@ -23,7 +23,7 @@ function upload(element, fileOrFiles, init, {
23
23
  }
24
24
 
25
25
  if ((0, _utils.isDisabled)(element)) return;
26
- this.click(element, init == null ? void 0 : init.clickInit);
26
+ this.click(element);
27
27
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
28
28
 
29
29
  (0, _utils.blur)(element); // focus fires when they make their selection
@@ -0,0 +1 @@
1
+ export declare function readBlobText(blob: Blob): Promise<string>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.readBlobText = readBlobText;
7
+
8
+ // jsdom does not implement Blob.text()
9
+ function readBlobText(blob) {
10
+ return new Promise((res, rej) => {
11
+ const fr = new FileReader();
12
+ fr.onerror = rej;
13
+ fr.onabort = rej;
14
+
15
+ fr.onload = () => {
16
+ res(String(fr.result));
17
+ };
18
+
19
+ fr.readAsText(blob);
20
+ });
21
+ }
@@ -0,0 +1,7 @@
1
+ export declare function createClipboardItem(...blobs: Array<Blob | string>): ClipboardItem;
2
+ export declare function attachClipboardStubToView(window: Window & typeof globalThis): {
3
+ resetClipboardStub: () => void;
4
+ detachClipboardStub: () => void;
5
+ };
6
+ export declare function resetClipboardStubOnView(window: Window & typeof globalThis): void;
7
+ export declare function detachClipboardStubFromView(window: Window & typeof globalThis): void;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.attachClipboardStubToView = attachClipboardStubToView;
7
+ exports.createClipboardItem = createClipboardItem;
8
+ exports.detachClipboardStubFromView = detachClipboardStubFromView;
9
+ exports.resetClipboardStubOnView = resetClipboardStubOnView;
10
+
11
+ var _ = require("..");
12
+
13
+ // Clipboard is not available in jsdom
14
+ class ClipboardItemStub {
15
+ constructor(data) {
16
+ this.data = void 0;
17
+ this.data = data;
18
+ }
19
+
20
+ get types() {
21
+ return Array.from(Object.keys(this.data));
22
+ }
23
+
24
+ async getType(type) {
25
+ const data = await this.data[type];
26
+
27
+ if (!data) {
28
+ throw new Error(`${type} is not one of the available MIME types on this item.`);
29
+ }
30
+
31
+ return data instanceof Blob ? data : new Blob([data], {
32
+ type
33
+ });
34
+ }
35
+
36
+ }
37
+
38
+ const ClipboardStubControl = Symbol('Manage ClipboardSub');
39
+
40
+ class ClipboardStub extends EventTarget {
41
+ constructor(...args) {
42
+ super(...args);
43
+ this.items = [];
44
+ this[ClipboardStubControl] = void 0;
45
+ }
46
+
47
+ async read() {
48
+ return Array.from(this.items);
49
+ }
50
+
51
+ async readText() {
52
+ let text = '';
53
+
54
+ for (const item of this.items) {
55
+ const type = item.types.includes('text/plain') ? 'text/plain' : item.types.find(t => t.startsWith('text/'));
56
+
57
+ if (type) {
58
+ text += await item.getType(type).then(b => (0, _.readBlobText)(b));
59
+ }
60
+ }
61
+
62
+ return text;
63
+ }
64
+
65
+ async write(data) {
66
+ this.items = data;
67
+ }
68
+
69
+ async writeText(text) {
70
+ this.items = [createClipboardItem(text)];
71
+ }
72
+
73
+ } // MDN lists string|Blob|Promise<Blob|string> as possible types in ClipboardItemData
74
+ // lib.dom.d.ts lists only Promise<Blob|string>
75
+ // https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/ClipboardItem#syntax
76
+
77
+
78
+ function createClipboardItem(...blobs) {
79
+ // use real ClipboardItem if available
80
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
81
+ const constructor = typeof ClipboardItem === 'undefined' ? ClipboardItemStub :
82
+ /* istanbul ignore next */
83
+ ClipboardItem;
84
+ return new constructor(Object.fromEntries(blobs.map(b => [typeof b === 'string' ? 'text/plain' : b.type, Promise.resolve(b)])));
85
+ }
86
+
87
+ function attachClipboardStubToView(window) {
88
+ if (window.navigator.clipboard instanceof ClipboardStub) {
89
+ return window.navigator.clipboard[ClipboardStubControl];
90
+ }
91
+
92
+ const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, 'clipboard');
93
+ let stub = new ClipboardStub();
94
+ const control = {
95
+ resetClipboardStub: () => {
96
+ stub = new ClipboardStub();
97
+ stub[ClipboardStubControl] = control;
98
+ },
99
+ detachClipboardStub: () => {
100
+ /* istanbul ignore if */
101
+ if (realClipboard) {
102
+ Object.defineProperty(window.navigator, 'clipboard', realClipboard);
103
+ } else {
104
+ Object.defineProperty(window.navigator, 'clipboard', {
105
+ value: undefined,
106
+ configurable: true
107
+ });
108
+ }
109
+ }
110
+ };
111
+ stub[ClipboardStubControl] = control;
112
+ Object.defineProperty(window.navigator, 'clipboard', {
113
+ get: () => stub,
114
+ configurable: true
115
+ });
116
+ return stub[ClipboardStubControl];
117
+ }
118
+
119
+ function resetClipboardStubOnView(window) {
120
+ if (window.navigator.clipboard instanceof ClipboardStub) {
121
+ window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
122
+ }
123
+ }
124
+
125
+ function detachClipboardStubFromView(window) {
126
+ if (window.navigator.clipboard instanceof ClipboardStub) {
127
+ window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
128
+ }
129
+ }
130
+ /* istanbul ignore else */
131
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
132
+
133
+
134
+ if (afterEach) {
135
+ afterEach(() => resetClipboardStubOnView(window));
136
+ }
137
+ /* istanbul ignore else */
138
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
139
+
140
+
141
+ if (afterAll) {
142
+ afterAll(() => detachClipboardStubFromView(window));
143
+ }
@@ -0,0 +1 @@
1
+ export declare function createDataTransfer(files?: File[]): DataTransfer;