@testing-library/user-event 14.0.0-alpha.7 → 14.0.0-beta.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 +5 -192
- package/dist/index.cjs +3003 -0
- package/dist/index.mjs +3074 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/types/clipboard/index.d.ts +3 -0
- package/dist/types/clipboard/paste.d.ts +2 -0
- package/dist/types/convenience/click.d.ts +4 -0
- package/dist/types/convenience/hover.d.ts +3 -0
- package/dist/types/convenience/index.d.ts +3 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/{document → types/document}/index.d.ts +0 -0
- package/dist/{document → types/document}/interceptor.d.ts +0 -0
- package/dist/{document → types/document}/selection.d.ts +0 -0
- package/dist/{document → types/document}/value.d.ts +0 -0
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +3 -0
- package/dist/types/event/behavior/registry.d.ts +9 -0
- package/dist/types/event/createEvent.d.ts +8 -0
- package/dist/types/event/dispatchEvent.d.ts +2 -0
- package/dist/types/event/eventTypes.d.ts +2 -0
- package/dist/types/event/index.d.ts +6 -0
- package/dist/types/event/types.d.ts +13 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/keyboard/index.d.ts +7 -0
- package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
- package/dist/types/keyboard/keyboardAction.d.ts +10 -0
- package/dist/{keyboard/getNextKeyDef.d.ts → types/keyboard/parseKeyDef.d.ts} +4 -6
- package/dist/{keyboard → types/keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/character.d.ts +0 -0
- package/dist/types/keyboard/plugins/combination.d.ts +5 -0
- package/dist/{keyboard → types/keyboard}/plugins/control.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/functional.d.ts +0 -3
- package/dist/{keyboard → types/keyboard}/plugins/index.d.ts +0 -1
- package/dist/types/keyboard/plugins/modifiers.d.ts +8 -0
- package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +4 -0
- package/dist/{keyboard → types/keyboard}/shared/index.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/types.d.ts +22 -24
- package/dist/types/options.d.ts +117 -0
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/types/pointer/index.d.ts +10 -0
- package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
- package/dist/types/pointer/parseKeyDef.d.ts +6 -0
- package/dist/{pointer → types/pointer}/pointerAction.d.ts +3 -2
- package/dist/types/pointer/pointerMove.d.ts +6 -0
- package/dist/types/pointer/pointerPress.d.ts +8 -0
- package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
- package/dist/{pointer → types/pointer}/types.d.ts +2 -12
- package/dist/types/setup/api.d.ts +5 -0
- package/dist/types/setup/config.d.ts +10 -0
- package/dist/types/setup/directApi.d.ts +19 -0
- package/dist/types/setup/index.d.ts +36 -0
- package/dist/types/setup/setup.d.ts +20 -0
- package/dist/types/setup/wrapAsync.d.ts +4 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/types/utility/index.d.ts +4 -0
- package/dist/types/utility/selectOptions.d.ts +3 -0
- package/dist/types/utility/type.d.ts +9 -0
- package/dist/types/utility/upload.d.ts +5 -0
- package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
- package/dist/types/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/calculateNewValue.d.ts +1 -3
- package/dist/types/utils/edit/editInputElement.d.ts +14 -0
- package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
- package/dist/types/utils/edit/prepareInput.d.ts +8 -0
- package/dist/types/utils/edit/setFiles.d.ts +12 -0
- package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
- package/dist/types/utils/focus/copySelection.d.ts +1 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/{utils → types/utils}/focus/focus.d.ts +3 -0
- package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
- package/dist/types/utils/focus/selectAll.d.ts +5 -0
- package/dist/{utils → types/utils}/focus/selection.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
- package/dist/{utils → types/utils}/index.d.ts +15 -4
- package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +5 -0
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
- package/dist/types/utils/misc/level.d.ts +17 -0
- package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
- package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +13 -30
- package/CHANGELOG.md +0 -5
- package/dist/clear.d.ts +0 -2
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.js +0 -90
- package/dist/document/value.js +0 -77
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -22
- package/dist/keyboard/getEventProps.d.ts +0 -17
- package/dist/keyboard/getEventProps.js +0 -33
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/index.d.ts +0 -19
- package/dist/keyboard/index.js +0 -78
- package/dist/keyboard/keyMap.js +0 -143
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.js +0 -166
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.js +0 -140
- package/dist/keyboard/plugins/index.js +0 -40
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/keyboard/types.js +0 -19
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/pointer/index.d.ts +0 -18
- package/dist/pointer/index.js +0 -90
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.d.ts +0 -6
- package/dist/pointer/parseKeyDef.js +0 -36
- package/dist/pointer/pointerAction.js +0 -52
- package/dist/pointer/pointerMove.d.ts +0 -5
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.d.ts +0 -7
- package/dist/pointer/pointerPress.js +0 -330
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.js +0 -1
- package/dist/selectOptions.d.ts +0 -4
- package/dist/selectOptions.js +0 -142
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/upload.js +0 -92
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.js +0 -50
- package/dist/utils/edit/fireInputEvent.d.ts +0 -11
- package/dist/utils/edit/fireInputEvent.js +0 -65
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -4
- package/dist/utils/edit/prepareInput.js +0 -60
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.js +0 -71
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.js +0 -408
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.js +0 -24
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -14
- package/dist/utils/pointer/firePointerEvents.js +0 -55
- package/dist/utils/pointer/mouseButtons.js +0 -45
package/dist/setup.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
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
DELETED
package/dist/tab.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.tab = tab;
|
|
7
|
-
|
|
8
|
-
function tab({
|
|
9
|
-
shift
|
|
10
|
-
} = {}) {
|
|
11
|
-
this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
12
|
-
}
|
package/dist/type.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { UserEvent } from './setup';
|
|
2
|
-
interface uploadInit {
|
|
3
|
-
clickInit?: MouseEventInit;
|
|
4
|
-
changeInit?: EventInit;
|
|
5
|
-
}
|
|
6
|
-
export interface uploadOptions {
|
|
7
|
-
applyAccept?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function upload(this: UserEvent, element: HTMLElement, fileOrFiles: File | File[], init?: uploadInit, { applyAccept }?: uploadOptions): void;
|
|
10
|
-
export {};
|
package/dist/upload.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.upload = upload;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
function upload(element, fileOrFiles, init, {
|
|
13
|
-
applyAccept = false
|
|
14
|
-
} = {}) {
|
|
15
|
-
var _input$files;
|
|
16
|
-
|
|
17
|
-
const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
|
|
18
|
-
|
|
19
|
-
if (!input || !(0, _utils.isElementType)(input, 'input', {
|
|
20
|
-
type: 'file'
|
|
21
|
-
})) {
|
|
22
|
-
throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if ((0, _utils.isDisabled)(element)) return;
|
|
26
|
-
this.click(element, init == null ? void 0 : init.clickInit);
|
|
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
|
-
|
|
29
|
-
(0, _utils.blur)(element); // focus fires when they make their selection
|
|
30
|
-
|
|
31
|
-
(0, _utils.focus)(element); // do not fire an input event if the file selection does not change
|
|
32
|
-
|
|
33
|
-
if (files.length === ((_input$files = input.files) == null ? void 0 : _input$files.length) && files.every((f, i) => {
|
|
34
|
-
var _input$files2;
|
|
35
|
-
|
|
36
|
-
return f === ((_input$files2 = input.files) == null ? void 0 : _input$files2.item(i));
|
|
37
|
-
})) {
|
|
38
|
-
return;
|
|
39
|
-
} // the event fired in the browser isn't actually an "input" or "change" event
|
|
40
|
-
// but a new Event with a type set to "input" and "change"
|
|
41
|
-
// Kinda odd...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const inputFiles = { ...files,
|
|
45
|
-
length: files.length,
|
|
46
|
-
item: index => files[index],
|
|
47
|
-
|
|
48
|
-
[Symbol.iterator]() {
|
|
49
|
-
let i = 0;
|
|
50
|
-
return {
|
|
51
|
-
next: () => ({
|
|
52
|
-
done: i >= files.length,
|
|
53
|
-
value: files[i++]
|
|
54
|
-
})
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
(0, _dom.fireEvent)(input, (0, _dom.createEvent)('input', input, {
|
|
60
|
-
target: {
|
|
61
|
-
files: inputFiles
|
|
62
|
-
},
|
|
63
|
-
bubbles: true,
|
|
64
|
-
cancelable: false,
|
|
65
|
-
composed: true
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
_dom.fireEvent.change(input, {
|
|
69
|
-
target: {
|
|
70
|
-
files: inputFiles
|
|
71
|
-
},
|
|
72
|
-
...(init == null ? void 0 : init.changeInit)
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function isAcceptableFile(file, accept) {
|
|
77
|
-
if (!accept) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const wildcards = ['audio/*', 'image/*', 'video/*'];
|
|
82
|
-
return accept.split(',').some(acceptToken => {
|
|
83
|
-
if (acceptToken.startsWith('.')) {
|
|
84
|
-
// tokens starting with a dot represent a file extension
|
|
85
|
-
return file.name.endsWith(acceptToken);
|
|
86
|
-
} else if (wildcards.includes(acceptToken)) {
|
|
87
|
-
return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return file.type === acceptToken;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isClickableInput = isClickableInput;
|
|
7
|
-
|
|
8
|
-
var _isElementType = require("../misc/isElementType");
|
|
9
|
-
|
|
10
|
-
const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit', 'checkbox', 'radio'];
|
|
11
|
-
|
|
12
|
-
function isClickableInput(element) {
|
|
13
|
-
return (0, _isElementType.isElementType)(element, 'button') || (0, _isElementType.isElementType)(element, 'input') && CLICKABLE_INPUT_TYPES.includes(element.type);
|
|
14
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.buildTimeValue = buildTimeValue;
|
|
7
|
-
|
|
8
|
-
function buildTimeValue(value) {
|
|
9
|
-
const onlyDigitsValue = value.replace(/\D/g, '');
|
|
10
|
-
|
|
11
|
-
if (onlyDigitsValue.length < 2) {
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const firstDigit = parseInt(onlyDigitsValue[0], 10);
|
|
16
|
-
const secondDigit = parseInt(onlyDigitsValue[1], 10);
|
|
17
|
-
|
|
18
|
-
if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
|
|
19
|
-
let index;
|
|
20
|
-
|
|
21
|
-
if (firstDigit >= 3) {
|
|
22
|
-
index = 1;
|
|
23
|
-
} else {
|
|
24
|
-
index = 2;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return build(onlyDigitsValue, index);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (value.length === 2) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return build(onlyDigitsValue, 2);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function build(onlyDigitsValue, index) {
|
|
38
|
-
const hours = onlyDigitsValue.slice(0, index);
|
|
39
|
-
const validHours = Math.min(parseInt(hours, 10), 23);
|
|
40
|
-
const minuteCharacters = onlyDigitsValue.slice(index);
|
|
41
|
-
const parsedMinutes = parseInt(minuteCharacters, 10);
|
|
42
|
-
const validMinutes = Math.min(parsedMinutes, 59);
|
|
43
|
-
return `${validHours.toString().padStart(2, '0')}:${validMinutes.toString().padStart(2, '0')}`;
|
|
44
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.calculateNewValue = calculateNewValue;
|
|
7
|
-
|
|
8
|
-
var _document = require("../../document");
|
|
9
|
-
|
|
10
|
-
var _isValidDateValue = require("./isValidDateValue");
|
|
11
|
-
|
|
12
|
-
var _isValidInputTimeValue = require("./isValidInputTimeValue");
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Calculate a new text value.
|
|
16
|
-
*/
|
|
17
|
-
// This implementation does not properly calculate a new DOM state.
|
|
18
|
-
// It only handles text values and neither cares for DOM offsets nor accounts for non-character elements.
|
|
19
|
-
// It can be used for text nodes and elements supporting value property.
|
|
20
|
-
// TODO: The implementation of `deleteContent` is brittle and should be replaced.
|
|
21
|
-
function calculateNewValue(inputData, node, {
|
|
22
|
-
startOffset,
|
|
23
|
-
endOffset
|
|
24
|
-
}, inputType) {
|
|
25
|
-
const value = node.nodeType === 3 ? String(node.nodeValue) : (0, _document.getUIValue)(node);
|
|
26
|
-
const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
|
|
27
|
-
const prolog = value.substring(0, prologEnd);
|
|
28
|
-
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === 'deleteContentForward' ? startOffset + 1 : endOffset);
|
|
29
|
-
const epilog = value.substring(epilogStart, value.length);
|
|
30
|
-
let newValue = `${prolog}${inputData}${epilog}`;
|
|
31
|
-
const newOffset = prologEnd + inputData.length;
|
|
32
|
-
|
|
33
|
-
if (node.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(node, newValue)) {
|
|
34
|
-
newValue = value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (node.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(node, newValue)) {
|
|
38
|
-
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(node, inputData)) {
|
|
39
|
-
newValue = inputData;
|
|
40
|
-
} else {
|
|
41
|
-
newValue = value;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
oldValue: value,
|
|
47
|
-
newValue,
|
|
48
|
-
newOffset
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { fireEvent } from '@testing-library/dom';
|
|
2
|
-
export declare function fireInputEvent(element: HTMLElement, { newValue, newSelection, eventOverrides, }: {
|
|
3
|
-
newValue: string;
|
|
4
|
-
newSelection: {
|
|
5
|
-
node: Node;
|
|
6
|
-
offset: number;
|
|
7
|
-
};
|
|
8
|
-
eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
|
|
9
|
-
[k: string]: unknown;
|
|
10
|
-
};
|
|
11
|
-
}): void;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fireInputEvent = fireInputEvent;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _document = require("../../document");
|
|
11
|
-
|
|
12
|
-
var _isElementType = require("../misc/isElementType");
|
|
13
|
-
|
|
14
|
-
var _selection = require("../focus/selection");
|
|
15
|
-
|
|
16
|
-
function fireInputEvent(element, {
|
|
17
|
-
newValue,
|
|
18
|
-
newSelection,
|
|
19
|
-
eventOverrides
|
|
20
|
-
}) {
|
|
21
|
-
const oldValue = element.value; // apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
22
|
-
|
|
23
|
-
if ((0, _isElementType.isElementType)(element, ['input', 'textarea'])) {
|
|
24
|
-
(0, _document.setUIValue)(element, newValue);
|
|
25
|
-
} else {
|
|
26
|
-
// The pre-commit hooks keeps changing this
|
|
27
|
-
// See https://github.com/kentcdodds/kcd-scripts/issues/218
|
|
28
|
-
|
|
29
|
-
/* istanbul ignore else */
|
|
30
|
-
// eslint-disable-next-line no-lonely-if
|
|
31
|
-
if (newSelection.node.nodeType === 3) {
|
|
32
|
-
newSelection.node.textContent = newValue;
|
|
33
|
-
} else {
|
|
34
|
-
// TODO: properly type guard
|
|
35
|
-
throw new Error('Invalid Element');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
(0, _selection.setSelection)({
|
|
40
|
-
focusNode: newSelection.node,
|
|
41
|
-
anchorOffset: newSelection.offset,
|
|
42
|
-
focusOffset: newSelection.offset
|
|
43
|
-
}); // When the input event happens in the browser, React executes all event handlers
|
|
44
|
-
// and if they change state of a controlled value, nothing happens.
|
|
45
|
-
// But when we trigger the event handlers in test environment,
|
|
46
|
-
// the changes are rolled back by React before the state update is applied.
|
|
47
|
-
// Then the updated state is applied which results in a resetted cursor.
|
|
48
|
-
// There is probably a better way to work around if we figure out
|
|
49
|
-
// why the batched update is executed differently in our test environment.
|
|
50
|
-
|
|
51
|
-
(0, _document.startTrackValue)(element);
|
|
52
|
-
|
|
53
|
-
_dom.fireEvent.input(element, { ...eventOverrides
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const tracked = (0, _document.endTrackValue)(element);
|
|
57
|
-
|
|
58
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
59
|
-
(0, _selection.setSelection)({
|
|
60
|
-
focusNode: newSelection.node,
|
|
61
|
-
anchorOffset: newSelection.offset,
|
|
62
|
-
focusOffset: newSelection.offset
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getValue = getValue;
|
|
7
|
-
|
|
8
|
-
var _document = require("../../document");
|
|
9
|
-
|
|
10
|
-
var _isContentEditable = require("./isContentEditable");
|
|
11
|
-
|
|
12
|
-
function getValue(element) {
|
|
13
|
-
// istanbul ignore if
|
|
14
|
-
if (!element) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if ((0, _isContentEditable.isContentEditable)(element)) {
|
|
19
|
-
return element.textContent;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return (0, _document.getUIValue)(element);
|
|
23
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getContentEditable = getContentEditable;
|
|
7
|
-
exports.isContentEditable = isContentEditable;
|
|
8
|
-
|
|
9
|
-
//jsdom is not supporting isContentEditable
|
|
10
|
-
function isContentEditable(element) {
|
|
11
|
-
return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* If a node is a contenteditable or inside one, return that element.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function getContentEditable(node) {
|
|
19
|
-
const element = getElement(node);
|
|
20
|
-
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getElement(node) {
|
|
24
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
25
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.editableInputTypes = void 0;
|
|
7
|
-
exports.isEditable = isEditable;
|
|
8
|
-
exports.isEditableInput = isEditableInput;
|
|
9
|
-
|
|
10
|
-
var _isElementType = require("../misc/isElementType");
|
|
11
|
-
|
|
12
|
-
var _isContentEditable = require("./isContentEditable");
|
|
13
|
-
|
|
14
|
-
function isEditable(element) {
|
|
15
|
-
return isEditableInput(element) || (0, _isElementType.isElementType)(element, 'textarea', {
|
|
16
|
-
readOnly: false
|
|
17
|
-
}) || (0, _isContentEditable.isContentEditable)(element);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let editableInputTypes;
|
|
21
|
-
exports.editableInputTypes = editableInputTypes;
|
|
22
|
-
|
|
23
|
-
(function (editableInputTypes) {
|
|
24
|
-
editableInputTypes["text"] = "text";
|
|
25
|
-
editableInputTypes["date"] = "date";
|
|
26
|
-
editableInputTypes["datetime-local"] = "datetime-local";
|
|
27
|
-
editableInputTypes["email"] = "email";
|
|
28
|
-
editableInputTypes["month"] = "month";
|
|
29
|
-
editableInputTypes["number"] = "number";
|
|
30
|
-
editableInputTypes["password"] = "password";
|
|
31
|
-
editableInputTypes["search"] = "search";
|
|
32
|
-
editableInputTypes["tel"] = "tel";
|
|
33
|
-
editableInputTypes["time"] = "time";
|
|
34
|
-
editableInputTypes["url"] = "url";
|
|
35
|
-
editableInputTypes["week"] = "week";
|
|
36
|
-
})(editableInputTypes || (exports.editableInputTypes = editableInputTypes = {}));
|
|
37
|
-
|
|
38
|
-
function isEditableInput(element) {
|
|
39
|
-
return (0, _isElementType.isElementType)(element, 'input', {
|
|
40
|
-
readOnly: false
|
|
41
|
-
}) && Boolean(editableInputTypes[element.type]);
|
|
42
|
-
}
|