@testing-library/user-event 12.7.4 → 12.8.3
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/README.md +12 -1
- package/dist/tab.js +2 -1
- package/dist/upload.js +28 -3
- package/dist/utils.js +15 -0
- package/package.json +1 -1
- package/typings/index.d.ts +7 -0
package/README.md
CHANGED
|
@@ -271,12 +271,15 @@ test('types into the input', () => {
|
|
|
271
271
|
})
|
|
272
272
|
```
|
|
273
273
|
|
|
274
|
-
### `upload(element, file, [{ clickInit, changeInit }])`
|
|
274
|
+
### `upload(element, file, [{ clickInit, changeInit }], [options])`
|
|
275
275
|
|
|
276
276
|
Uploads file to an `<input>`. For uploading multiple files use `<input>` with
|
|
277
277
|
`multiple` attribute and the second `upload` argument must be array then. Also
|
|
278
278
|
it's possible to initialize click or change event with using third argument.
|
|
279
279
|
|
|
280
|
+
If `options.applyAccept` is set to `true` and there is an `accept` attribute on
|
|
281
|
+
the element, files that don't match will be discarded.
|
|
282
|
+
|
|
280
283
|
```jsx
|
|
281
284
|
import React from 'react'
|
|
282
285
|
import {render, screen} from '@testing-library/react'
|
|
@@ -533,6 +536,8 @@ method.
|
|
|
533
536
|
| arrowRight | `{arrowright}` |
|
|
534
537
|
| arrowDown | `{arrowdown}` |
|
|
535
538
|
| arrowUp | `{arrowup}` |
|
|
539
|
+
| home | `{home}` |
|
|
540
|
+
| end | `{end}` |
|
|
536
541
|
| enter | `{enter}` |
|
|
537
542
|
| escape | `{esc}` |
|
|
538
543
|
| delete | `{del}` |
|
|
@@ -685,6 +690,12 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
685
690
|
<td align="center"><a href="http://www.alex-boyce.me/"><img src="https://avatars.githubusercontent.com/u/4050934?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alex Boyce</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=curiosity26" title="Code">💻</a></td>
|
|
686
691
|
<td align="center"><a href="https://benadamstyles.com"><img src="https://avatars.githubusercontent.com/u/4380655?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ben Styles</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=benadamstyles" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=benadamstyles" title="Tests">⚠️</a></td>
|
|
687
692
|
<td align="center"><a href="http://laurabeatris.com"><img src="https://avatars.githubusercontent.com/u/48022589?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Laura Beatris</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=LauraBeatris" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=LauraBeatris" title="Tests">⚠️</a></td>
|
|
693
|
+
<td align="center"><a href="https://twitter.com/boriscoder"><img src="https://avatars.githubusercontent.com/u/812240?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Boris Serdiuk</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Ajust-boris" title="Bug reports">🐛</a></td>
|
|
694
|
+
<td align="center"><a href="https://bozdoz.com"><img src="https://avatars.githubusercontent.com/u/1410985?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bozdoz</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=bozdoz" title="Documentation">📖</a></td>
|
|
695
|
+
</tr>
|
|
696
|
+
<tr>
|
|
697
|
+
<td align="center"><a href="https://github.com/jKatt"><img src="https://avatars.githubusercontent.com/u/5550790?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jan Kattelans</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=jKatt" title="Code">💻</a></td>
|
|
698
|
+
<td align="center"><a href="https://github.com/schoeneu"><img src="https://avatars.githubusercontent.com/u/3261341?v=4?s=100" width="100px;" alt=""/><br /><sub><b>schoeneu</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Aschoeneu" title="Bug reports">🐛</a></td>
|
|
688
699
|
</tr>
|
|
689
700
|
</table>
|
|
690
701
|
|
package/dist/tab.js
CHANGED
|
@@ -38,7 +38,8 @@ function tab({
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
|
|
41
|
-
const enabledElements = [...focusableElements].filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !el.disabled
|
|
41
|
+
const enabledElements = [...focusableElements].filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !el.disabled && // Hidden elements are not tabable
|
|
42
|
+
(0, _utils.isVisible)(el));
|
|
42
43
|
if (enabledElements.length === 0) return;
|
|
43
44
|
const orderedElements = enabledElements.map((el, idx) => ({
|
|
44
45
|
el,
|
package/dist/upload.js
CHANGED
|
@@ -13,18 +13,25 @@ var _blur = require("./blur");
|
|
|
13
13
|
|
|
14
14
|
var _focus = require("./focus");
|
|
15
15
|
|
|
16
|
-
function upload(element, fileOrFiles, init
|
|
16
|
+
function upload(element, fileOrFiles, init, {
|
|
17
|
+
applyAccept = false
|
|
18
|
+
} = {}) {
|
|
17
19
|
if (element.disabled) return;
|
|
18
20
|
(0, _click.click)(element, init);
|
|
19
21
|
const input = element.tagName === 'LABEL' ? element.control : element;
|
|
20
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
22
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, element.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
21
23
|
|
|
22
24
|
(0, _blur.blur)(element, init); // focus fires when they make their selection
|
|
23
25
|
|
|
24
|
-
(0, _focus.focus)(element, init); //
|
|
26
|
+
(0, _focus.focus)(element, init); // do not fire an input event if the file selection does not change
|
|
27
|
+
|
|
28
|
+
if (files.length === input.files.length && files.every((f, i) => f === input.files.item(i))) {
|
|
29
|
+
return;
|
|
30
|
+
} // the event fired in the browser isn't actually an "input" or "change" event
|
|
25
31
|
// but a new Event with a type set to "input" and "change"
|
|
26
32
|
// Kinda odd...
|
|
27
33
|
|
|
34
|
+
|
|
28
35
|
const inputFiles = {
|
|
29
36
|
length: files.length,
|
|
30
37
|
item: index => files[index],
|
|
@@ -46,4 +53,22 @@ function upload(element, fileOrFiles, init) {
|
|
|
46
53
|
},
|
|
47
54
|
...init
|
|
48
55
|
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isAcceptableFile(file, accept) {
|
|
59
|
+
if (!accept) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const wildcards = ['audio/*', 'image/*', 'video/*'];
|
|
64
|
+
return accept.split(',').some(acceptToken => {
|
|
65
|
+
if (acceptToken[0] === '.') {
|
|
66
|
+
// tokens starting with a dot represent a file extension
|
|
67
|
+
return file.name.endsWith(acceptToken);
|
|
68
|
+
} else if (wildcards.includes(acceptToken)) {
|
|
69
|
+
return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return file.type === acceptToken;
|
|
73
|
+
});
|
|
49
74
|
}
|
package/dist/utils.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.getValue = getValue;
|
|
|
18
18
|
exports.getSelectionRange = getSelectionRange;
|
|
19
19
|
exports.isContentEditable = isContentEditable;
|
|
20
20
|
exports.isInstanceOfElement = isInstanceOfElement;
|
|
21
|
+
exports.isVisible = isVisible;
|
|
21
22
|
exports.FOCUSABLE_SELECTOR = void 0;
|
|
22
23
|
|
|
23
24
|
var _dom = require("@testing-library/dom");
|
|
@@ -278,6 +279,20 @@ function isClickableInput(element) {
|
|
|
278
279
|
return element.tagName === 'BUTTON' || isInstanceOfElement(element, 'HTMLInputElement') && CLICKABLE_INPUT_TYPES.includes(element.type);
|
|
279
280
|
}
|
|
280
281
|
|
|
282
|
+
function isVisible(element) {
|
|
283
|
+
const getComputedStyle = (0, _helpers.getWindowFromNode)(element).getComputedStyle;
|
|
284
|
+
|
|
285
|
+
for (; element && element.ownerDocument; element = element.parentNode) {
|
|
286
|
+
const display = getComputedStyle(element).display;
|
|
287
|
+
|
|
288
|
+
if (display === 'none') {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
|
|
281
296
|
function eventWrapper(cb) {
|
|
282
297
|
let result;
|
|
283
298
|
(0, _dom.getConfig)().eventWrapper(() => {
|
package/package.json
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export interface IClickOptions {
|
|
|
26
26
|
clickCount?: number
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export interface IUploadOptions {
|
|
30
|
+
applyAccept?: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
declare const userEvent: {
|
|
30
34
|
clear: (element: TargetElement) => void
|
|
31
35
|
click: (
|
|
@@ -52,6 +56,7 @@ declare const userEvent: {
|
|
|
52
56
|
element: TargetElement,
|
|
53
57
|
files: FilesArgument,
|
|
54
58
|
init?: UploadInitArgument,
|
|
59
|
+
options?: IUploadOptions,
|
|
55
60
|
) => void
|
|
56
61
|
type: <T extends ITypeOpts>(
|
|
57
62
|
element: TargetElement,
|
|
@@ -84,6 +89,8 @@ export enum specialChars {
|
|
|
84
89
|
escape = '{esc}',
|
|
85
90
|
delete = '{del}',
|
|
86
91
|
backspace = '{backspace}',
|
|
92
|
+
home = '{home}',
|
|
93
|
+
end = '{end}',
|
|
87
94
|
selectAll = '{selectall}',
|
|
88
95
|
space = '{space}',
|
|
89
96
|
whitespace = ' ',
|