@testing-library/user-event 13.4.1 → 14.0.0-alpha.10
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 +4 -0
- package/dist/clear.d.ts +2 -2
- package/dist/clear.js +14 -29
- package/dist/click.d.ts +4 -3
- package/dist/click.js +29 -143
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +90 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +15 -57
- package/dist/index.d.ts +4 -21
- package/dist/index.js +4 -29
- package/dist/keyboard/getNextKeyDef.d.ts +3 -0
- package/dist/keyboard/getNextKeyDef.js +59 -87
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/keyboard/index.js +4 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +28 -8
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +29 -57
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +5 -16
- package/dist/keyboard/plugins/functional.js +33 -15
- package/dist/keyboard/plugins/index.js +5 -5
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +8 -0
- package/dist/paste.d.ts +3 -2
- package/dist/paste.js +8 -15
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +136 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +330 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +18 -20
- package/dist/setup.d.ts +92 -0
- package/dist/setup.js +203 -0
- package/dist/tab.d.ts +3 -4
- package/dist/tab.js +3 -136
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -3
- package/dist/upload.js +3 -9
- package/dist/utils/edit/calculateNewValue.d.ts +12 -5
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/editInputElement.js +53 -0
- package/dist/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- package/dist/utils/edit/isContentEditable.d.ts +4 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/utils/edit/isEditable.d.ts +1 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +22 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +13 -6
- package/dist/utils/index.js +145 -54
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/hasFormSubmit.d.ts +1 -0
- package/dist/utils/misc/hasFormSubmit.js +10 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +25 -0
- package/dist/utils/pointer/firePointerEvents.js +112 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.d.ts +0 -17
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/edit/selectionRange.d.ts +0 -16
- package/dist/utils/edit/selectionRange.js +0 -104
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
package/dist/setup.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setup = setup;
|
|
7
|
+
exports.userEventApis = void 0;
|
|
8
|
+
|
|
9
|
+
var _clear = require("./clear");
|
|
10
|
+
|
|
11
|
+
var _click = require("./click");
|
|
12
|
+
|
|
13
|
+
var _document = require("./document");
|
|
14
|
+
|
|
15
|
+
var _hover = require("./hover");
|
|
16
|
+
|
|
17
|
+
var _keyboard = require("./keyboard");
|
|
18
|
+
|
|
19
|
+
var _paste = require("./paste");
|
|
20
|
+
|
|
21
|
+
var _pointer = require("./pointer");
|
|
22
|
+
|
|
23
|
+
var _selectOptions = require("./selectOptions");
|
|
24
|
+
|
|
25
|
+
var _tab = require("./tab");
|
|
26
|
+
|
|
27
|
+
var _type = require("./type");
|
|
28
|
+
|
|
29
|
+
var _upload = require("./upload");
|
|
30
|
+
|
|
31
|
+
const userEventApis = {
|
|
32
|
+
clear: _clear.clear,
|
|
33
|
+
click: _click.click,
|
|
34
|
+
dblClick: _click.dblClick,
|
|
35
|
+
deselectOptions: _selectOptions.deselectOptions,
|
|
36
|
+
hover: _hover.hover,
|
|
37
|
+
keyboard: _keyboard.keyboard,
|
|
38
|
+
paste: _paste.paste,
|
|
39
|
+
pointer: _pointer.pointer,
|
|
40
|
+
selectOptions: _selectOptions.selectOptions,
|
|
41
|
+
tab: _tab.tab,
|
|
42
|
+
tripleClick: _click.tripleClick,
|
|
43
|
+
type: _type.type,
|
|
44
|
+
unhover: _hover.unhover,
|
|
45
|
+
upload: _upload.upload
|
|
46
|
+
};
|
|
47
|
+
exports.userEventApis = userEventApis;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Start a "session" with userEvent.
|
|
51
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
52
|
+
*/
|
|
53
|
+
function setup(options = {}) {
|
|
54
|
+
var _options$document;
|
|
55
|
+
|
|
56
|
+
(0, _document.prepareDocument)((_options$document = options.document) != null ? _options$document : document);
|
|
57
|
+
return _setup(options, {
|
|
58
|
+
keyboardState: (0, _keyboard.createKeyboardState)(),
|
|
59
|
+
pointerState: (0, _pointer.createPointerState)()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function _setup({
|
|
64
|
+
applyAccept,
|
|
65
|
+
autoModify,
|
|
66
|
+
delay = 0,
|
|
67
|
+
document,
|
|
68
|
+
keyboardMap,
|
|
69
|
+
pointerMap,
|
|
70
|
+
skipAutoClose,
|
|
71
|
+
skipClick,
|
|
72
|
+
skipHover,
|
|
73
|
+
skipPointerEventsCheck = false
|
|
74
|
+
}, {
|
|
75
|
+
keyboardState,
|
|
76
|
+
pointerState
|
|
77
|
+
}) {
|
|
78
|
+
const keyboardDefaults = {
|
|
79
|
+
autoModify,
|
|
80
|
+
delay,
|
|
81
|
+
document,
|
|
82
|
+
keyboardMap
|
|
83
|
+
};
|
|
84
|
+
const pointerDefaults = {
|
|
85
|
+
skipPointerEventsCheck
|
|
86
|
+
};
|
|
87
|
+
const pointerApiDefaults = {
|
|
88
|
+
delay,
|
|
89
|
+
pointerMap
|
|
90
|
+
};
|
|
91
|
+
const clickDefaults = {
|
|
92
|
+
skipHover
|
|
93
|
+
};
|
|
94
|
+
const typeDefaults = {
|
|
95
|
+
delay,
|
|
96
|
+
skipAutoClose,
|
|
97
|
+
skipClick
|
|
98
|
+
};
|
|
99
|
+
const uploadDefaults = {
|
|
100
|
+
applyAccept
|
|
101
|
+
};
|
|
102
|
+
const userEvent = {
|
|
103
|
+
clear: (...args) => {
|
|
104
|
+
return _clear.clear.call(userEvent, ...args);
|
|
105
|
+
},
|
|
106
|
+
click: (...args) => {
|
|
107
|
+
args[2] = { ...pointerDefaults,
|
|
108
|
+
...clickDefaults,
|
|
109
|
+
...args[2]
|
|
110
|
+
};
|
|
111
|
+
return _click.click.call(userEvent, ...args);
|
|
112
|
+
},
|
|
113
|
+
dblClick: (...args) => {
|
|
114
|
+
args[2] = { ...pointerDefaults,
|
|
115
|
+
...clickDefaults,
|
|
116
|
+
...args[2]
|
|
117
|
+
};
|
|
118
|
+
return _click.dblClick.call(userEvent, ...args);
|
|
119
|
+
},
|
|
120
|
+
deselectOptions: (...args) => {
|
|
121
|
+
args[3] = { ...pointerDefaults,
|
|
122
|
+
...args[3]
|
|
123
|
+
};
|
|
124
|
+
return _selectOptions.deselectOptions.call(userEvent, ...args);
|
|
125
|
+
},
|
|
126
|
+
hover: (...args) => {
|
|
127
|
+
args[2] = { ...pointerDefaults,
|
|
128
|
+
...args[2]
|
|
129
|
+
};
|
|
130
|
+
return _hover.hover.call(userEvent, ...args);
|
|
131
|
+
},
|
|
132
|
+
// keyboard needs typecasting because of the overloading
|
|
133
|
+
keyboard: (...args) => {
|
|
134
|
+
args[1] = { ...keyboardDefaults,
|
|
135
|
+
...args[1],
|
|
136
|
+
keyboardState
|
|
137
|
+
};
|
|
138
|
+
const ret = (0, _keyboard.keyboard)(...args);
|
|
139
|
+
|
|
140
|
+
if (ret instanceof Promise) {
|
|
141
|
+
return ret.then(() => undefined);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
paste: (...args) => {
|
|
145
|
+
return _paste.paste.call(userEvent, ...args);
|
|
146
|
+
},
|
|
147
|
+
// pointer needs typecasting because of the overloading
|
|
148
|
+
pointer: (...args) => {
|
|
149
|
+
args[1] = { ...pointerApiDefaults,
|
|
150
|
+
...args[1],
|
|
151
|
+
pointerState,
|
|
152
|
+
keyboardState
|
|
153
|
+
};
|
|
154
|
+
const ret = (0, _pointer.pointer)(...args);
|
|
155
|
+
|
|
156
|
+
if (ret instanceof Promise) {
|
|
157
|
+
return ret.then(() => undefined);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
selectOptions: (...args) => {
|
|
161
|
+
args[3] = { ...pointerDefaults,
|
|
162
|
+
...args[3]
|
|
163
|
+
};
|
|
164
|
+
return _selectOptions.selectOptions.call(userEvent, ...args);
|
|
165
|
+
},
|
|
166
|
+
setup: options => {
|
|
167
|
+
return _setup({ ...keyboardDefaults,
|
|
168
|
+
...pointerDefaults,
|
|
169
|
+
...clickDefaults,
|
|
170
|
+
...options
|
|
171
|
+
}, {
|
|
172
|
+
keyboardState,
|
|
173
|
+
pointerState
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
tab: (...args) => {
|
|
177
|
+
return _tab.tab.call(userEvent, ...args);
|
|
178
|
+
},
|
|
179
|
+
tripleClick: (...args) => {
|
|
180
|
+
return _click.tripleClick.call(userEvent, ...args);
|
|
181
|
+
},
|
|
182
|
+
// type needs typecasting because of the overloading
|
|
183
|
+
type: (...args) => {
|
|
184
|
+
args[2] = { ...typeDefaults,
|
|
185
|
+
...args[2]
|
|
186
|
+
};
|
|
187
|
+
return _type.type.call(userEvent, ...args);
|
|
188
|
+
},
|
|
189
|
+
unhover: (...args) => {
|
|
190
|
+
args[2] = { ...pointerDefaults,
|
|
191
|
+
...args[2]
|
|
192
|
+
};
|
|
193
|
+
return _hover.unhover.call(userEvent, ...args);
|
|
194
|
+
},
|
|
195
|
+
upload: (...args) => {
|
|
196
|
+
args[3] = { ...uploadDefaults,
|
|
197
|
+
...args[3]
|
|
198
|
+
};
|
|
199
|
+
return _upload.upload.call(userEvent, ...args);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return userEvent;
|
|
203
|
+
}
|
package/dist/tab.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export interface tabOptions {
|
|
2
3
|
shift?: boolean;
|
|
3
|
-
focusTrap?: Document | Element;
|
|
4
4
|
}
|
|
5
|
-
declare function tab({ shift
|
|
6
|
-
export { tab };
|
|
5
|
+
export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
|
package/dist/tab.js
CHANGED
|
@@ -5,141 +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
|
-
var _focus = require("./focus");
|
|
13
|
-
|
|
14
|
-
var _blur = require("./blur");
|
|
15
|
-
|
|
16
|
-
function getNextElement(currentIndex, shift, elements, focusTrap) {
|
|
17
|
-
if ((0, _utils.isDocument)(focusTrap) && (currentIndex === 0 && shift || currentIndex === elements.length - 1 && !shift)) {
|
|
18
|
-
return focusTrap.body;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
22
|
-
const defaultIndex = shift ? elements.length - 1 : 0;
|
|
23
|
-
return elements[nextIndex] || elements[defaultIndex];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
8
|
function tab({
|
|
27
|
-
shift
|
|
28
|
-
focusTrap
|
|
9
|
+
shift
|
|
29
10
|
} = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
|
|
33
|
-
const previousElement = (0, _utils.getActiveElement)(doc);
|
|
34
|
-
|
|
35
|
-
if (!focusTrap) {
|
|
36
|
-
focusTrap = doc;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
|
|
40
|
-
const enabledElements = Array.from(focusableElements).filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !(0, _utils.isDisabled)(el) && // Hidden elements are not tabable
|
|
41
|
-
(0, _utils.isVisible)(el));
|
|
42
|
-
if (enabledElements.length === 0) return;
|
|
43
|
-
const orderedElements = enabledElements.map((el, idx) => ({
|
|
44
|
-
el,
|
|
45
|
-
idx
|
|
46
|
-
})).sort((a, b) => {
|
|
47
|
-
// tabindex has no effect if the active element has tabindex="-1"
|
|
48
|
-
if (previousElement && previousElement.getAttribute('tabindex') === '-1') {
|
|
49
|
-
return a.idx - b.idx;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const tabIndexA = Number(a.el.getAttribute('tabindex'));
|
|
53
|
-
const tabIndexB = Number(b.el.getAttribute('tabindex'));
|
|
54
|
-
const diff = tabIndexA - tabIndexB;
|
|
55
|
-
return diff === 0 ? a.idx - b.idx : diff;
|
|
56
|
-
}).map(({
|
|
57
|
-
el
|
|
58
|
-
}) => el); // TODO: verify/remove type casts
|
|
59
|
-
|
|
60
|
-
const checkedRadio = {};
|
|
61
|
-
let prunedElements = [];
|
|
62
|
-
orderedElements.forEach(currentElement => {
|
|
63
|
-
// For radio groups keep only the active radio
|
|
64
|
-
// If there is no active radio, keep only the checked radio
|
|
65
|
-
// If there is no checked radio, treat like everything else
|
|
66
|
-
const el = currentElement;
|
|
67
|
-
|
|
68
|
-
if (el.type === 'radio' && el.name) {
|
|
69
|
-
// If the active element is part of the group, add only that
|
|
70
|
-
const prev = previousElement;
|
|
71
|
-
|
|
72
|
-
if (prev && prev.type === el.type && prev.name === el.name) {
|
|
73
|
-
if (el === prev) {
|
|
74
|
-
prunedElements.push(el);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return;
|
|
78
|
-
} // If we stumble upon a checked radio, remove the others
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (el.checked) {
|
|
82
|
-
prunedElements = prunedElements.filter(e => e.type !== el.type || e.name !== el.name);
|
|
83
|
-
prunedElements.push(el);
|
|
84
|
-
checkedRadio[el.name] = el;
|
|
85
|
-
return;
|
|
86
|
-
} // If we already found the checked one, skip
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
prunedElements.push(el);
|
|
95
|
-
});
|
|
96
|
-
const index = prunedElements.findIndex(el => el === previousElement);
|
|
97
|
-
const nextElement = getNextElement(index, shift, prunedElements, focusTrap);
|
|
98
|
-
const shiftKeyInit = {
|
|
99
|
-
key: 'Shift',
|
|
100
|
-
keyCode: 16,
|
|
101
|
-
shiftKey: true
|
|
102
|
-
};
|
|
103
|
-
const tabKeyInit = {
|
|
104
|
-
key: 'Tab',
|
|
105
|
-
keyCode: 9,
|
|
106
|
-
shiftKey: shift
|
|
107
|
-
};
|
|
108
|
-
let continueToTab = true; // not sure how to make it so there's no previous element...
|
|
109
|
-
// istanbul ignore else
|
|
110
|
-
|
|
111
|
-
if (previousElement) {
|
|
112
|
-
// preventDefault on the shift key makes no difference
|
|
113
|
-
if (shift) _dom.fireEvent.keyDown(previousElement, { ...shiftKeyInit
|
|
114
|
-
});
|
|
115
|
-
continueToTab = _dom.fireEvent.keyDown(previousElement, { ...tabKeyInit
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const keyUpTarget = !continueToTab && previousElement ? previousElement : nextElement;
|
|
120
|
-
|
|
121
|
-
if (continueToTab) {
|
|
122
|
-
if (nextElement === doc.body) {
|
|
123
|
-
/* istanbul ignore else */
|
|
124
|
-
if (previousElement) {
|
|
125
|
-
(0, _blur.blur)(previousElement);
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
(0, _focus.focus)(nextElement);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...tabKeyInit
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
if (shift) {
|
|
136
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...shiftKeyInit,
|
|
137
|
-
shiftKey: false
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/*
|
|
142
|
-
eslint
|
|
143
|
-
complexity: "off",
|
|
144
|
-
max-statements: "off",
|
|
145
|
-
*/
|
|
11
|
+
this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
12
|
+
}
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export interface typeOptions {
|
|
3
|
+
delay?: number;
|
|
4
|
+
skipClick?: boolean;
|
|
5
|
+
skipAutoClose?: boolean;
|
|
6
|
+
initialSelectionStart?: number;
|
|
7
|
+
initialSelectionEnd?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function type(this: UserEvent, element: Element, text: string, options?: typeOptions & {
|
|
10
|
+
delay?: 0;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function type(this: UserEvent, element: Element, text: string, options: typeOptions & {
|
|
13
|
+
delay: number;
|
|
14
|
+
}): Promise<void>;
|
package/dist/type.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.type = type;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _document = require("./document");
|
|
11
|
+
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
|
|
14
|
+
var _keyboard = require("./keyboard");
|
|
15
|
+
|
|
16
|
+
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
|
|
17
|
+
// depending on whether it will be async.
|
|
18
|
+
function type(element, text, {
|
|
19
|
+
delay = 0,
|
|
20
|
+
...options
|
|
21
|
+
} = {}) {
|
|
22
|
+
(0, _document.prepareDocument)(element.ownerDocument); // we do not want to wrap in the asyncWrapper if we're not
|
|
23
|
+
// going to actually be doing anything async, so we only wrap
|
|
24
|
+
// if the delay is greater than 0
|
|
25
|
+
|
|
26
|
+
if (delay > 0) {
|
|
27
|
+
return (0, _dom.getConfig)().asyncWrapper(() => typeImplementation(this, element, text, {
|
|
28
|
+
delay,
|
|
29
|
+
...options
|
|
30
|
+
}));
|
|
31
|
+
} else {
|
|
32
|
+
return void typeImplementation(this, element, text, {
|
|
33
|
+
delay,
|
|
34
|
+
...options
|
|
35
|
+
}) // prevents users from dealing with UnhandledPromiseRejectionWarning
|
|
36
|
+
.catch(console.error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function typeImplementation(userEvent, element, text, {
|
|
41
|
+
delay,
|
|
42
|
+
skipClick = false,
|
|
43
|
+
skipAutoClose = false,
|
|
44
|
+
initialSelectionStart = undefined,
|
|
45
|
+
initialSelectionEnd = undefined
|
|
46
|
+
}) {
|
|
47
|
+
// TODO: properly type guard
|
|
48
|
+
// we use this workaround for now to prevent changing behavior
|
|
49
|
+
if (element.disabled) return;
|
|
50
|
+
if (!skipClick) userEvent.click(element);
|
|
51
|
+
|
|
52
|
+
if (initialSelectionStart !== undefined) {
|
|
53
|
+
(0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
promise,
|
|
58
|
+
releaseAllKeys
|
|
59
|
+
} = (0, _keyboard.keyboardImplementationWrapper)(text, {
|
|
60
|
+
delay,
|
|
61
|
+
document: element.ownerDocument
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (delay > 0) {
|
|
65
|
+
await promise;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!skipAutoClose) {
|
|
69
|
+
releaseAllKeys();
|
|
70
|
+
} // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return promise;
|
|
74
|
+
}
|
package/dist/upload.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
1
2
|
interface uploadInit {
|
|
2
3
|
clickInit?: MouseEventInit;
|
|
3
4
|
changeInit?: EventInit;
|
|
4
5
|
}
|
|
5
|
-
interface uploadOptions {
|
|
6
|
+
export interface uploadOptions {
|
|
6
7
|
applyAccept?: boolean;
|
|
7
8
|
}
|
|
8
|
-
declare function upload(element: HTMLElement, fileOrFiles: File | File[], init?: uploadInit, { applyAccept }?: uploadOptions): void;
|
|
9
|
-
export {
|
|
9
|
+
export declare function upload(this: UserEvent, element: HTMLElement, fileOrFiles: File | File[], init?: uploadInit, { applyAccept }?: uploadOptions): void;
|
|
10
|
+
export {};
|
package/dist/upload.js
CHANGED
|
@@ -7,12 +7,6 @@ exports.upload = upload;
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
-
var _click = require("./click");
|
|
11
|
-
|
|
12
|
-
var _blur = require("./blur");
|
|
13
|
-
|
|
14
|
-
var _focus = require("./focus");
|
|
15
|
-
|
|
16
10
|
var _utils = require("./utils");
|
|
17
11
|
|
|
18
12
|
function upload(element, fileOrFiles, init, {
|
|
@@ -29,12 +23,12 @@ function upload(element, fileOrFiles, init, {
|
|
|
29
23
|
}
|
|
30
24
|
|
|
31
25
|
if ((0, _utils.isDisabled)(element)) return;
|
|
32
|
-
|
|
26
|
+
this.click(element, init == null ? void 0 : init.clickInit);
|
|
33
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
|
|
34
28
|
|
|
35
|
-
(0,
|
|
29
|
+
(0, _utils.blur)(element); // focus fires when they make their selection
|
|
36
30
|
|
|
37
|
-
(0,
|
|
31
|
+
(0, _utils.focus)(element); // do not fire an input event if the file selection does not change
|
|
38
32
|
|
|
39
33
|
if (files.length === ((_input$files = input.files) == null ? void 0 : _input$files.length) && files.every((f, i) => {
|
|
40
34
|
var _input$files2;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { EditableInputType } from './isEditable';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate a new text value.
|
|
4
|
+
*/
|
|
5
|
+
export declare function calculateNewValue(inputData: string, node: (HTMLInputElement & {
|
|
6
|
+
type: EditableInputType;
|
|
7
|
+
}) | HTMLTextAreaElement, { startOffset, endOffset, }: {
|
|
8
|
+
startOffset: number;
|
|
9
|
+
endOffset: number;
|
|
10
|
+
}, inputType?: string): {
|
|
11
|
+
oldValue: string;
|
|
5
12
|
newValue: string;
|
|
6
|
-
|
|
13
|
+
newOffset: number;
|
|
7
14
|
};
|
|
@@ -5,44 +5,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.calculateNewValue = calculateNewValue;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _getValue2 = require("./getValue");
|
|
8
|
+
var _document = require("../../document");
|
|
11
9
|
|
|
12
10
|
var _isValidDateValue = require("./isValidDateValue");
|
|
13
11
|
|
|
14
12
|
var _isValidInputTimeValue = require("./isValidInputTimeValue");
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const prologEnd = Math.max(0, selectionStart === selectionEnd && deleteContent === 'backward' ? selectionStart - 1 : selectionStart);
|
|
14
|
+
/**
|
|
15
|
+
* Calculate a new text value.
|
|
16
|
+
*/
|
|
17
|
+
function calculateNewValue(inputData, node, {
|
|
18
|
+
startOffset,
|
|
19
|
+
endOffset
|
|
20
|
+
}, inputType) {
|
|
21
|
+
const value = (0, _document.getUIValue)(node);
|
|
22
|
+
const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
|
|
26
23
|
const prolog = value.substring(0, prologEnd);
|
|
27
|
-
const epilogStart = Math.min(value.length,
|
|
24
|
+
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === 'deleteContentForward' ? startOffset + 1 : endOffset);
|
|
28
25
|
const epilog = value.substring(epilogStart, value.length);
|
|
29
|
-
let newValue = `${prolog}${
|
|
30
|
-
const
|
|
26
|
+
let newValue = `${prolog}${inputData}${epilog}`;
|
|
27
|
+
const newOffset = prologEnd + inputData.length;
|
|
31
28
|
|
|
32
|
-
if (
|
|
29
|
+
if (node.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(node, newValue)) {
|
|
33
30
|
newValue = value;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
if (
|
|
37
|
-
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(
|
|
38
|
-
newValue =
|
|
33
|
+
if (node.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(node, newValue)) {
|
|
34
|
+
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(node, inputData)) {
|
|
35
|
+
newValue = inputData;
|
|
39
36
|
} else {
|
|
40
37
|
newValue = value;
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
return {
|
|
42
|
+
oldValue: value,
|
|
45
43
|
newValue,
|
|
46
|
-
|
|
44
|
+
newOffset
|
|
47
45
|
};
|
|
48
46
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Change the value of an element as if it was changed as a result of a user input.
|
|
4
|
+
*
|
|
5
|
+
* Fires the input event.
|
|
6
|
+
*/
|
|
7
|
+
export declare function editInputElement(element: HTMLInputElement | HTMLTextAreaElement, { newValue, newSelection, eventOverrides, }: {
|
|
8
|
+
newValue: string;
|
|
9
|
+
newSelection: {
|
|
10
|
+
node: Node;
|
|
11
|
+
offset: number;
|
|
12
|
+
};
|
|
13
|
+
eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
|
|
14
|
+
[k: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.editInputElement = editInputElement;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
12
|
+
var _selection = require("../focus/selection");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Change the value of an element as if it was changed as a result of a user input.
|
|
16
|
+
*
|
|
17
|
+
* Fires the input event.
|
|
18
|
+
*/
|
|
19
|
+
function editInputElement(element, {
|
|
20
|
+
newValue,
|
|
21
|
+
newSelection,
|
|
22
|
+
eventOverrides
|
|
23
|
+
}) {
|
|
24
|
+
const oldValue = element.value; // apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
25
|
+
|
|
26
|
+
(0, _document.setUIValue)(element, newValue);
|
|
27
|
+
(0, _selection.setSelection)({
|
|
28
|
+
focusNode: newSelection.node,
|
|
29
|
+
anchorOffset: newSelection.offset,
|
|
30
|
+
focusOffset: newSelection.offset
|
|
31
|
+
}); // When the input event happens in the browser, React executes all event handlers
|
|
32
|
+
// and if they change state of a controlled value, nothing happens.
|
|
33
|
+
// But when we trigger the event handlers in test environment,
|
|
34
|
+
// the changes are rolled back by React before the state update is applied.
|
|
35
|
+
// Then the updated state is applied which results in a resetted cursor.
|
|
36
|
+
// There is probably a better way to work around if we figure out
|
|
37
|
+
// why the batched update is executed differently in our test environment.
|
|
38
|
+
|
|
39
|
+
(0, _document.startTrackValue)(element);
|
|
40
|
+
|
|
41
|
+
_dom.fireEvent.input(element, { ...eventOverrides
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const tracked = (0, _document.endTrackValue)(element);
|
|
45
|
+
|
|
46
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
47
|
+
(0, _selection.setSelection)({
|
|
48
|
+
focusNode: newSelection.node,
|
|
49
|
+
anchorOffset: newSelection.offset,
|
|
50
|
+
focusOffset: newSelection.offset
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getValue
|
|
1
|
+
export declare function getValue<T extends Element | null>(element: T): T extends HTMLInputElement | HTMLTextAreaElement ? string : string | null;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getValue = getValue;
|
|
7
7
|
|
|
8
|
+
var _document = require("../../document");
|
|
9
|
+
|
|
8
10
|
var _isContentEditable = require("./isContentEditable");
|
|
9
11
|
|
|
10
12
|
function getValue(element) {
|
|
@@ -17,5 +19,5 @@ function getValue(element) {
|
|
|
17
19
|
return element.textContent;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
return element
|
|
22
|
+
return (0, _document.getUIValue)(element);
|
|
21
23
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export declare function isContentEditable(element: Element): element is HTMLElement & {
|
|
2
2
|
contenteditable: 'true';
|
|
3
3
|
};
|
|
4
|
+
/**
|
|
5
|
+
* If a node is a contenteditable or inside one, return that element.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getContentEditable(node: Node): Element | null;
|