@testing-library/user-event 13.5.0 → 14.0.0-alpha.4
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 +3 -0
- package/dist/clear.d.ts +2 -2
- package/dist/clear.js +1 -3
- package/dist/click.d.ts +3 -3
- package/dist/click.js +13 -144
- package/dist/document/index.d.ts +9 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +17 -0
- package/dist/document/selection.js +64 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +15 -57
- package/dist/index.d.ts +4 -21
- package/dist/index.js +4 -29
- package/dist/keyboard/getNextKeyDef.js +3 -92
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/keyboard/index.js +4 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/plugins/character.js +8 -18
- package/dist/keyboard/plugins/control.js +3 -6
- package/dist/keyboard/plugins/functional.js +20 -6
- package/dist/keyboard/plugins/index.js +2 -4
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +3 -0
- package/dist/paste.d.ts +3 -2
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +125 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +328 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +74 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +18 -20
- package/dist/setup.d.ts +89 -0
- package/dist/setup.js +206 -0
- package/dist/tab.d.ts +3 -3
- package/dist/tab.js +18 -97
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -3
- package/dist/upload.js +3 -9
- package/dist/{keyboard/shared → utils/edit}/fireInputEvent.d.ts +0 -9
- package/dist/utils/edit/fireInputEvent.js +59 -0
- package/dist/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- package/dist/utils/edit/selectionRange.d.ts +0 -11
- package/dist/utils/edit/selectionRange.js +9 -49
- package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +19 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +72 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- package/dist/utils/index.d.ts +10 -3
- package/dist/utils/index.js +120 -29
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/fakeEvent.d.ts +20 -0
- package/dist/utils/pointer/fakeEvent.js +91 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +14 -0
- package/dist/utils/pointer/firePointerEvents.js +55 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.readNextDescriptor = readNextDescriptor;
|
|
7
|
+
var bracketDict;
|
|
8
|
+
/**
|
|
9
|
+
* Read the next key definition from user input
|
|
10
|
+
*
|
|
11
|
+
* Describe key per `{descriptor}` or `[descriptor]`.
|
|
12
|
+
* Everything else will be interpreted as a single character as descriptor - e.g. `a`.
|
|
13
|
+
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
14
|
+
* A previously pressed key can be released per `{/descriptor}`.
|
|
15
|
+
* Keeping the key pressed can be written as `{descriptor>}`.
|
|
16
|
+
* When keeping the key pressed you can choose how long the key is pressed `{descriptor>3}`.
|
|
17
|
+
* You can then release the key per `{descriptor>3/}` or keep it pressed and continue with the next key.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
(function (bracketDict) {
|
|
21
|
+
bracketDict["{"] = "}";
|
|
22
|
+
bracketDict["["] = "]";
|
|
23
|
+
})(bracketDict || (bracketDict = {}));
|
|
24
|
+
|
|
25
|
+
function readNextDescriptor(text) {
|
|
26
|
+
let pos = 0;
|
|
27
|
+
const startBracket = text[pos] in bracketDict ? text[pos] : '';
|
|
28
|
+
pos += startBracket.length; // `foo{{bar` is an escaped char at position 3,
|
|
29
|
+
// but `foo{{{>5}bar` should be treated as `{` pressed down for 5 keydowns.
|
|
30
|
+
|
|
31
|
+
const startBracketRepeated = startBracket ? text.match(new RegExp(`^\\${startBracket}+`))[0].length : 0;
|
|
32
|
+
const isEscapedChar = startBracketRepeated === 2 || startBracket === '{' && startBracketRepeated > 3;
|
|
33
|
+
const type = isEscapedChar ? '' : startBracket;
|
|
34
|
+
return {
|
|
35
|
+
type,
|
|
36
|
+
...(type === '' ? readPrintableChar(text, pos) : readTag(text, pos, type))
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readPrintableChar(text, pos) {
|
|
41
|
+
const descriptor = text[pos];
|
|
42
|
+
assertDescriptor(descriptor, text, pos);
|
|
43
|
+
pos += descriptor.length;
|
|
44
|
+
return {
|
|
45
|
+
consumedLength: pos,
|
|
46
|
+
descriptor,
|
|
47
|
+
releasePrevious: false,
|
|
48
|
+
releaseSelf: true,
|
|
49
|
+
repeat: 1
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function readTag(text, pos, startBracket) {
|
|
54
|
+
var _text$slice$match, _text$slice$match$, _text$slice$match2;
|
|
55
|
+
|
|
56
|
+
const releasePreviousModifier = text[pos] === '/' ? '/' : '';
|
|
57
|
+
pos += releasePreviousModifier.length;
|
|
58
|
+
const descriptor = (_text$slice$match = text.slice(pos).match(/^\w+/)) == null ? void 0 : _text$slice$match[0];
|
|
59
|
+
assertDescriptor(descriptor, text, pos);
|
|
60
|
+
pos += descriptor.length;
|
|
61
|
+
const repeatModifier = (_text$slice$match$ = (_text$slice$match2 = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _text$slice$match2[0]) != null ? _text$slice$match$ : '';
|
|
62
|
+
pos += repeatModifier.length;
|
|
63
|
+
const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
|
|
64
|
+
pos += releaseSelfModifier.length;
|
|
65
|
+
const expectedEndBracket = bracketDict[startBracket];
|
|
66
|
+
const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : '';
|
|
67
|
+
|
|
68
|
+
if (!endBracket) {
|
|
69
|
+
throw new Error(getErrorMessage([!repeatModifier && 'repeat modifier', !releaseSelfModifier && 'release modifier', `"${expectedEndBracket}"`].filter(Boolean).join(' or '), text[pos], text));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
pos += endBracket.length;
|
|
73
|
+
return {
|
|
74
|
+
consumedLength: pos,
|
|
75
|
+
descriptor,
|
|
76
|
+
releasePrevious: !!releasePreviousModifier,
|
|
77
|
+
repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
|
|
78
|
+
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function assertDescriptor(descriptor, text, pos) {
|
|
83
|
+
if (!descriptor) {
|
|
84
|
+
throw new Error(getErrorMessage('key descriptor', text[pos], text));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
89
|
+
if (releaseSelfModifier) {
|
|
90
|
+
return releaseSelfModifier === '/';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (repeatModifier) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getErrorMessage(expected, found, text) {
|
|
99
|
+
return `Expected ${expected} but found "${found != null ? found : ''}" in "${text}"
|
|
100
|
+
See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
|
|
101
|
+
for more information about how userEvent parses your input.`;
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findClosest(element: Element, callback: (e: Element) => boolean): Element | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findClosest = findClosest;
|
|
7
|
+
|
|
8
|
+
function findClosest(element, callback) {
|
|
9
|
+
let el = element;
|
|
10
|
+
|
|
11
|
+
do {
|
|
12
|
+
if (callback(el)) {
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
el = el.parentElement;
|
|
17
|
+
} while (el && el !== element.ownerDocument.body);
|
|
18
|
+
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDescendantOrSelf(potentialDescendant: Element, potentialAncestor: Element): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isDescendantOrSelf = isDescendantOrSelf;
|
|
7
|
+
|
|
8
|
+
function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
9
|
+
let el = potentialDescendant;
|
|
10
|
+
|
|
11
|
+
do {
|
|
12
|
+
if (el === potentialAncestor) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
el = el.parentElement;
|
|
17
|
+
} while (el);
|
|
18
|
+
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PointerCoords {
|
|
2
|
+
x?: number;
|
|
3
|
+
y?: number;
|
|
4
|
+
clientX?: number;
|
|
5
|
+
clientY?: number;
|
|
6
|
+
offsetX?: number;
|
|
7
|
+
offsetY?: number;
|
|
8
|
+
pageX?: number;
|
|
9
|
+
pageY?: number;
|
|
10
|
+
screenX?: number;
|
|
11
|
+
screenY?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface FakePointerEventInit extends MouseEventInit, PointerEventInit, PointerCoords {
|
|
14
|
+
}
|
|
15
|
+
export declare class FakeMouseEvent extends MouseEvent {
|
|
16
|
+
constructor(type: string, init: FakePointerEventInit);
|
|
17
|
+
}
|
|
18
|
+
export declare class FakePointerEvent extends MouseEvent {
|
|
19
|
+
constructor(type: string, init: FakePointerEventInit);
|
|
20
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FakePointerEvent = exports.FakeMouseEvent = void 0;
|
|
7
|
+
|
|
8
|
+
// See : https://github.com/testing-library/react-testing-library/issues/268
|
|
9
|
+
function assignProps(obj, props) {
|
|
10
|
+
for (const [key, value] of Object.entries(props)) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
get: () => value
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function assignPositionInit(obj, {
|
|
18
|
+
x,
|
|
19
|
+
y,
|
|
20
|
+
clientX,
|
|
21
|
+
clientY,
|
|
22
|
+
offsetX,
|
|
23
|
+
offsetY,
|
|
24
|
+
pageX,
|
|
25
|
+
pageY,
|
|
26
|
+
screenX,
|
|
27
|
+
screenY
|
|
28
|
+
}) {
|
|
29
|
+
var _ref, _ref2, _ref3, _ref4;
|
|
30
|
+
|
|
31
|
+
assignProps(obj, {
|
|
32
|
+
/* istanbul ignore start */
|
|
33
|
+
x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
|
|
34
|
+
y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
|
|
35
|
+
clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
|
|
36
|
+
clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
|
|
37
|
+
offsetX: offsetX != null ? offsetX : 0,
|
|
38
|
+
offsetY: offsetY != null ? offsetY : 0,
|
|
39
|
+
pageX: pageX != null ? pageX : 0,
|
|
40
|
+
pageY: pageY != null ? pageY : 0,
|
|
41
|
+
screenX: screenX != null ? screenX : 0,
|
|
42
|
+
screenY: screenY != null ? screenY : 0
|
|
43
|
+
/* istanbul ignore end */
|
|
44
|
+
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function assignPointerInit(obj, {
|
|
49
|
+
isPrimary,
|
|
50
|
+
pointerId,
|
|
51
|
+
pointerType
|
|
52
|
+
}) {
|
|
53
|
+
assignProps(obj, {
|
|
54
|
+
isPrimary,
|
|
55
|
+
pointerId,
|
|
56
|
+
pointerType
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const notBubbling = ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'];
|
|
61
|
+
|
|
62
|
+
function getInitDefaults(type, init) {
|
|
63
|
+
return {
|
|
64
|
+
bubbles: !notBubbling.includes(type),
|
|
65
|
+
cancelable: true,
|
|
66
|
+
composed: true,
|
|
67
|
+
...init
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class FakeMouseEvent extends MouseEvent {
|
|
72
|
+
constructor(type, init) {
|
|
73
|
+
super(type, getInitDefaults(type, init));
|
|
74
|
+
assignPositionInit(this, init);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} // Should extend PointerEvent, but... https://github.com/jsdom/jsdom/issues/2527
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
exports.FakeMouseEvent = FakeMouseEvent;
|
|
81
|
+
|
|
82
|
+
class FakePointerEvent extends MouseEvent {
|
|
83
|
+
constructor(type, init) {
|
|
84
|
+
super(type, getInitDefaults(type, init));
|
|
85
|
+
assignPositionInit(this, init);
|
|
86
|
+
assignPointerInit(this, init);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
exports.FakePointerEvent = FakePointerEvent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { pointerState } from '../../pointer/types';
|
|
2
|
+
import type { keyboardState } from '../../keyboard/types';
|
|
3
|
+
import { PointerCoords } from './fakeEvent';
|
|
4
|
+
import { MouseButton } from './mouseButtons';
|
|
5
|
+
export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
|
|
6
|
+
pointerState: pointerState;
|
|
7
|
+
keyboardState: keyboardState;
|
|
8
|
+
pointerType?: 'mouse' | 'pen' | 'touch';
|
|
9
|
+
button?: MouseButton;
|
|
10
|
+
coords?: PointerCoords;
|
|
11
|
+
pointerId?: number;
|
|
12
|
+
isPrimary?: boolean;
|
|
13
|
+
clickCount?: number;
|
|
14
|
+
}): boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.firePointerEvent = firePointerEvent;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _fakeEvent = require("./fakeEvent");
|
|
11
|
+
|
|
12
|
+
var _mouseButtons = require("./mouseButtons");
|
|
13
|
+
|
|
14
|
+
function firePointerEvent(target, type, {
|
|
15
|
+
pointerState,
|
|
16
|
+
keyboardState,
|
|
17
|
+
pointerType,
|
|
18
|
+
button,
|
|
19
|
+
coords,
|
|
20
|
+
pointerId,
|
|
21
|
+
isPrimary,
|
|
22
|
+
clickCount
|
|
23
|
+
}) {
|
|
24
|
+
const Event = type === 'click' || type.startsWith('mouse') ? _fakeEvent.FakeMouseEvent : _fakeEvent.FakePointerEvent;
|
|
25
|
+
const init = { ...coords,
|
|
26
|
+
altKey: keyboardState.modifiers.alt,
|
|
27
|
+
ctrlKey: keyboardState.modifiers.ctrl,
|
|
28
|
+
metaKey: keyboardState.modifiers.meta,
|
|
29
|
+
shiftKey: keyboardState.modifiers.shift
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (Event === _fakeEvent.FakePointerEvent || type === 'click') {
|
|
33
|
+
init.pointerId = pointerId;
|
|
34
|
+
init.pointerType = pointerType;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (['pointerdown', 'pointerup'].includes(type)) {
|
|
38
|
+
init.isPrimary = isPrimary;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].includes(type)) {
|
|
42
|
+
init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
|
|
43
|
+
init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
|
|
44
|
+
var _p$keyDef$button;
|
|
45
|
+
|
|
46
|
+
return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (['mousedown', 'mouseup', 'click'].includes(type)) {
|
|
51
|
+
init.detail = clickCount;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (0, _dom.fireEvent)(target, new Event(type, init));
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MouseButton: {
|
|
2
|
+
readonly primary: 0;
|
|
3
|
+
readonly secondary: 1;
|
|
4
|
+
readonly auxiliary: 2;
|
|
5
|
+
readonly back: 3;
|
|
6
|
+
readonly X1: 3;
|
|
7
|
+
readonly forward: 4;
|
|
8
|
+
readonly X2: 4;
|
|
9
|
+
};
|
|
10
|
+
export declare type MouseButton = keyof typeof MouseButton | number;
|
|
11
|
+
export declare function getMouseButton(button: MouseButton): number;
|
|
12
|
+
export declare function getMouseButtons(...buttons: Array<MouseButton>): number;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MouseButton = void 0;
|
|
7
|
+
exports.getMouseButton = getMouseButton;
|
|
8
|
+
exports.getMouseButtons = getMouseButtons;
|
|
9
|
+
const MouseButton = {
|
|
10
|
+
primary: 0,
|
|
11
|
+
secondary: 1,
|
|
12
|
+
auxiliary: 2,
|
|
13
|
+
back: 3,
|
|
14
|
+
X1: 3,
|
|
15
|
+
forward: 4,
|
|
16
|
+
X2: 4
|
|
17
|
+
};
|
|
18
|
+
exports.MouseButton = MouseButton;
|
|
19
|
+
// Some legacy...
|
|
20
|
+
const MouseButtonFlip = {
|
|
21
|
+
auxiliary: 1,
|
|
22
|
+
secondary: 2,
|
|
23
|
+
1: 2,
|
|
24
|
+
2: 1
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getMouseButton(button) {
|
|
28
|
+
if (button in MouseButtonFlip) {
|
|
29
|
+
return MouseButtonFlip[button];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return typeof button === 'number' ? button : MouseButton[button];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getMouseButtons(...buttons) {
|
|
36
|
+
let v = 0;
|
|
37
|
+
|
|
38
|
+
for (const t of buttons) {
|
|
39
|
+
const pos = typeof t === 'number' ? t : MouseButton[t]; // eslint-disable-next-line no-bitwise
|
|
40
|
+
|
|
41
|
+
v |= 2 ** pos;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return v;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/user-event",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0-alpha.4",
|
|
4
4
|
"description": "Fire events the same way the user does",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "Giorgio Polvara <polvara@gmail.com>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=12",
|
|
16
16
|
"npm": ">=6"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "kcd-scripts build",
|
|
30
|
+
"build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
|
|
31
31
|
"lint": "kcd-scripts lint",
|
|
32
32
|
"setup": "npm install && npm run validate -s",
|
|
33
33
|
"test": "kcd-scripts test",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@types/estree": "0.0.45",
|
|
47
47
|
"@types/jest-in-case": "^1.0.3",
|
|
48
48
|
"@types/react": "^17.0.3",
|
|
49
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
49
50
|
"is-ci": "^2.0.0",
|
|
50
51
|
"jest-in-case": "^1.0.2",
|
|
51
52
|
"jest-serializer-ansi": "^1.0.3",
|
package/dist/blur.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blur = blur;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function blur(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const wasActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (!wasActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.blur());
|
|
15
|
-
}
|
package/dist/dom-helpers.d.ts
DELETED
package/dist/focus.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.focus = focus;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function focus(element) {
|
|
11
|
-
if (!(0, _utils.isFocusable)(element)) return;
|
|
12
|
-
const isAlreadyActive = (0, _utils.getActiveElement)(element.ownerDocument) === element;
|
|
13
|
-
if (isAlreadyActive) return;
|
|
14
|
-
(0, _utils.eventWrapper)(() => element.focus());
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.carryValue = carryValue;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
function carryValue(element, state, newValue) {
|
|
11
|
-
const value = (0, _utils.getValue)(element);
|
|
12
|
-
state.carryValue = value !== newValue && value === '' && (0, _utils.hasUnreliableEmptyValue)(element) ? newValue : undefined;
|
|
13
|
-
}
|
|
@@ -1,110 +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 _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
function fireInputEvent(element, {
|
|
13
|
-
newValue,
|
|
14
|
-
newSelectionStart,
|
|
15
|
-
eventOverrides
|
|
16
|
-
}) {
|
|
17
|
-
// apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
18
|
-
if ((0, _utils.isContentEditable)(element)) {
|
|
19
|
-
applyNative(element, 'textContent', newValue);
|
|
20
|
-
} else
|
|
21
|
-
/* istanbul ignore else */
|
|
22
|
-
if ((0, _utils.isElementType)(element, ['input', 'textarea'])) {
|
|
23
|
-
applyNative(element, 'value', newValue);
|
|
24
|
-
} else {
|
|
25
|
-
// TODO: properly type guard
|
|
26
|
-
throw new Error('Invalid Element');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setSelectionRangeAfterInput(element, newSelectionStart);
|
|
30
|
-
|
|
31
|
-
_dom.fireEvent.input(element, { ...eventOverrides
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function setSelectionRangeAfterInput(element, newSelectionStart) {
|
|
38
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function setSelectionRangeAfterInputHandler(element, newValue, newSelectionStart) {
|
|
42
|
-
const value = (0, _utils.getValue)(element); // don't apply this workaround on elements that don't necessarily report the visible value - e.g. number
|
|
43
|
-
// TODO: this could probably be only applied when there is keyboardState.carryValue
|
|
44
|
-
|
|
45
|
-
const isUnreliableValue = value === '' && (0, _utils.hasUnreliableEmptyValue)(element);
|
|
46
|
-
|
|
47
|
-
if (!isUnreliableValue && value === newValue) {
|
|
48
|
-
const {
|
|
49
|
-
selectionStart
|
|
50
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
51
|
-
|
|
52
|
-
if (selectionStart === value.length) {
|
|
53
|
-
// The value was changed as expected, but the cursor was moved to the end
|
|
54
|
-
// TODO: this could probably be only applied when we work around a framework setter on the element in applyNative
|
|
55
|
-
(0, _utils.setSelectionRange)(element, newSelectionStart, newSelectionStart);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const initial = Symbol('initial input value/textContent');
|
|
61
|
-
const onBlur = Symbol('onBlur');
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* React tracks the changes on element properties.
|
|
65
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
66
|
-
* so that it later picks up the change.
|
|
67
|
-
*
|
|
68
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
69
|
-
*/
|
|
70
|
-
function applyNative(element, propName, propValue) {
|
|
71
|
-
const descriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
72
|
-
const nativeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
73
|
-
|
|
74
|
-
if (descriptor && nativeDescriptor) {
|
|
75
|
-
Object.defineProperty(element, propName, nativeDescriptor);
|
|
76
|
-
} // Keep track of the initial value to determine if a change event should be dispatched.
|
|
77
|
-
// CONSTRAINT: We can not determine what happened between focus event and our first API call.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (element[initial] === undefined) {
|
|
81
|
-
element[initial] = String(element[propName]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
element[propName] = propValue; // Add an event listener for the blur event to the capture phase on the window.
|
|
85
|
-
// CONSTRAINT: Currently there is no cross-platform solution to unshift the event handler stack.
|
|
86
|
-
// Our change event might occur after other event handlers on the blur event have been processed.
|
|
87
|
-
|
|
88
|
-
if (!element[onBlur]) {
|
|
89
|
-
var _element$ownerDocumen;
|
|
90
|
-
|
|
91
|
-
(_element$ownerDocumen = element.ownerDocument.defaultView) == null ? void 0 : _element$ownerDocumen.addEventListener('blur', element[onBlur] = () => {
|
|
92
|
-
const initV = element[initial]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
93
|
-
|
|
94
|
-
delete element[onBlur]; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
95
|
-
|
|
96
|
-
delete element[initial];
|
|
97
|
-
|
|
98
|
-
if (String(element[propName]) !== initV) {
|
|
99
|
-
_dom.fireEvent.change(element);
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
capture: true,
|
|
103
|
-
once: true
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (descriptor) {
|
|
108
|
-
Object.defineProperty(element, propName, descriptor);
|
|
109
|
-
}
|
|
110
|
-
}
|
package/dist/select-options.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PointerOptions } from './utils';
|
|
2
|
-
declare const selectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
3
|
-
declare const deselectOptions: (args_0: Element, args_1: string | string[] | HTMLElement | HTMLElement[], args_2?: MouseEventInit | undefined, args_3?: PointerOptions | undefined) => void;
|
|
4
|
-
export { selectOptions, deselectOptions };
|
package/dist/type/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { typeOptions } from './typeImplementation';
|
|
2
|
-
export declare function type(element: Element, text: string, options?: typeOptions & {
|
|
3
|
-
delay?: 0;
|
|
4
|
-
}): void;
|
|
5
|
-
export declare function type(element: Element, text: string, options: typeOptions & {
|
|
6
|
-
delay: number;
|
|
7
|
-
}): Promise<void>;
|
package/dist/type/index.js
DELETED
|
@@ -1,33 +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 _typeImplementation = require("./typeImplementation");
|
|
11
|
-
|
|
12
|
-
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
|
|
13
|
-
// depending on whether it will be async.
|
|
14
|
-
function type(element, text, {
|
|
15
|
-
delay = 0,
|
|
16
|
-
...options
|
|
17
|
-
} = {}) {
|
|
18
|
-
// we do not want to wrap in the asyncWrapper if we're not
|
|
19
|
-
// going to actually be doing anything async, so we only wrap
|
|
20
|
-
// if the delay is greater than 0
|
|
21
|
-
if (delay > 0) {
|
|
22
|
-
return (0, _dom.getConfig)().asyncWrapper(() => (0, _typeImplementation.typeImplementation)(element, text, {
|
|
23
|
-
delay,
|
|
24
|
-
...options
|
|
25
|
-
}));
|
|
26
|
-
} else {
|
|
27
|
-
return void (0, _typeImplementation.typeImplementation)(element, text, {
|
|
28
|
-
delay,
|
|
29
|
-
...options
|
|
30
|
-
}) // prevents users from dealing with UnhandledPromiseRejectionWarning
|
|
31
|
-
.catch(console.error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface typeOptions {
|
|
2
|
-
delay?: number;
|
|
3
|
-
skipClick?: boolean;
|
|
4
|
-
skipAutoClose?: boolean;
|
|
5
|
-
initialSelectionStart?: number;
|
|
6
|
-
initialSelectionEnd?: number;
|
|
7
|
-
}
|
|
8
|
-
export declare function typeImplementation(element: Element, text: string, { delay, skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }: typeOptions & {
|
|
9
|
-
delay: number;
|
|
10
|
-
}): Promise<void>;
|