@testing-library/user-event 13.0.10 → 13.0.14
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/clear.js +7 -9
- package/dist/click.js +5 -7
- package/dist/keyboard/plugins/arrow.js +3 -3
- package/dist/keyboard/plugins/character.js +51 -34
- package/dist/keyboard/plugins/control.js +14 -10
- package/dist/keyboard/plugins/functional.js +7 -13
- package/dist/keyboard/plugins/index.js +5 -4
- package/dist/keyboard/shared/carryValue.d.ts +2 -0
- package/dist/keyboard/shared/carryValue.js +13 -0
- package/dist/keyboard/shared/{fireInputEventIfNeeded.d.ts → fireInputEvent.d.ts} +2 -5
- package/dist/keyboard/shared/fireInputEvent.js +59 -0
- package/dist/keyboard/shared/index.d.ts +2 -2
- package/dist/keyboard/shared/index.js +12 -12
- package/dist/paste.js +22 -19
- package/dist/select-options.js +1 -1
- package/dist/type/typeImplementation.js +3 -15
- package/dist/upload.js +1 -1
- package/dist/utils/click/isClickableInput.js +2 -2
- package/dist/utils/edit/calculateNewValue.d.ts +2 -2
- package/dist/utils/edit/calculateNewValue.js +21 -73
- package/dist/utils/edit/cursorPosition.d.ts +2 -0
- package/dist/utils/edit/cursorPosition.js +35 -0
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +10 -0
- package/dist/utils/edit/hasUnreliableEmptyValue.js +21 -0
- package/dist/utils/edit/isContentEditable.d.ts +3 -1
- package/dist/utils/edit/isEditable.d.ts +24 -0
- package/dist/utils/edit/isEditable.js +40 -0
- package/dist/utils/edit/maxLength.d.ts +1 -0
- package/dist/utils/edit/maxLength.js +50 -0
- package/dist/utils/edit/selectionRange.d.ts +16 -0
- package/dist/utils/edit/selectionRange.js +99 -0
- package/dist/utils/index.d.ts +6 -3
- package/dist/utils/index.js +51 -12
- package/dist/utils/misc/isElementType.d.ts +5 -0
- package/dist/utils/misc/isElementType.js +24 -0
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +2 -2
- package/package.json +1 -1
- package/dist/keyboard/plugins/control/calculateNewDeleteValue.d.ts +0 -4
- package/dist/keyboard/plugins/control/calculateNewDeleteValue.js +0 -46
- package/dist/keyboard/plugins/functional/calculateBackspaceValue.d.ts +0 -4
- package/dist/keyboard/plugins/functional/calculateBackspaceValue.js +0 -57
- package/dist/keyboard/shared/fireInputEventIfNeeded.js +0 -58
- package/dist/keyboard/shared/setSelectionRange.d.ts +0 -5
- package/dist/keyboard/shared/setSelectionRange.js +0 -32
- package/dist/utils/edit/getSelectionRange.d.ts +0 -4
- package/dist/utils/edit/getSelectionRange.js +0 -32
- package/dist/utils/edit/setSelectionRangeIfNecessary.d.ts +0 -1
- package/dist/utils/edit/setSelectionRangeIfNecessary.js +0 -44
- package/dist/utils/misc/isInstanceOfElement.d.ts +0 -7
- package/dist/utils/misc/isInstanceOfElement.js +0 -38
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.calculateNewDeleteValue = calculateNewDeleteValue;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../../utils");
|
|
9
|
-
|
|
10
|
-
function calculateNewDeleteValue(element) {
|
|
11
|
-
var _getValue;
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
selectionStart,
|
|
15
|
-
selectionEnd
|
|
16
|
-
} = (0, _utils.getSelectionRange)(element); // istanbul ignore next
|
|
17
|
-
|
|
18
|
-
const value = (_getValue = (0, _utils.getValue)(element)) != null ? _getValue : '';
|
|
19
|
-
let newValue;
|
|
20
|
-
|
|
21
|
-
if (selectionStart === null) {
|
|
22
|
-
// at the end of an input type that does not support selection ranges
|
|
23
|
-
// https://github.com/testing-library/user-event/issues/316#issuecomment-639744793
|
|
24
|
-
newValue = value;
|
|
25
|
-
} else if (selectionStart === selectionEnd) {
|
|
26
|
-
if (selectionStart === 0) {
|
|
27
|
-
// at the beginning of the input
|
|
28
|
-
newValue = value.slice(1);
|
|
29
|
-
} else if (selectionStart === value.length) {
|
|
30
|
-
// at the end of the input
|
|
31
|
-
newValue = value;
|
|
32
|
-
} else {
|
|
33
|
-
// in the middle of the input
|
|
34
|
-
newValue = value.slice(0, selectionStart) + value.slice(selectionEnd + 1);
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
// we have something selected
|
|
38
|
-
const firstPart = value.slice(0, selectionStart);
|
|
39
|
-
newValue = firstPart + value.slice(selectionEnd);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
newValue,
|
|
44
|
-
newSelectionStart: selectionStart != null ? selectionStart : 0
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.calculateNewBackspaceValue = calculateNewBackspaceValue;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../../utils");
|
|
9
|
-
|
|
10
|
-
// yes, calculateNewBackspaceValue and calculateNewValue look extremely similar
|
|
11
|
-
// and you may be tempted to create a shared abstraction.
|
|
12
|
-
// If you, brave soul, decide to so endevor, please increment this count
|
|
13
|
-
// when you inevitably fail: 1
|
|
14
|
-
function calculateNewBackspaceValue(element, value = (() => {
|
|
15
|
-
var _getValue;
|
|
16
|
-
|
|
17
|
-
return (_getValue = (0, _utils.getValue)(element)) != null ? _getValue :
|
|
18
|
-
/* istanbul ignore next */
|
|
19
|
-
'';
|
|
20
|
-
})()) {
|
|
21
|
-
const {
|
|
22
|
-
selectionStart,
|
|
23
|
-
selectionEnd
|
|
24
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
25
|
-
let newValue, newSelectionStart;
|
|
26
|
-
|
|
27
|
-
if (selectionStart === null) {
|
|
28
|
-
// at the end of an input type that does not support selection ranges
|
|
29
|
-
// https://github.com/testing-library/user-event/issues/316#issuecomment-639744793
|
|
30
|
-
newValue = value.slice(0, value.length - 1);
|
|
31
|
-
newSelectionStart = newValue.length;
|
|
32
|
-
} else if (selectionStart === selectionEnd) {
|
|
33
|
-
if (selectionStart === 0) {
|
|
34
|
-
// at the beginning of the input
|
|
35
|
-
newValue = value;
|
|
36
|
-
newSelectionStart = selectionStart;
|
|
37
|
-
} else if (selectionStart === value.length) {
|
|
38
|
-
// at the end of the input
|
|
39
|
-
newValue = value.slice(0, value.length - 1);
|
|
40
|
-
newSelectionStart = selectionStart - 1;
|
|
41
|
-
} else {
|
|
42
|
-
// in the middle of the input
|
|
43
|
-
newValue = value.slice(0, selectionStart - 1) + value.slice(selectionEnd);
|
|
44
|
-
newSelectionStart = selectionStart - 1;
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
// we have something selected
|
|
48
|
-
const firstPart = value.slice(0, selectionStart);
|
|
49
|
-
newValue = firstPart + value.slice(selectionEnd);
|
|
50
|
-
newSelectionStart = firstPart.length;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
newValue,
|
|
55
|
-
newSelectionStart
|
|
56
|
-
};
|
|
57
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fireInputEventIfNeeded = fireInputEventIfNeeded;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
var _setSelectionRange = require("./setSelectionRange");
|
|
13
|
-
|
|
14
|
-
function fireInputEventIfNeeded({
|
|
15
|
-
currentElement,
|
|
16
|
-
newValue,
|
|
17
|
-
newSelectionStart,
|
|
18
|
-
eventOverrides
|
|
19
|
-
}) {
|
|
20
|
-
const el = currentElement();
|
|
21
|
-
const prevValue = (0, _utils.getValue)(el);
|
|
22
|
-
|
|
23
|
-
if (el && !isReadonly(el) && !(0, _utils.isClickableInput)(el) && newValue !== prevValue) {
|
|
24
|
-
if ((0, _utils.isContentEditable)(el)) {
|
|
25
|
-
_dom.fireEvent.input(el, {
|
|
26
|
-
target: {
|
|
27
|
-
textContent: newValue
|
|
28
|
-
},
|
|
29
|
-
...eventOverrides
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
_dom.fireEvent.input(el, {
|
|
33
|
-
target: {
|
|
34
|
-
value: newValue
|
|
35
|
-
},
|
|
36
|
-
...eventOverrides
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
(0, _setSelectionRange.setSelectionRange)({
|
|
41
|
-
currentElement,
|
|
42
|
-
newValue,
|
|
43
|
-
newSelectionStart
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
prevValue
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isReadonly(element) {
|
|
53
|
-
if (!(0, _utils.isInstanceOfElement)(element, 'HTMLInputElement') && !(0, _utils.isInstanceOfElement)(element, 'HTMLTextAreaElement')) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return element.readOnly;
|
|
58
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setSelectionRange = setSelectionRange;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
function setSelectionRange({
|
|
11
|
-
currentElement,
|
|
12
|
-
newValue,
|
|
13
|
-
newSelectionStart
|
|
14
|
-
}) {
|
|
15
|
-
// if we *can* change the selection start, then we will if the new value
|
|
16
|
-
// is the same as the current value (so it wasn't programatically changed
|
|
17
|
-
// when the fireEvent.input was triggered).
|
|
18
|
-
// The reason we have to do this at all is because it actually *is*
|
|
19
|
-
// programmatically changed by fireEvent.input, so we have to simulate the
|
|
20
|
-
// browser's default behavior
|
|
21
|
-
const el = currentElement();
|
|
22
|
-
const value = (0, _utils.getValue)(el);
|
|
23
|
-
|
|
24
|
-
if (value === newValue) {
|
|
25
|
-
(0, _utils.setSelectionRangeIfNecessary)(el, newSelectionStart, newSelectionStart);
|
|
26
|
-
} else {
|
|
27
|
-
// If the currentValue is different than the expected newValue and we *can*
|
|
28
|
-
// change the selection range, than we should set it to the length of the
|
|
29
|
-
// currentValue to ensure that the browser behavior is mimicked.
|
|
30
|
-
(0, _utils.setSelectionRangeIfNecessary)(el, value.length, value.length);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getSelectionRange = getSelectionRange;
|
|
7
|
-
|
|
8
|
-
var _isContentEditable = require("./isContentEditable");
|
|
9
|
-
|
|
10
|
-
function getSelectionRange(element) {
|
|
11
|
-
if ((0, _isContentEditable.isContentEditable)(element)) {
|
|
12
|
-
const selection = element.ownerDocument.getSelection();
|
|
13
|
-
|
|
14
|
-
if (selection != null && selection.rangeCount) {
|
|
15
|
-
const range = selection.getRangeAt(0);
|
|
16
|
-
return {
|
|
17
|
-
selectionStart: range.startOffset,
|
|
18
|
-
selectionEnd: range.endOffset
|
|
19
|
-
};
|
|
20
|
-
} else {
|
|
21
|
-
return {
|
|
22
|
-
selectionStart: null,
|
|
23
|
-
selectionEnd: null
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
selectionStart: element.selectionStart,
|
|
30
|
-
selectionEnd: element.selectionEnd
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function setSelectionRangeIfNecessary(element: Element, newSelectionStart: number, newSelectionEnd: number): void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setSelectionRangeIfNecessary = setSelectionRangeIfNecessary;
|
|
7
|
-
|
|
8
|
-
var _isContentEditable = require("./isContentEditable");
|
|
9
|
-
|
|
10
|
-
var _getSelectionRange = require("./getSelectionRange");
|
|
11
|
-
|
|
12
|
-
function setSelectionRangeIfNecessary(element, newSelectionStart, newSelectionEnd) {
|
|
13
|
-
const {
|
|
14
|
-
selectionStart,
|
|
15
|
-
selectionEnd
|
|
16
|
-
} = (0, _getSelectionRange.getSelectionRange)(element);
|
|
17
|
-
|
|
18
|
-
if (!(0, _isContentEditable.isContentEditable)(element) && (!element.setSelectionRange || selectionStart === null)) {
|
|
19
|
-
// cannot set selection
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (selectionStart !== newSelectionStart || selectionEnd !== newSelectionStart) {
|
|
24
|
-
if ((0, _isContentEditable.isContentEditable)(element)) {
|
|
25
|
-
const range = element.ownerDocument.createRange();
|
|
26
|
-
range.selectNodeContents(element); // istanbul ignore else
|
|
27
|
-
|
|
28
|
-
if (element.firstChild) {
|
|
29
|
-
range.setStart(element.firstChild, newSelectionStart);
|
|
30
|
-
range.setEnd(element.firstChild, newSelectionEnd);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
|
|
34
|
-
|
|
35
|
-
if (selection) {
|
|
36
|
-
selection.removeAllRanges();
|
|
37
|
-
selection.addRange(range);
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
;
|
|
41
|
-
element.setSelectionRange(newSelectionStart, newSelectionEnd);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if an element is of a given type.
|
|
3
|
-
*
|
|
4
|
-
* @param {Element} element The element to test
|
|
5
|
-
* @param {string} elementType Constructor name. E.g. 'HTMLSelectElement'
|
|
6
|
-
*/
|
|
7
|
-
export declare function isInstanceOfElement(element: Element, elementType: string): boolean;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isInstanceOfElement = isInstanceOfElement;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@testing-library/dom/dist/helpers");
|
|
9
|
-
|
|
10
|
-
// isInstanceOfElement can be removed once the peerDependency for @testing-library/dom is bumped to a version that includes https://github.com/testing-library/dom-testing-library/pull/885
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Check if an element is of a given type.
|
|
14
|
-
*
|
|
15
|
-
* @param {Element} element The element to test
|
|
16
|
-
* @param {string} elementType Constructor name. E.g. 'HTMLSelectElement'
|
|
17
|
-
*/
|
|
18
|
-
function isInstanceOfElement(element, elementType) {
|
|
19
|
-
try {
|
|
20
|
-
// Window usually has the element constructors as properties but is not required to do so per specs
|
|
21
|
-
const constructor = (0, _helpers.getWindowFromNode)(element)[elementType];
|
|
22
|
-
|
|
23
|
-
if (typeof constructor === 'function') {
|
|
24
|
-
return element instanceof constructor;
|
|
25
|
-
}
|
|
26
|
-
} catch {// The document might not be associated with a window
|
|
27
|
-
} // Fall back to the constructor name as workaround for test environments that
|
|
28
|
-
// a) not associate the document with a window
|
|
29
|
-
// b) not provide the constructor as property of window
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (/^HTML(\w+)Element$/.test(element.constructor.name)) {
|
|
33
|
-
return element.constructor.name === elementType;
|
|
34
|
-
} // The user passed some node that is not created in a browser-like environment
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
throw new Error(`Unable to verify if element is instance of ${elementType}. Please file an issue describing your test environment: https://github.com/testing-library/dom-testing-library/issues/new`);
|
|
38
|
-
}
|