@testing-library/user-event 14.0.0-beta.8 → 14.0.0-beta.9
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/dist/index.cjs +445 -385
- package/dist/index.mjs +445 -385
- 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/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +2 -1
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/types/pointer/types.d.ts +2 -1
- package/dist/types/setup/index.d.ts +2 -0
- package/dist/types/setup/setup.d.ts +1 -0
- package/dist/types/utility/clear.d.ts +1 -1
- package/dist/types/utils/edit/editInputElement.d.ts +3 -5
- package/dist/types/utils/edit/prepareInput.d.ts +2 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +2 -14
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/package.json +1 -1
- package/CHANGELOG.md +0 -5
- package/dist/types/utils/pointer/firePointerEvents.d.ts +0 -25
package/dist/index.cjs
CHANGED
|
@@ -45,187 +45,6 @@ __export(src_exports, {
|
|
|
45
45
|
default: () => userEvent
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
// src/document/index.ts
|
|
49
|
-
var import_dom = require("@testing-library/dom");
|
|
50
|
-
|
|
51
|
-
// src/document/interceptor.ts
|
|
52
|
-
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
53
|
-
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
54
|
-
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
55
|
-
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
56
|
-
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
57
|
-
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
function intercept(...args) {
|
|
61
|
-
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
62
|
-
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
63
|
-
if (target === "set") {
|
|
64
|
-
realFunc.call(this, realArgs);
|
|
65
|
-
} else {
|
|
66
|
-
realFunc.call(this, ...realArgs);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
;
|
|
70
|
-
intercept[Interceptor] = Interceptor;
|
|
71
|
-
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
72
|
-
[target]: intercept
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/document/selection.ts
|
|
77
|
-
var UISelection = Symbol("Displayed selection in UI");
|
|
78
|
-
function prepareSelectionInterceptor(element) {
|
|
79
|
-
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
80
|
-
const isUI = start && typeof start === "object" && start[UISelection];
|
|
81
|
-
if (!isUI) {
|
|
82
|
-
this[UISelection] = void 0;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
realArgs: [Number(start), end, direction]
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
89
|
-
this[UISelection] = void 0;
|
|
90
|
-
return { realArgs: v };
|
|
91
|
-
});
|
|
92
|
-
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
93
|
-
this[UISelection] = void 0;
|
|
94
|
-
return { realArgs: v };
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function setUISelection(element, {
|
|
98
|
-
focusOffset: focusOffsetParam,
|
|
99
|
-
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
100
|
-
}, mode = "replace") {
|
|
101
|
-
const valueLength = getUIValue(element).length;
|
|
102
|
-
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
103
|
-
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
104
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
105
|
-
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
106
|
-
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
107
|
-
element[UISelection] = {
|
|
108
|
-
anchorOffset,
|
|
109
|
-
focusOffset
|
|
110
|
-
};
|
|
111
|
-
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const startObj = new Number(startOffset);
|
|
115
|
-
startObj[UISelection] = UISelection;
|
|
116
|
-
try {
|
|
117
|
-
element.setSelectionRange(startObj, endOffset);
|
|
118
|
-
} catch {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function getUISelection(element) {
|
|
122
|
-
var _a, _b, _c;
|
|
123
|
-
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
124
|
-
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
125
|
-
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
126
|
-
};
|
|
127
|
-
return __spreadProps(__spreadValues({}, sel), {
|
|
128
|
-
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
129
|
-
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function clearUISelection(element) {
|
|
133
|
-
element[UISelection] = void 0;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// src/document/value.ts
|
|
137
|
-
var UIValue = Symbol("Displayed value in UI");
|
|
138
|
-
var InitialValue = Symbol("Initial value to compare on blur");
|
|
139
|
-
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
140
|
-
function valueInterceptor(v) {
|
|
141
|
-
const isUI = typeof v === "object" && v[UIValue];
|
|
142
|
-
this[UIValue] = isUI ? String(v) : void 0;
|
|
143
|
-
if (!isUI) {
|
|
144
|
-
trackValue(this, String(v));
|
|
145
|
-
this[InitialValue] = String(v);
|
|
146
|
-
clearUISelection(this);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
applyNative: !!isUI,
|
|
150
|
-
realArgs: String(v)
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function prepareValueInterceptor(element) {
|
|
154
|
-
prepareInterceptor(element, "value", valueInterceptor);
|
|
155
|
-
}
|
|
156
|
-
function setUIValue(element, value) {
|
|
157
|
-
element.value = {
|
|
158
|
-
[UIValue]: UIValue,
|
|
159
|
-
toString: () => value
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function getUIValue(element) {
|
|
163
|
-
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
164
|
-
}
|
|
165
|
-
function setInitialValue(element) {
|
|
166
|
-
element[InitialValue] = element.value;
|
|
167
|
-
}
|
|
168
|
-
function getInitialValue(element) {
|
|
169
|
-
return element[InitialValue];
|
|
170
|
-
}
|
|
171
|
-
function startTrackValue(element) {
|
|
172
|
-
element[TrackChanges] = [];
|
|
173
|
-
}
|
|
174
|
-
function trackValue(element, v) {
|
|
175
|
-
var _a;
|
|
176
|
-
(_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
|
|
177
|
-
}
|
|
178
|
-
function endTrackValue(element) {
|
|
179
|
-
const tracked = element[TrackChanges];
|
|
180
|
-
element[TrackChanges] = void 0;
|
|
181
|
-
return tracked;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/document/index.ts
|
|
185
|
-
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
186
|
-
function prepareDocument(document2) {
|
|
187
|
-
if (document2[isPrepared]) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
document2.addEventListener("focus", (e) => {
|
|
191
|
-
const el = e.target;
|
|
192
|
-
prepareElement(el);
|
|
193
|
-
}, {
|
|
194
|
-
capture: true,
|
|
195
|
-
passive: true
|
|
196
|
-
});
|
|
197
|
-
if (document2.activeElement) {
|
|
198
|
-
prepareElement(document2.activeElement);
|
|
199
|
-
}
|
|
200
|
-
document2.addEventListener("blur", (e) => {
|
|
201
|
-
const el = e.target;
|
|
202
|
-
const initialValue = getInitialValue(el);
|
|
203
|
-
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
204
|
-
import_dom.fireEvent.change(el);
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
capture: true,
|
|
208
|
-
passive: true
|
|
209
|
-
});
|
|
210
|
-
document2[isPrepared] = isPrepared;
|
|
211
|
-
}
|
|
212
|
-
function prepareElement(el) {
|
|
213
|
-
if ("value" in el) {
|
|
214
|
-
setInitialValue(el);
|
|
215
|
-
}
|
|
216
|
-
if (el[isPrepared]) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if ("value" in el) {
|
|
220
|
-
prepareValueInterceptor(el);
|
|
221
|
-
prepareSelectionInterceptor(el);
|
|
222
|
-
}
|
|
223
|
-
el[isPrepared] = isPrepared;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// src/keyboard/keyboardAction.ts
|
|
227
|
-
var import_dom10 = require("@testing-library/dom");
|
|
228
|
-
|
|
229
48
|
// src/utils/misc/isElementType.ts
|
|
230
49
|
function isElementType(element, tag, props) {
|
|
231
50
|
if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
|
|
@@ -595,9 +414,6 @@ function calculateNewValue(inputData, node, {
|
|
|
595
414
|
};
|
|
596
415
|
}
|
|
597
416
|
|
|
598
|
-
// src/utils/edit/editInputElement.ts
|
|
599
|
-
var import_dom2 = require("@testing-library/dom");
|
|
600
|
-
|
|
601
417
|
// src/utils/edit/isContentEditable.ts
|
|
602
418
|
function isContentEditable(element) {
|
|
603
419
|
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
@@ -721,7 +537,7 @@ function setSelection({
|
|
|
721
537
|
}
|
|
722
538
|
|
|
723
539
|
// src/utils/edit/editInputElement.ts
|
|
724
|
-
function editInputElement(element, {
|
|
540
|
+
function editInputElement(config, element, {
|
|
725
541
|
newValue,
|
|
726
542
|
newSelection,
|
|
727
543
|
eventOverrides
|
|
@@ -734,7 +550,7 @@ function editInputElement(element, {
|
|
|
734
550
|
focusOffset: newSelection.offset
|
|
735
551
|
});
|
|
736
552
|
startTrackValue(element);
|
|
737
|
-
|
|
553
|
+
dispatchUIEvent(config, element, "input", eventOverrides);
|
|
738
554
|
const tracked = endTrackValue(element);
|
|
739
555
|
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
740
556
|
setSelection({
|
|
@@ -786,9 +602,6 @@ function supportsMaxLength(element) {
|
|
|
786
602
|
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
787
603
|
}
|
|
788
604
|
|
|
789
|
-
// src/utils/edit/prepareInput.ts
|
|
790
|
-
var import_dom3 = require("@testing-library/dom");
|
|
791
|
-
|
|
792
605
|
// src/utils/focus/cursor.ts
|
|
793
606
|
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
794
607
|
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
|
|
@@ -893,7 +706,7 @@ function getDescendant(node, direction) {
|
|
|
893
706
|
}
|
|
894
707
|
|
|
895
708
|
// src/utils/edit/prepareInput.ts
|
|
896
|
-
function prepareInput(data, element, inputType = "insertText") {
|
|
709
|
+
function prepareInput(config, data, element, inputType = "insertText") {
|
|
897
710
|
const inputRange = getInputRange(element);
|
|
898
711
|
if (!inputRange) {
|
|
899
712
|
return;
|
|
@@ -932,7 +745,7 @@ function prepareInput(data, element, inputType = "insertText") {
|
|
|
932
745
|
}
|
|
933
746
|
}
|
|
934
747
|
if (del || data) {
|
|
935
|
-
|
|
748
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
936
749
|
}
|
|
937
750
|
}
|
|
938
751
|
};
|
|
@@ -944,7 +757,7 @@ function prepareInput(data, element, inputType = "insertText") {
|
|
|
944
757
|
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
945
758
|
return;
|
|
946
759
|
}
|
|
947
|
-
editInputElement(element, {
|
|
760
|
+
editInputElement(config, element, {
|
|
948
761
|
newValue,
|
|
949
762
|
newSelection: {
|
|
950
763
|
node: element,
|
|
@@ -1001,10 +814,10 @@ function setFiles(el, files) {
|
|
|
1001
814
|
}
|
|
1002
815
|
|
|
1003
816
|
// src/utils/misc/eventWrapper.ts
|
|
1004
|
-
var
|
|
817
|
+
var import_dom = require("@testing-library/dom");
|
|
1005
818
|
function eventWrapper(cb) {
|
|
1006
819
|
let result;
|
|
1007
|
-
(0,
|
|
820
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
1008
821
|
result = cb();
|
|
1009
822
|
});
|
|
1010
823
|
return result;
|
|
@@ -1192,6 +1005,14 @@ function isAllSelected(target) {
|
|
|
1192
1005
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1193
1006
|
}
|
|
1194
1007
|
|
|
1008
|
+
// src/utils/keyboard/getKeyEventProps.ts
|
|
1009
|
+
function getKeyEventProps(keyDef) {
|
|
1010
|
+
return {
|
|
1011
|
+
key: keyDef.key,
|
|
1012
|
+
code: keyDef.code
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1195
1016
|
// src/utils/keyboard/getUIEventModifiers.ts
|
|
1196
1017
|
function getUIEventModifiers(keyboardState) {
|
|
1197
1018
|
return {
|
|
@@ -1210,14 +1031,6 @@ function getUIEventModifiers(keyboardState) {
|
|
|
1210
1031
|
};
|
|
1211
1032
|
}
|
|
1212
1033
|
|
|
1213
|
-
// src/utils/keyboard/getKeyEventProps.ts
|
|
1214
|
-
function getKeyEventProps(keyDef, state) {
|
|
1215
|
-
return __spreadValues({
|
|
1216
|
-
key: keyDef.key,
|
|
1217
|
-
code: keyDef.code
|
|
1218
|
-
}, getUIEventModifiers(state));
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1034
|
// src/utils/keyDef/readNextDescriptor.ts
|
|
1222
1035
|
var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
1223
1036
|
bracketDict2["{"] = "}";
|
|
@@ -1296,6 +1109,11 @@ function getErrorMessage(expected, found, text) {
|
|
|
1296
1109
|
for more information about how userEvent parses your input.`;
|
|
1297
1110
|
}
|
|
1298
1111
|
|
|
1112
|
+
// src/utils/misc/cloneEvent.ts
|
|
1113
|
+
function cloneEvent(event) {
|
|
1114
|
+
return new event.constructor(event.type, event);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1299
1117
|
// src/utils/misc/getDocumentFromNode.ts
|
|
1300
1118
|
function getDocumentFromNode(el) {
|
|
1301
1119
|
return isDocument(el) ? el : el.ownerDocument;
|
|
@@ -1462,10 +1280,6 @@ function hasBitFlag(conf, flag) {
|
|
|
1462
1280
|
return (conf & flag) > 0;
|
|
1463
1281
|
}
|
|
1464
1282
|
|
|
1465
|
-
// src/utils/pointer/firePointerEvents.ts
|
|
1466
|
-
var import_dom5 = require("@testing-library/dom");
|
|
1467
|
-
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1468
|
-
|
|
1469
1283
|
// src/utils/pointer/mouseButtons.ts
|
|
1470
1284
|
var MouseButton = {
|
|
1471
1285
|
primary: 0,
|
|
@@ -1497,38 +1311,33 @@ function getMouseButtons(...buttons) {
|
|
|
1497
1311
|
return v;
|
|
1498
1312
|
}
|
|
1499
1313
|
|
|
1500
|
-
// src/
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
init.detail = clickCount;
|
|
1314
|
+
// src/event/createEvent.ts
|
|
1315
|
+
var import_dom2 = require("@testing-library/dom");
|
|
1316
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1317
|
+
|
|
1318
|
+
// src/event/eventTypes.ts
|
|
1319
|
+
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1320
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1321
|
+
function getEventClass(type3) {
|
|
1322
|
+
return import_event_map.eventMap[eventKeys[type3]].EventType;
|
|
1323
|
+
}
|
|
1324
|
+
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1325
|
+
function isMouseEvent(type3) {
|
|
1326
|
+
return mouseEvents.includes(getEventClass(type3));
|
|
1327
|
+
}
|
|
1328
|
+
function isKeyboardEvent(type3) {
|
|
1329
|
+
return getEventClass(type3) === "KeyboardEvent";
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// src/event/createEvent.ts
|
|
1333
|
+
function createEvent(type3, target, init) {
|
|
1334
|
+
const eventKey = Object.keys(import_event_map2.eventMap).find((k) => k.toLowerCase() === type3);
|
|
1335
|
+
const event = import_dom2.createEvent[eventKey](target, init);
|
|
1336
|
+
if (isMouseEvent(type3) && init) {
|
|
1337
|
+
assignPositionInit(event, init);
|
|
1338
|
+
assignPointerInit(event, init);
|
|
1526
1339
|
}
|
|
1527
|
-
|
|
1528
|
-
const event = import_dom5.createEvent[eventKey](target, init);
|
|
1529
|
-
assignPositionInit(event, init);
|
|
1530
|
-
assignPointerInit(event, init);
|
|
1531
|
-
return (0, import_dom5.fireEvent)(target, event);
|
|
1340
|
+
return event;
|
|
1532
1341
|
}
|
|
1533
1342
|
function assignProps(obj, props) {
|
|
1534
1343
|
for (const [key, value] of Object.entries(props)) {
|
|
@@ -1569,6 +1378,247 @@ function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
|
1569
1378
|
});
|
|
1570
1379
|
}
|
|
1571
1380
|
|
|
1381
|
+
// src/event/behavior/registry.ts
|
|
1382
|
+
var behavior = {};
|
|
1383
|
+
|
|
1384
|
+
// src/event/behavior/click.ts
|
|
1385
|
+
behavior.click = (event, target, config) => {
|
|
1386
|
+
var _a;
|
|
1387
|
+
const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
|
|
1388
|
+
if (control) {
|
|
1389
|
+
return () => {
|
|
1390
|
+
if (isFocusable(control)) {
|
|
1391
|
+
focus(control);
|
|
1392
|
+
}
|
|
1393
|
+
dispatchEvent(config, control, cloneEvent(event));
|
|
1394
|
+
};
|
|
1395
|
+
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1396
|
+
return () => {
|
|
1397
|
+
blur(target);
|
|
1398
|
+
target.dispatchEvent(new Event("fileDialog"));
|
|
1399
|
+
focus(target);
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// src/event/dispatchEvent.ts
|
|
1405
|
+
function dispatchEvent(config, target, event) {
|
|
1406
|
+
var _a, _b;
|
|
1407
|
+
const type3 = event.type;
|
|
1408
|
+
const behaviorImplementation = (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1409
|
+
if (behaviorImplementation) {
|
|
1410
|
+
event.preventDefault();
|
|
1411
|
+
let defaultPrevented = false;
|
|
1412
|
+
Object.defineProperty(event, "defaultPrevented", {
|
|
1413
|
+
get: () => defaultPrevented
|
|
1414
|
+
});
|
|
1415
|
+
Object.defineProperty(event, "preventDefault", {
|
|
1416
|
+
value: () => {
|
|
1417
|
+
defaultPrevented = event.cancelable;
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
target.dispatchEvent(event);
|
|
1421
|
+
if (!defaultPrevented) {
|
|
1422
|
+
behaviorImplementation();
|
|
1423
|
+
}
|
|
1424
|
+
return !defaultPrevented;
|
|
1425
|
+
}
|
|
1426
|
+
return target.dispatchEvent(event);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/event/wrapEvent.ts
|
|
1430
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1431
|
+
function wrapEvent(cb, _element) {
|
|
1432
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// src/event/index.ts
|
|
1436
|
+
function dispatchUIEvent(config, target, type3, init) {
|
|
1437
|
+
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1438
|
+
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1439
|
+
}
|
|
1440
|
+
const event = createEvent(type3, target, init);
|
|
1441
|
+
return wrapEvent(() => dispatchEvent(config, target, event), target);
|
|
1442
|
+
}
|
|
1443
|
+
function bindDispatchUIEvent(config) {
|
|
1444
|
+
return dispatchUIEvent.bind(void 0, config);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
// src/document/interceptor.ts
|
|
1448
|
+
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
1449
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
1450
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
1451
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1452
|
+
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1453
|
+
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
function intercept(...args) {
|
|
1457
|
+
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
1458
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
1459
|
+
if (target === "set") {
|
|
1460
|
+
realFunc.call(this, realArgs);
|
|
1461
|
+
} else {
|
|
1462
|
+
realFunc.call(this, ...realArgs);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
;
|
|
1466
|
+
intercept[Interceptor] = Interceptor;
|
|
1467
|
+
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
1468
|
+
[target]: intercept
|
|
1469
|
+
}));
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/document/selection.ts
|
|
1473
|
+
var UISelection = Symbol("Displayed selection in UI");
|
|
1474
|
+
function prepareSelectionInterceptor(element) {
|
|
1475
|
+
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
1476
|
+
const isUI = start && typeof start === "object" && start[UISelection];
|
|
1477
|
+
if (!isUI) {
|
|
1478
|
+
this[UISelection] = void 0;
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
realArgs: [Number(start), end, direction]
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
1485
|
+
this[UISelection] = void 0;
|
|
1486
|
+
return { realArgs: v };
|
|
1487
|
+
});
|
|
1488
|
+
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
1489
|
+
this[UISelection] = void 0;
|
|
1490
|
+
return { realArgs: v };
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
function setUISelection(element, {
|
|
1494
|
+
focusOffset: focusOffsetParam,
|
|
1495
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
1496
|
+
}, mode = "replace") {
|
|
1497
|
+
const valueLength = getUIValue(element).length;
|
|
1498
|
+
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
1499
|
+
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
1500
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1501
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
1502
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
1503
|
+
element[UISelection] = {
|
|
1504
|
+
anchorOffset,
|
|
1505
|
+
focusOffset
|
|
1506
|
+
};
|
|
1507
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
const startObj = new Number(startOffset);
|
|
1511
|
+
startObj[UISelection] = UISelection;
|
|
1512
|
+
try {
|
|
1513
|
+
element.setSelectionRange(startObj, endOffset);
|
|
1514
|
+
} catch {
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
function getUISelection(element) {
|
|
1518
|
+
var _a, _b, _c;
|
|
1519
|
+
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1520
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1521
|
+
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1522
|
+
};
|
|
1523
|
+
return __spreadProps(__spreadValues({}, sel), {
|
|
1524
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
1525
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
function clearUISelection(element) {
|
|
1529
|
+
element[UISelection] = void 0;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
// src/document/value.ts
|
|
1533
|
+
var UIValue = Symbol("Displayed value in UI");
|
|
1534
|
+
var InitialValue = Symbol("Initial value to compare on blur");
|
|
1535
|
+
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1536
|
+
function valueInterceptor(v) {
|
|
1537
|
+
const isUI = typeof v === "object" && v[UIValue];
|
|
1538
|
+
this[UIValue] = isUI ? String(v) : void 0;
|
|
1539
|
+
if (!isUI) {
|
|
1540
|
+
trackValue(this, String(v));
|
|
1541
|
+
this[InitialValue] = String(v);
|
|
1542
|
+
clearUISelection(this);
|
|
1543
|
+
}
|
|
1544
|
+
return {
|
|
1545
|
+
applyNative: !!isUI,
|
|
1546
|
+
realArgs: String(v)
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
function prepareValueInterceptor(element) {
|
|
1550
|
+
prepareInterceptor(element, "value", valueInterceptor);
|
|
1551
|
+
}
|
|
1552
|
+
function setUIValue(element, value) {
|
|
1553
|
+
element.value = {
|
|
1554
|
+
[UIValue]: UIValue,
|
|
1555
|
+
toString: () => value
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function getUIValue(element) {
|
|
1559
|
+
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
1560
|
+
}
|
|
1561
|
+
function setInitialValue(element) {
|
|
1562
|
+
element[InitialValue] = element.value;
|
|
1563
|
+
}
|
|
1564
|
+
function getInitialValue(element) {
|
|
1565
|
+
return element[InitialValue];
|
|
1566
|
+
}
|
|
1567
|
+
function startTrackValue(element) {
|
|
1568
|
+
element[TrackChanges] = [];
|
|
1569
|
+
}
|
|
1570
|
+
function trackValue(element, v) {
|
|
1571
|
+
var _a;
|
|
1572
|
+
(_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
|
|
1573
|
+
}
|
|
1574
|
+
function endTrackValue(element) {
|
|
1575
|
+
const tracked = element[TrackChanges];
|
|
1576
|
+
element[TrackChanges] = void 0;
|
|
1577
|
+
return tracked;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/document/index.ts
|
|
1581
|
+
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1582
|
+
function prepareDocument(document2) {
|
|
1583
|
+
if (document2[isPrepared]) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
document2.addEventListener("focus", (e) => {
|
|
1587
|
+
const el = e.target;
|
|
1588
|
+
prepareElement(el);
|
|
1589
|
+
}, {
|
|
1590
|
+
capture: true,
|
|
1591
|
+
passive: true
|
|
1592
|
+
});
|
|
1593
|
+
if (document2.activeElement) {
|
|
1594
|
+
prepareElement(document2.activeElement);
|
|
1595
|
+
}
|
|
1596
|
+
document2.addEventListener("blur", (e) => {
|
|
1597
|
+
const el = e.target;
|
|
1598
|
+
const initialValue = getInitialValue(el);
|
|
1599
|
+
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
1600
|
+
dispatchUIEvent({}, el, "change");
|
|
1601
|
+
}
|
|
1602
|
+
}, {
|
|
1603
|
+
capture: true,
|
|
1604
|
+
passive: true
|
|
1605
|
+
});
|
|
1606
|
+
document2[isPrepared] = isPrepared;
|
|
1607
|
+
}
|
|
1608
|
+
function prepareElement(el) {
|
|
1609
|
+
if ("value" in el) {
|
|
1610
|
+
setInitialValue(el);
|
|
1611
|
+
}
|
|
1612
|
+
if (el[isPrepared]) {
|
|
1613
|
+
return;
|
|
1614
|
+
}
|
|
1615
|
+
if ("value" in el) {
|
|
1616
|
+
prepareValueInterceptor(el);
|
|
1617
|
+
prepareSelectionInterceptor(el);
|
|
1618
|
+
}
|
|
1619
|
+
el[isPrepared] = isPrepared;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1572
1622
|
// src/keyboard/plugins/arrow.ts
|
|
1573
1623
|
var keydownBehavior = [
|
|
1574
1624
|
{
|
|
@@ -1629,21 +1679,18 @@ var keydownBehavior2 = [
|
|
|
1629
1679
|
},
|
|
1630
1680
|
{
|
|
1631
1681
|
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1632
|
-
handle: (keDef, element) => {
|
|
1682
|
+
handle: (keDef, element, config) => {
|
|
1633
1683
|
var _a;
|
|
1634
|
-
(_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1684
|
+
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1635
1685
|
}
|
|
1636
1686
|
}
|
|
1637
1687
|
];
|
|
1638
1688
|
|
|
1639
|
-
// src/keyboard/plugins/character.ts
|
|
1640
|
-
var import_dom7 = require("@testing-library/dom");
|
|
1641
|
-
|
|
1642
1689
|
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1643
|
-
|
|
1644
|
-
function fireChangeForInputTimeIfValid(el, prevValue, timeNewEntry) {
|
|
1690
|
+
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1645
1691
|
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1646
|
-
|
|
1692
|
+
setUIValue(el, timeNewEntry);
|
|
1693
|
+
dispatchUIEvent(config, el, "change");
|
|
1647
1694
|
}
|
|
1648
1695
|
}
|
|
1649
1696
|
|
|
@@ -1654,10 +1701,10 @@ var keypressBehavior = [
|
|
|
1654
1701
|
var _a;
|
|
1655
1702
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1656
1703
|
},
|
|
1657
|
-
handle: (keyDef, element,
|
|
1704
|
+
handle: (keyDef, element, config) => {
|
|
1658
1705
|
var _a;
|
|
1659
1706
|
let newEntry = keyDef.key;
|
|
1660
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1707
|
+
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1661
1708
|
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1662
1709
|
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1663
1710
|
newEntry = timeNewEntry;
|
|
@@ -1665,7 +1712,7 @@ var keypressBehavior = [
|
|
|
1665
1712
|
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1666
1713
|
const prevValue = getValue(element);
|
|
1667
1714
|
if (prevValue !== newValue) {
|
|
1668
|
-
editInputElement(element, {
|
|
1715
|
+
editInputElement(config, element, {
|
|
1669
1716
|
newValue,
|
|
1670
1717
|
newSelection: {
|
|
1671
1718
|
node: element,
|
|
@@ -1677,8 +1724,8 @@ var keypressBehavior = [
|
|
|
1677
1724
|
}
|
|
1678
1725
|
});
|
|
1679
1726
|
}
|
|
1680
|
-
fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
|
|
1681
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1727
|
+
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1728
|
+
config.keyboardState.carryValue = textToBeTyped;
|
|
1682
1729
|
}
|
|
1683
1730
|
},
|
|
1684
1731
|
{
|
|
@@ -1686,10 +1733,10 @@ var keypressBehavior = [
|
|
|
1686
1733
|
var _a;
|
|
1687
1734
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1688
1735
|
},
|
|
1689
|
-
handle: (keyDef, element,
|
|
1736
|
+
handle: (keyDef, element, config) => {
|
|
1690
1737
|
var _a;
|
|
1691
1738
|
let newEntry = keyDef.key;
|
|
1692
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1739
|
+
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1693
1740
|
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1694
1741
|
if (isValidToBeTyped) {
|
|
1695
1742
|
newEntry = textToBeTyped;
|
|
@@ -1697,7 +1744,7 @@ var keypressBehavior = [
|
|
|
1697
1744
|
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1698
1745
|
const prevValue = getValue(element);
|
|
1699
1746
|
if (prevValue !== newValue) {
|
|
1700
|
-
editInputElement(element, {
|
|
1747
|
+
editInputElement(config, element, {
|
|
1701
1748
|
newValue,
|
|
1702
1749
|
newSelection: {
|
|
1703
1750
|
node: element,
|
|
@@ -1710,11 +1757,10 @@ var keypressBehavior = [
|
|
|
1710
1757
|
});
|
|
1711
1758
|
}
|
|
1712
1759
|
if (isValidToBeTyped) {
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
});
|
|
1760
|
+
setUIValue(element, textToBeTyped);
|
|
1761
|
+
dispatchUIEvent(config, element, "change");
|
|
1716
1762
|
}
|
|
1717
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1763
|
+
config.keyboardState.carryValue = textToBeTyped;
|
|
1718
1764
|
}
|
|
1719
1765
|
},
|
|
1720
1766
|
{
|
|
@@ -1722,12 +1768,12 @@ var keypressBehavior = [
|
|
|
1722
1768
|
var _a;
|
|
1723
1769
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1724
1770
|
},
|
|
1725
|
-
handle: (keyDef, element) => {
|
|
1771
|
+
handle: (keyDef, element, config) => {
|
|
1726
1772
|
var _a, _b;
|
|
1727
1773
|
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1728
1774
|
return;
|
|
1729
1775
|
}
|
|
1730
|
-
const { getNewValue, commit } = prepareInput(keyDef.key, element);
|
|
1776
|
+
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1731
1777
|
const newValue = getNewValue();
|
|
1732
1778
|
const valueParts = newValue.split("e", 2);
|
|
1733
1779
|
if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
|
|
@@ -1741,28 +1787,27 @@ var keypressBehavior = [
|
|
|
1741
1787
|
var _a;
|
|
1742
1788
|
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1743
1789
|
},
|
|
1744
|
-
handle: (keyDef, element) => {
|
|
1790
|
+
handle: (keyDef, element, config) => {
|
|
1745
1791
|
var _a;
|
|
1746
|
-
(_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1792
|
+
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1747
1793
|
}
|
|
1748
1794
|
},
|
|
1749
1795
|
{
|
|
1750
1796
|
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1751
|
-
handle: (keyDef, element,
|
|
1797
|
+
handle: (keyDef, element, config) => {
|
|
1752
1798
|
var _a;
|
|
1753
|
-
(_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1799
|
+
(_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1754
1800
|
}
|
|
1755
1801
|
}
|
|
1756
1802
|
];
|
|
1757
1803
|
|
|
1758
1804
|
// src/keyboard/plugins/functional.ts
|
|
1759
|
-
var import_dom8 = require("@testing-library/dom");
|
|
1760
1805
|
var keydownBehavior3 = [
|
|
1761
1806
|
{
|
|
1762
1807
|
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1763
|
-
handle: (keyDef, element) => {
|
|
1808
|
+
handle: (keyDef, element, config) => {
|
|
1764
1809
|
var _a;
|
|
1765
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1810
|
+
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1766
1811
|
}
|
|
1767
1812
|
},
|
|
1768
1813
|
{
|
|
@@ -1786,25 +1831,25 @@ var keydownBehavior3 = [
|
|
|
1786
1831
|
var keypressBehavior2 = [
|
|
1787
1832
|
{
|
|
1788
1833
|
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1789
|
-
handle: (keyDef, element) => {
|
|
1834
|
+
handle: (keyDef, element, config) => {
|
|
1790
1835
|
const form = element.form;
|
|
1791
1836
|
if (hasFormSubmit(form)) {
|
|
1792
|
-
|
|
1837
|
+
dispatchUIEvent(config, form, "submit");
|
|
1793
1838
|
}
|
|
1794
1839
|
}
|
|
1795
1840
|
},
|
|
1796
1841
|
{
|
|
1797
1842
|
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1798
|
-
handle: (keyDef, element,
|
|
1799
|
-
|
|
1843
|
+
handle: (keyDef, element, config) => {
|
|
1844
|
+
dispatchUIEvent(config, element, "click");
|
|
1800
1845
|
}
|
|
1801
1846
|
},
|
|
1802
1847
|
{
|
|
1803
1848
|
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1804
|
-
handle: (keyDef, element) => {
|
|
1849
|
+
handle: (keyDef, element, config) => {
|
|
1805
1850
|
const form = element.form;
|
|
1806
1851
|
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1807
|
-
|
|
1852
|
+
dispatchUIEvent(config, form, "submit");
|
|
1808
1853
|
}
|
|
1809
1854
|
}
|
|
1810
1855
|
}
|
|
@@ -1812,8 +1857,8 @@ var keypressBehavior2 = [
|
|
|
1812
1857
|
var keyupBehavior = [
|
|
1813
1858
|
{
|
|
1814
1859
|
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1815
|
-
handle: (keyDef, element,
|
|
1816
|
-
|
|
1860
|
+
handle: (keyDef, element, config) => {
|
|
1861
|
+
dispatchUIEvent(config, element, "click");
|
|
1817
1862
|
}
|
|
1818
1863
|
}
|
|
1819
1864
|
];
|
|
@@ -1827,7 +1872,6 @@ var keydownBehavior4 = [
|
|
|
1827
1872
|
];
|
|
1828
1873
|
|
|
1829
1874
|
// src/keyboard/plugins/modifiers.ts
|
|
1830
|
-
var import_dom9 = require("@testing-library/dom");
|
|
1831
1875
|
var modifierKeys = [
|
|
1832
1876
|
"Alt",
|
|
1833
1877
|
"AltGraph",
|
|
@@ -1847,12 +1891,12 @@ var modifierLocks = [
|
|
|
1847
1891
|
var preKeydownBehavior = [
|
|
1848
1892
|
{
|
|
1849
1893
|
matches: (keyDef) => modifierKeys.includes(keyDef.key),
|
|
1850
|
-
handle: (keyDef, element,
|
|
1894
|
+
handle: (keyDef, element, config) => {
|
|
1851
1895
|
var _a;
|
|
1852
|
-
keyboardState.modifiers[keyDef.key] = true;
|
|
1896
|
+
config.keyboardState.modifiers[keyDef.key] = true;
|
|
1853
1897
|
if (keyDef.key === "AltGraph") {
|
|
1854
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1855
|
-
|
|
1898
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1899
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1856
1900
|
}
|
|
1857
1901
|
}
|
|
1858
1902
|
},
|
|
@@ -1887,10 +1931,10 @@ var preKeyupBehavior = [
|
|
|
1887
1931
|
var postKeyupBehavior = [
|
|
1888
1932
|
{
|
|
1889
1933
|
matches: (keyDef) => keyDef.key === "AltGraph",
|
|
1890
|
-
handle: (keyDef, element,
|
|
1934
|
+
handle: (keyDef, element, config) => {
|
|
1891
1935
|
var _a;
|
|
1892
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1893
|
-
|
|
1936
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1937
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1894
1938
|
}
|
|
1895
1939
|
}
|
|
1896
1940
|
];
|
|
@@ -1967,7 +2011,7 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
1967
2011
|
}
|
|
1968
2012
|
config.keyboardState.activeElement = element;
|
|
1969
2013
|
applyPlugins(preKeydownBehavior2, keyDef, element, config);
|
|
1970
|
-
const unpreventedDefault =
|
|
2014
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
1971
2015
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
1972
2016
|
if (unpreventedDefault) {
|
|
1973
2017
|
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
@@ -1976,7 +2020,7 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
1976
2020
|
}
|
|
1977
2021
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
1978
2022
|
const element = getCurrentElement();
|
|
1979
|
-
const unpreventedDefault =
|
|
2023
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
1980
2024
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
1981
2025
|
}));
|
|
1982
2026
|
if (unpreventedDefault) {
|
|
@@ -1986,7 +2030,7 @@ async function keypress(keyDef, getCurrentElement, config) {
|
|
|
1986
2030
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
1987
2031
|
const element = getCurrentElement();
|
|
1988
2032
|
applyPlugins(preKeyupBehavior2, keyDef, element, config);
|
|
1989
|
-
const unpreventedDefault =
|
|
2033
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef));
|
|
1990
2034
|
if (unprevented && unpreventedDefault) {
|
|
1991
2035
|
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
1992
2036
|
}
|
|
@@ -2039,8 +2083,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2039
2083
|
|
|
2040
2084
|
// src/keyboard/index.ts
|
|
2041
2085
|
async function keyboard(text) {
|
|
2042
|
-
const
|
|
2043
|
-
const actions = parseKeyDef(keyboardMap, text);
|
|
2086
|
+
const actions = parseKeyDef(this[Config].keyboardMap, text);
|
|
2044
2087
|
return keyboardAction(this[Config], actions);
|
|
2045
2088
|
}
|
|
2046
2089
|
function createKeyboardState() {
|
|
@@ -2085,6 +2128,34 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2085
2128
|
return defs;
|
|
2086
2129
|
}
|
|
2087
2130
|
|
|
2131
|
+
// src/pointer/firePointerEvents.ts
|
|
2132
|
+
function firePointerEvent(config, target, type3, {
|
|
2133
|
+
pointerType,
|
|
2134
|
+
button,
|
|
2135
|
+
coords,
|
|
2136
|
+
pointerId,
|
|
2137
|
+
isPrimary,
|
|
2138
|
+
clickCount
|
|
2139
|
+
}) {
|
|
2140
|
+
const init = __spreadValues({}, coords);
|
|
2141
|
+
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
2142
|
+
init.pointerId = pointerId;
|
|
2143
|
+
init.pointerType = pointerType;
|
|
2144
|
+
}
|
|
2145
|
+
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
2146
|
+
init.isPrimary = isPrimary;
|
|
2147
|
+
}
|
|
2148
|
+
init.button = getMouseButton(button != null ? button : 0);
|
|
2149
|
+
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2150
|
+
var _a;
|
|
2151
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2152
|
+
}));
|
|
2153
|
+
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2154
|
+
init.detail = clickCount;
|
|
2155
|
+
}
|
|
2156
|
+
return dispatchUIEvent(config, target, type3, init);
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2088
2159
|
// src/pointer/resolveSelectionTarget.ts
|
|
2089
2160
|
function resolveSelectionTarget({
|
|
2090
2161
|
target,
|
|
@@ -2131,7 +2202,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
2131
2202
|
|
|
2132
2203
|
// src/pointer/pointerMove.ts
|
|
2133
2204
|
async function pointerMove(config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2134
|
-
const { pointerState
|
|
2205
|
+
const { pointerState } = config;
|
|
2135
2206
|
if (!(pointerName in pointerState.position)) {
|
|
2136
2207
|
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
2137
2208
|
}
|
|
@@ -2206,9 +2277,7 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
|
|
|
2206
2277
|
}
|
|
2207
2278
|
}
|
|
2208
2279
|
function fire(eventTarget, type3, eventCoords) {
|
|
2209
|
-
return firePointerEvent(eventTarget, type3, {
|
|
2210
|
-
pointerState,
|
|
2211
|
-
keyboardState,
|
|
2280
|
+
return firePointerEvent(config, eventTarget, type3, {
|
|
2212
2281
|
coords: eventCoords,
|
|
2213
2282
|
pointerId,
|
|
2214
2283
|
pointerType
|
|
@@ -2240,7 +2309,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2240
2309
|
var _a, _b, _c;
|
|
2241
2310
|
setLevelRef(config, 2 /* Trigger */);
|
|
2242
2311
|
assertPointerEvents(config, target);
|
|
2243
|
-
const { pointerState
|
|
2312
|
+
const { pointerState } = config;
|
|
2244
2313
|
const { name, pointerType, button } = keyDef;
|
|
2245
2314
|
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2246
2315
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
@@ -2302,9 +2371,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2302
2371
|
}
|
|
2303
2372
|
return pressObj;
|
|
2304
2373
|
function fire(type3) {
|
|
2305
|
-
return firePointerEvent(target, type3, {
|
|
2306
|
-
pointerState,
|
|
2307
|
-
keyboardState,
|
|
2374
|
+
return firePointerEvent(config, target, type3, {
|
|
2308
2375
|
button,
|
|
2309
2376
|
clickCount,
|
|
2310
2377
|
coords,
|
|
@@ -2321,10 +2388,9 @@ function up(config, pointerName, {
|
|
|
2321
2388
|
node,
|
|
2322
2389
|
offset
|
|
2323
2390
|
}, pressed, targetIsDisabled) {
|
|
2324
|
-
var _a;
|
|
2325
2391
|
setLevelRef(config, 2 /* Trigger */);
|
|
2326
2392
|
assertPointerEvents(config, target);
|
|
2327
|
-
const { pointerState
|
|
2393
|
+
const { pointerState } = config;
|
|
2328
2394
|
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2329
2395
|
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2330
2396
|
let { unpreventedDefault } = pressed;
|
|
@@ -2365,21 +2431,15 @@ function up(config, pointerName, {
|
|
|
2365
2431
|
unpreventedDefault = fire("mouseup") && unpreventedDefault;
|
|
2366
2432
|
const canClick = pointerType !== "mouse" || button === "primary";
|
|
2367
2433
|
if (canClick && target === pressed.downTarget) {
|
|
2368
|
-
|
|
2434
|
+
fire("click");
|
|
2369
2435
|
if (clickCount === 2) {
|
|
2370
2436
|
fire("dblclick");
|
|
2371
2437
|
}
|
|
2372
|
-
const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
|
|
2373
|
-
if (unpreventedClick && control && isFocusable(control)) {
|
|
2374
|
-
focus(control);
|
|
2375
|
-
}
|
|
2376
2438
|
}
|
|
2377
2439
|
}
|
|
2378
2440
|
}
|
|
2379
2441
|
function fire(type3) {
|
|
2380
|
-
return firePointerEvent(target, type3, {
|
|
2381
|
-
pointerState,
|
|
2382
|
-
keyboardState,
|
|
2442
|
+
return firePointerEvent(config, target, type3, {
|
|
2383
2443
|
button,
|
|
2384
2444
|
clickCount,
|
|
2385
2445
|
coords,
|
|
@@ -2569,7 +2629,6 @@ async function tab({
|
|
|
2569
2629
|
}
|
|
2570
2630
|
|
|
2571
2631
|
// src/clipboard/copy.ts
|
|
2572
|
-
var import_dom11 = require("@testing-library/dom");
|
|
2573
2632
|
async function copy() {
|
|
2574
2633
|
var _a;
|
|
2575
2634
|
const doc = this[Config].document;
|
|
@@ -2578,7 +2637,7 @@ async function copy() {
|
|
|
2578
2637
|
if (clipboardData.items.length === 0) {
|
|
2579
2638
|
return;
|
|
2580
2639
|
}
|
|
2581
|
-
|
|
2640
|
+
this.dispatchUIEvent(target, "copy", {
|
|
2582
2641
|
clipboardData
|
|
2583
2642
|
});
|
|
2584
2643
|
if (this[Config].writeToClipboard) {
|
|
@@ -2588,7 +2647,6 @@ async function copy() {
|
|
|
2588
2647
|
}
|
|
2589
2648
|
|
|
2590
2649
|
// src/clipboard/cut.ts
|
|
2591
|
-
var import_dom12 = require("@testing-library/dom");
|
|
2592
2650
|
async function cut() {
|
|
2593
2651
|
var _a, _b;
|
|
2594
2652
|
const doc = this[Config].document;
|
|
@@ -2597,11 +2655,11 @@ async function cut() {
|
|
|
2597
2655
|
if (clipboardData.items.length === 0) {
|
|
2598
2656
|
return;
|
|
2599
2657
|
}
|
|
2600
|
-
|
|
2658
|
+
this.dispatchUIEvent(target, "cut", {
|
|
2601
2659
|
clipboardData
|
|
2602
2660
|
});
|
|
2603
2661
|
if (isEditable(target)) {
|
|
2604
|
-
(_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2662
|
+
(_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2605
2663
|
}
|
|
2606
2664
|
if (this[Config].writeToClipboard) {
|
|
2607
2665
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
@@ -2610,25 +2668,20 @@ async function cut() {
|
|
|
2610
2668
|
}
|
|
2611
2669
|
|
|
2612
2670
|
// src/clipboard/paste.ts
|
|
2613
|
-
var import_dom13 = require("@testing-library/dom");
|
|
2614
2671
|
async function paste(clipboardData) {
|
|
2615
|
-
var _a, _b;
|
|
2672
|
+
var _a, _b, _c;
|
|
2616
2673
|
const doc = this[Config].document;
|
|
2617
2674
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2618
|
-
const
|
|
2675
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2619
2676
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2620
2677
|
});
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
function pasteImpl(target, clipboardData) {
|
|
2624
|
-
var _a;
|
|
2625
|
-
import_dom13.fireEvent.paste(target, {
|
|
2626
|
-
clipboardData
|
|
2678
|
+
this.dispatchUIEvent(target, "paste", {
|
|
2679
|
+
clipboardData: dataTransfer
|
|
2627
2680
|
});
|
|
2628
2681
|
if (isEditable(target)) {
|
|
2629
|
-
const
|
|
2630
|
-
if (
|
|
2631
|
-
(
|
|
2682
|
+
const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2683
|
+
if (textData) {
|
|
2684
|
+
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2632
2685
|
}
|
|
2633
2686
|
}
|
|
2634
2687
|
}
|
|
@@ -2652,11 +2705,11 @@ async function clear(element) {
|
|
|
2652
2705
|
if (!isAllSelected(element)) {
|
|
2653
2706
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2654
2707
|
}
|
|
2655
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
2708
|
+
(_a = prepareInput(this[Config], "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
2656
2709
|
}
|
|
2657
2710
|
|
|
2658
2711
|
// src/utility/selectOptions.ts
|
|
2659
|
-
var
|
|
2712
|
+
var import_dom4 = require("@testing-library/dom");
|
|
2660
2713
|
async function selectOptions(select, values) {
|
|
2661
2714
|
return selectOptionsBase.call(this, true, select, values);
|
|
2662
2715
|
}
|
|
@@ -2665,7 +2718,7 @@ async function deselectOptions(select, values) {
|
|
|
2665
2718
|
}
|
|
2666
2719
|
async function selectOptionsBase(newValue, select, values) {
|
|
2667
2720
|
if (!newValue && !select.multiple) {
|
|
2668
|
-
throw (0,
|
|
2721
|
+
throw (0, import_dom4.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
2669
2722
|
}
|
|
2670
2723
|
const valArray = Array.isArray(values) ? values : [values];
|
|
2671
2724
|
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
@@ -2677,34 +2730,43 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2677
2730
|
if (matchingOption) {
|
|
2678
2731
|
return matchingOption;
|
|
2679
2732
|
} else {
|
|
2680
|
-
throw (0,
|
|
2733
|
+
throw (0, import_dom4.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
2681
2734
|
}
|
|
2682
2735
|
}
|
|
2683
2736
|
}).filter((option) => !isDisabled(option));
|
|
2684
2737
|
if (isDisabled(select) || !selectedOptions.length)
|
|
2685
2738
|
return;
|
|
2739
|
+
const selectOption = (option) => {
|
|
2740
|
+
option.selected = newValue;
|
|
2741
|
+
this.dispatchUIEvent(select, "input", {
|
|
2742
|
+
bubbles: true,
|
|
2743
|
+
cancelable: false,
|
|
2744
|
+
composed: true
|
|
2745
|
+
});
|
|
2746
|
+
this.dispatchUIEvent(select, "change");
|
|
2747
|
+
};
|
|
2686
2748
|
if (isElementType(select, "select")) {
|
|
2687
2749
|
if (select.multiple) {
|
|
2688
2750
|
for (const option of selectedOptions) {
|
|
2689
2751
|
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2690
2752
|
if (withPointerEvents) {
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2753
|
+
this.dispatchUIEvent(option, "pointerover");
|
|
2754
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2755
|
+
this.dispatchUIEvent(option, "mouseover");
|
|
2756
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2757
|
+
this.dispatchUIEvent(option, "pointermove");
|
|
2758
|
+
this.dispatchUIEvent(option, "mousemove");
|
|
2759
|
+
this.dispatchUIEvent(option, "pointerdown");
|
|
2760
|
+
this.dispatchUIEvent(option, "mousedown");
|
|
2699
2761
|
}
|
|
2700
2762
|
focus(select);
|
|
2701
2763
|
if (withPointerEvents) {
|
|
2702
|
-
|
|
2703
|
-
|
|
2764
|
+
this.dispatchUIEvent(option, "pointerup");
|
|
2765
|
+
this.dispatchUIEvent(option, "mouseup");
|
|
2704
2766
|
}
|
|
2705
2767
|
selectOption(option);
|
|
2706
2768
|
if (withPointerEvents) {
|
|
2707
|
-
|
|
2769
|
+
this.dispatchUIEvent(option, "click");
|
|
2708
2770
|
}
|
|
2709
2771
|
}
|
|
2710
2772
|
} else if (selectedOptions.length === 1) {
|
|
@@ -2716,16 +2778,16 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2716
2778
|
}
|
|
2717
2779
|
selectOption(selectedOptions[0]);
|
|
2718
2780
|
if (withPointerEvents) {
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2781
|
+
this.dispatchUIEvent(select, "pointerover");
|
|
2782
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2783
|
+
this.dispatchUIEvent(select, "mouseover");
|
|
2784
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2785
|
+
this.dispatchUIEvent(select, "pointerup");
|
|
2786
|
+
this.dispatchUIEvent(select, "mouseup");
|
|
2787
|
+
this.dispatchUIEvent(select, "click");
|
|
2726
2788
|
}
|
|
2727
2789
|
} else {
|
|
2728
|
-
throw (0,
|
|
2790
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2729
2791
|
}
|
|
2730
2792
|
} else if (select.getAttribute("role") === "listbox") {
|
|
2731
2793
|
for (const option of selectedOptions) {
|
|
@@ -2733,16 +2795,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2733
2795
|
await this.unhover(option);
|
|
2734
2796
|
}
|
|
2735
2797
|
} else {
|
|
2736
|
-
throw (0,
|
|
2737
|
-
}
|
|
2738
|
-
function selectOption(option) {
|
|
2739
|
-
option.selected = newValue;
|
|
2740
|
-
(0, import_dom14.fireEvent)(select, (0, import_dom14.createEvent)("input", select, {
|
|
2741
|
-
bubbles: true,
|
|
2742
|
-
cancelable: false,
|
|
2743
|
-
composed: true
|
|
2744
|
-
}));
|
|
2745
|
-
import_dom14.fireEvent.change(select);
|
|
2798
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
2746
2799
|
}
|
|
2747
2800
|
}
|
|
2748
2801
|
|
|
@@ -2768,28 +2821,29 @@ async function type(element, text, {
|
|
|
2768
2821
|
}
|
|
2769
2822
|
|
|
2770
2823
|
// src/utility/upload.ts
|
|
2771
|
-
var import_dom15 = require("@testing-library/dom");
|
|
2772
2824
|
async function upload(element, fileOrFiles) {
|
|
2773
|
-
var _a;
|
|
2774
2825
|
const input = isElementType(element, "label") ? element.control : element;
|
|
2775
2826
|
if (!input || !isElementType(input, "input", { type: "file" })) {
|
|
2776
2827
|
throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
|
|
2777
2828
|
}
|
|
2778
2829
|
if (isDisabled(element))
|
|
2779
2830
|
return;
|
|
2780
|
-
await this.click(element);
|
|
2781
2831
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2832
|
+
const fileDialog = () => {
|
|
2833
|
+
var _a;
|
|
2834
|
+
if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2835
|
+
var _a2;
|
|
2836
|
+
return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
|
|
2837
|
+
})) {
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
setFiles(input, createFileList(files));
|
|
2841
|
+
this.dispatchUIEvent(input, "input");
|
|
2842
|
+
this.dispatchUIEvent(input, "change");
|
|
2843
|
+
};
|
|
2844
|
+
input.addEventListener("fileDialog", fileDialog);
|
|
2845
|
+
await this.click(element);
|
|
2846
|
+
input.removeEventListener("fileDialog", fileDialog);
|
|
2793
2847
|
}
|
|
2794
2848
|
function isAcceptableFile(file, accept) {
|
|
2795
2849
|
if (!accept) {
|
|
@@ -2807,30 +2861,35 @@ function isAcceptableFile(file, accept) {
|
|
|
2807
2861
|
}
|
|
2808
2862
|
|
|
2809
2863
|
// src/setup/wrapAsync.ts
|
|
2810
|
-
var
|
|
2864
|
+
var import_dom5 = require("@testing-library/dom");
|
|
2811
2865
|
function wrapAsync(implementation) {
|
|
2812
|
-
return (0,
|
|
2866
|
+
return (0, import_dom5.getConfig)().asyncWrapper(implementation);
|
|
2813
2867
|
}
|
|
2814
2868
|
|
|
2815
2869
|
// src/setup/setup.ts
|
|
2870
|
+
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2871
|
+
const document2 = getDocument(options, node);
|
|
2872
|
+
const {
|
|
2873
|
+
keyboardState = createKeyboardState(),
|
|
2874
|
+
pointerState = createPointerState(document2)
|
|
2875
|
+
} = options;
|
|
2876
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2877
|
+
document: document2,
|
|
2878
|
+
keyboardState,
|
|
2879
|
+
pointerState
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2816
2882
|
function setupMain(options = {}) {
|
|
2817
2883
|
var _a;
|
|
2818
|
-
const
|
|
2819
|
-
prepareDocument(
|
|
2820
|
-
const view = (_a =
|
|
2884
|
+
const config = createConfig(options);
|
|
2885
|
+
prepareDocument(config.document);
|
|
2886
|
+
const view = (_a = config.document.defaultView) != null ? _a : window;
|
|
2821
2887
|
attachClipboardStubToView(view);
|
|
2822
|
-
return doSetup(
|
|
2823
|
-
keyboardState: createKeyboardState(),
|
|
2824
|
-
pointerState: createPointerState(doc)
|
|
2825
|
-
}));
|
|
2888
|
+
return doSetup(config);
|
|
2826
2889
|
}
|
|
2827
2890
|
function setupDirect(options = {}, node) {
|
|
2828
|
-
const
|
|
2829
|
-
prepareDocument(
|
|
2830
|
-
const config = __spreadValues(__spreadValues({
|
|
2831
|
-
keyboardState: createKeyboardState(),
|
|
2832
|
-
pointerState: createPointerState(doc)
|
|
2833
|
-
}, defaultOptionsDirect), options);
|
|
2891
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
2892
|
+
prepareDocument(config.document);
|
|
2834
2893
|
return {
|
|
2835
2894
|
config,
|
|
2836
2895
|
api: doSetup(config)
|
|
@@ -2849,7 +2908,8 @@ function wrapAndBindImpl(instance, impl) {
|
|
|
2849
2908
|
}
|
|
2850
2909
|
function doSetup(config) {
|
|
2851
2910
|
const instance = __spreadValues({
|
|
2852
|
-
[Config]: config
|
|
2911
|
+
[Config]: config,
|
|
2912
|
+
dispatchUIEvent: bindDispatchUIEvent(config)
|
|
2853
2913
|
}, api_exports);
|
|
2854
2914
|
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2855
2915
|
name,
|