@testing-library/user-event 13.5.0 → 14.0.0-alpha.12
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 +14 -29
- package/dist/click.d.ts +4 -3
- package/dist/click.js +30 -145
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +90 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +17 -59
- package/dist/index.d.ts +3 -22
- package/dist/index.js +3 -36
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/keyboard/getNextKeyDef.js +4 -123
- package/dist/keyboard/index.d.ts +1 -1
- package/dist/keyboard/index.js +4 -8
- package/dist/keyboard/keyMap.js +26 -46
- package/dist/keyboard/keyboardImplementation.js +15 -17
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +29 -57
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/keyboard/plugins/control.js +5 -16
- package/dist/keyboard/plugins/functional.js +23 -14
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +4 -13
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +3 -2
- package/dist/paste.d.ts +3 -2
- package/dist/paste.js +8 -15
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +136 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +330 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +35 -38
- package/dist/setup.d.ts +92 -0
- package/dist/setup.js +203 -0
- package/dist/tab.d.ts +3 -4
- package/dist/tab.js +3 -136
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -4
- package/dist/upload.js +3 -9
- package/dist/utils/edit/calculateNewValue.d.ts +12 -5
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/editInputElement.js +53 -0
- package/dist/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- package/dist/utils/edit/isContentEditable.d.ts +4 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/utils/edit/isEditable.d.ts +1 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +22 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +12 -6
- package/dist/utils/index.js +132 -54
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +25 -0
- package/dist/utils/pointer/firePointerEvents.js +112 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.d.ts +0 -17
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/edit/selectionRange.d.ts +0 -16
- package/dist/utils/edit/selectionRange.js +0 -104
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
|
@@ -3,21 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.deselectOptions = deselectOptions;
|
|
7
|
+
exports.selectOptions = selectOptions;
|
|
7
8
|
|
|
8
9
|
var _dom = require("@testing-library/dom");
|
|
9
10
|
|
|
10
11
|
var _utils = require("./utils");
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function selectOptions(select, values, options = {}) {
|
|
14
|
+
return selectOptionsBase.call(this, true, select, values, options);
|
|
15
|
+
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
function deselectOptions(select, values, options = {}) {
|
|
18
|
+
return selectOptionsBase.call(this, false, select, values, options);
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
function selectOptionsBase(newValue, select, values,
|
|
19
|
-
skipPointerEventsCheck
|
|
20
|
-
}
|
|
21
|
+
function selectOptionsBase(newValue, select, values, {
|
|
22
|
+
skipPointerEventsCheck
|
|
23
|
+
}) {
|
|
21
24
|
if (!newValue && !select.multiple) {
|
|
22
25
|
throw (0, _dom.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
23
26
|
}
|
|
@@ -45,46 +48,46 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
45
48
|
const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(option); // events fired for multiple select are weird. Can't use hover...
|
|
46
49
|
|
|
47
50
|
if (withPointerEvents) {
|
|
48
|
-
_dom.fireEvent.pointerOver(option
|
|
51
|
+
_dom.fireEvent.pointerOver(option);
|
|
49
52
|
|
|
50
|
-
_dom.fireEvent.pointerEnter(select
|
|
53
|
+
_dom.fireEvent.pointerEnter(select);
|
|
51
54
|
|
|
52
55
|
_dom.fireEvent.mouseOver(option);
|
|
53
56
|
|
|
54
57
|
_dom.fireEvent.mouseEnter(select);
|
|
55
58
|
|
|
56
|
-
_dom.fireEvent.pointerMove(option
|
|
59
|
+
_dom.fireEvent.pointerMove(option);
|
|
57
60
|
|
|
58
|
-
_dom.fireEvent.mouseMove(option
|
|
61
|
+
_dom.fireEvent.mouseMove(option);
|
|
59
62
|
|
|
60
|
-
_dom.fireEvent.pointerDown(option
|
|
63
|
+
_dom.fireEvent.pointerDown(option);
|
|
61
64
|
|
|
62
|
-
_dom.fireEvent.mouseDown(option
|
|
65
|
+
_dom.fireEvent.mouseDown(option);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
(0,
|
|
68
|
+
(0, _utils.focus)(select);
|
|
66
69
|
|
|
67
70
|
if (withPointerEvents) {
|
|
68
|
-
_dom.fireEvent.pointerUp(option
|
|
71
|
+
_dom.fireEvent.pointerUp(option);
|
|
69
72
|
|
|
70
|
-
_dom.fireEvent.mouseUp(option
|
|
73
|
+
_dom.fireEvent.mouseUp(option);
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
selectOption(option);
|
|
74
77
|
|
|
75
78
|
if (withPointerEvents) {
|
|
76
|
-
_dom.fireEvent.click(option
|
|
79
|
+
_dom.fireEvent.click(option);
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
} else if (selectedOptions.length === 1) {
|
|
80
83
|
const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(select); // the click to open the select options
|
|
81
84
|
|
|
82
85
|
if (withPointerEvents) {
|
|
83
|
-
|
|
84
|
-
skipPointerEventsCheck
|
|
86
|
+
this.click(select, {
|
|
87
|
+
skipPointerEventsCheck: true
|
|
85
88
|
});
|
|
86
89
|
} else {
|
|
87
|
-
(0,
|
|
90
|
+
(0, _utils.focus)(select);
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
selectOption(selectedOptions[0]);
|
|
@@ -92,32 +95,32 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
92
95
|
if (withPointerEvents) {
|
|
93
96
|
// the browser triggers another click event on the select for the click on the option
|
|
94
97
|
// this second click has no 'down' phase
|
|
95
|
-
_dom.fireEvent.pointerOver(select
|
|
98
|
+
_dom.fireEvent.pointerOver(select);
|
|
96
99
|
|
|
97
|
-
_dom.fireEvent.pointerEnter(select
|
|
100
|
+
_dom.fireEvent.pointerEnter(select);
|
|
98
101
|
|
|
99
102
|
_dom.fireEvent.mouseOver(select);
|
|
100
103
|
|
|
101
104
|
_dom.fireEvent.mouseEnter(select);
|
|
102
105
|
|
|
103
|
-
_dom.fireEvent.pointerUp(select
|
|
106
|
+
_dom.fireEvent.pointerUp(select);
|
|
104
107
|
|
|
105
|
-
_dom.fireEvent.mouseUp(select
|
|
108
|
+
_dom.fireEvent.mouseUp(select);
|
|
106
109
|
|
|
107
|
-
_dom.fireEvent.click(select
|
|
110
|
+
_dom.fireEvent.click(select);
|
|
108
111
|
}
|
|
109
112
|
} else {
|
|
110
113
|
throw (0, _dom.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
111
114
|
}
|
|
112
115
|
} else if (select.getAttribute('role') === 'listbox') {
|
|
113
116
|
selectedOptions.forEach(option => {
|
|
114
|
-
|
|
117
|
+
this.hover(option, {
|
|
115
118
|
skipPointerEventsCheck
|
|
116
119
|
});
|
|
117
|
-
|
|
120
|
+
this.click(option, {
|
|
118
121
|
skipPointerEventsCheck
|
|
119
122
|
});
|
|
120
|
-
|
|
123
|
+
this.unhover(option, {
|
|
121
124
|
skipPointerEventsCheck
|
|
122
125
|
});
|
|
123
126
|
});
|
|
@@ -130,15 +133,9 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
130
133
|
(0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
|
|
131
134
|
bubbles: true,
|
|
132
135
|
cancelable: false,
|
|
133
|
-
composed: true
|
|
134
|
-
...init
|
|
136
|
+
composed: true
|
|
135
137
|
}));
|
|
136
138
|
|
|
137
|
-
_dom.fireEvent.change(select
|
|
139
|
+
_dom.fireEvent.change(select);
|
|
138
140
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const selectOptions = selectOptionsBase.bind(null, true);
|
|
142
|
-
exports.selectOptions = selectOptions;
|
|
143
|
-
const deselectOptions = selectOptionsBase.bind(null, false);
|
|
144
|
-
exports.deselectOptions = deselectOptions;
|
|
141
|
+
}
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { clear } from './clear';
|
|
2
|
+
import { click, clickOptions, dblClick, tripleClick } from './click';
|
|
3
|
+
import { hover, unhover } from './hover';
|
|
4
|
+
import { keyboard, keyboardOptions } from './keyboard';
|
|
5
|
+
import type { keyboardState } from './keyboard/types';
|
|
6
|
+
import { paste } from './paste';
|
|
7
|
+
import { pointer } from './pointer';
|
|
8
|
+
import type { pointerOptions, pointerState } from './pointer/types';
|
|
9
|
+
import { deselectOptions, selectOptions } from './selectOptions';
|
|
10
|
+
import { tab, tabOptions } from './tab';
|
|
11
|
+
import { type, typeOptions } from './type';
|
|
12
|
+
import { upload, uploadOptions } from './upload';
|
|
13
|
+
import { PointerOptions } from './utils';
|
|
14
|
+
export declare const userEventApis: {
|
|
15
|
+
clear: typeof clear;
|
|
16
|
+
click: typeof click;
|
|
17
|
+
dblClick: typeof dblClick;
|
|
18
|
+
deselectOptions: typeof deselectOptions;
|
|
19
|
+
hover: typeof hover;
|
|
20
|
+
keyboard: typeof keyboard;
|
|
21
|
+
paste: typeof paste;
|
|
22
|
+
pointer: typeof pointer;
|
|
23
|
+
selectOptions: typeof selectOptions;
|
|
24
|
+
tab: typeof tab;
|
|
25
|
+
tripleClick: typeof tripleClick;
|
|
26
|
+
type: typeof type;
|
|
27
|
+
unhover: typeof unhover;
|
|
28
|
+
upload: typeof upload;
|
|
29
|
+
};
|
|
30
|
+
export declare type UserEventApis = typeof userEventApis;
|
|
31
|
+
declare type setup = ReturnType<typeof _setup>['setup'];
|
|
32
|
+
export declare type UserEvent = UserEventApis & {
|
|
33
|
+
setup: setup;
|
|
34
|
+
};
|
|
35
|
+
declare type ClickOptions = Omit<clickOptions, 'clickCount'>;
|
|
36
|
+
declare type KeyboardOptions = Partial<keyboardOptions>;
|
|
37
|
+
declare type PointerApiOptions = Partial<pointerOptions>;
|
|
38
|
+
declare type TabOptions = Omit<tabOptions, 'shift'>;
|
|
39
|
+
declare type TypeOptions = Omit<typeOptions, 'initialSelectionStart' | 'initialSelectionEnd'>;
|
|
40
|
+
declare type UploadOptions = uploadOptions;
|
|
41
|
+
interface SetupOptions extends ClickOptions, KeyboardOptions, PointerOptions, PointerApiOptions, TabOptions, TypeOptions, UploadOptions {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Start a "session" with userEvent.
|
|
45
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
46
|
+
*/
|
|
47
|
+
export declare function setup(options?: SetupOptions): {
|
|
48
|
+
clear: typeof clear;
|
|
49
|
+
click: typeof click;
|
|
50
|
+
dblClick: typeof dblClick;
|
|
51
|
+
deselectOptions: typeof deselectOptions;
|
|
52
|
+
hover: typeof hover;
|
|
53
|
+
keyboard: typeof keyboard;
|
|
54
|
+
paste: typeof paste;
|
|
55
|
+
pointer: typeof pointer;
|
|
56
|
+
selectOptions: typeof selectOptions;
|
|
57
|
+
tab: typeof tab;
|
|
58
|
+
tripleClick: typeof tripleClick;
|
|
59
|
+
type: typeof type;
|
|
60
|
+
unhover: typeof unhover;
|
|
61
|
+
upload: typeof upload;
|
|
62
|
+
} & {
|
|
63
|
+
/**
|
|
64
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
65
|
+
*/
|
|
66
|
+
setup(options: SetupOptions): {
|
|
67
|
+
clear: typeof clear;
|
|
68
|
+
click: typeof click;
|
|
69
|
+
dblClick: typeof dblClick;
|
|
70
|
+
deselectOptions: typeof deselectOptions;
|
|
71
|
+
hover: typeof hover;
|
|
72
|
+
keyboard: typeof keyboard;
|
|
73
|
+
paste: typeof paste;
|
|
74
|
+
pointer: typeof pointer;
|
|
75
|
+
selectOptions: typeof selectOptions;
|
|
76
|
+
tab: typeof tab;
|
|
77
|
+
tripleClick: typeof tripleClick;
|
|
78
|
+
type: typeof type;
|
|
79
|
+
unhover: typeof unhover;
|
|
80
|
+
upload: typeof upload;
|
|
81
|
+
} & any;
|
|
82
|
+
};
|
|
83
|
+
declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
|
|
84
|
+
keyboardState: keyboardState;
|
|
85
|
+
pointerState: pointerState;
|
|
86
|
+
}): UserEventApis & {
|
|
87
|
+
/**
|
|
88
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
89
|
+
*/
|
|
90
|
+
setup(options: SetupOptions): ReturnType<typeof _setup>;
|
|
91
|
+
};
|
|
92
|
+
export {};
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setup = setup;
|
|
7
|
+
exports.userEventApis = void 0;
|
|
8
|
+
|
|
9
|
+
var _clear = require("./clear");
|
|
10
|
+
|
|
11
|
+
var _click = require("./click");
|
|
12
|
+
|
|
13
|
+
var _document = require("./document");
|
|
14
|
+
|
|
15
|
+
var _hover = require("./hover");
|
|
16
|
+
|
|
17
|
+
var _keyboard = require("./keyboard");
|
|
18
|
+
|
|
19
|
+
var _paste = require("./paste");
|
|
20
|
+
|
|
21
|
+
var _pointer = require("./pointer");
|
|
22
|
+
|
|
23
|
+
var _selectOptions = require("./selectOptions");
|
|
24
|
+
|
|
25
|
+
var _tab = require("./tab");
|
|
26
|
+
|
|
27
|
+
var _type = require("./type");
|
|
28
|
+
|
|
29
|
+
var _upload = require("./upload");
|
|
30
|
+
|
|
31
|
+
const userEventApis = {
|
|
32
|
+
clear: _clear.clear,
|
|
33
|
+
click: _click.click,
|
|
34
|
+
dblClick: _click.dblClick,
|
|
35
|
+
deselectOptions: _selectOptions.deselectOptions,
|
|
36
|
+
hover: _hover.hover,
|
|
37
|
+
keyboard: _keyboard.keyboard,
|
|
38
|
+
paste: _paste.paste,
|
|
39
|
+
pointer: _pointer.pointer,
|
|
40
|
+
selectOptions: _selectOptions.selectOptions,
|
|
41
|
+
tab: _tab.tab,
|
|
42
|
+
tripleClick: _click.tripleClick,
|
|
43
|
+
type: _type.type,
|
|
44
|
+
unhover: _hover.unhover,
|
|
45
|
+
upload: _upload.upload
|
|
46
|
+
};
|
|
47
|
+
exports.userEventApis = userEventApis;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Start a "session" with userEvent.
|
|
51
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
52
|
+
*/
|
|
53
|
+
function setup(options = {}) {
|
|
54
|
+
var _options$document;
|
|
55
|
+
|
|
56
|
+
(0, _document.prepareDocument)((_options$document = options.document) != null ? _options$document : document);
|
|
57
|
+
return _setup(options, {
|
|
58
|
+
keyboardState: (0, _keyboard.createKeyboardState)(),
|
|
59
|
+
pointerState: (0, _pointer.createPointerState)()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function _setup({
|
|
64
|
+
applyAccept,
|
|
65
|
+
autoModify,
|
|
66
|
+
delay = 0,
|
|
67
|
+
document,
|
|
68
|
+
keyboardMap,
|
|
69
|
+
pointerMap,
|
|
70
|
+
skipAutoClose,
|
|
71
|
+
skipClick,
|
|
72
|
+
skipHover,
|
|
73
|
+
skipPointerEventsCheck = false
|
|
74
|
+
}, {
|
|
75
|
+
keyboardState,
|
|
76
|
+
pointerState
|
|
77
|
+
}) {
|
|
78
|
+
const keyboardDefaults = {
|
|
79
|
+
autoModify,
|
|
80
|
+
delay,
|
|
81
|
+
document,
|
|
82
|
+
keyboardMap
|
|
83
|
+
};
|
|
84
|
+
const pointerDefaults = {
|
|
85
|
+
skipPointerEventsCheck
|
|
86
|
+
};
|
|
87
|
+
const pointerApiDefaults = {
|
|
88
|
+
delay,
|
|
89
|
+
pointerMap
|
|
90
|
+
};
|
|
91
|
+
const clickDefaults = {
|
|
92
|
+
skipHover
|
|
93
|
+
};
|
|
94
|
+
const typeDefaults = {
|
|
95
|
+
delay,
|
|
96
|
+
skipAutoClose,
|
|
97
|
+
skipClick
|
|
98
|
+
};
|
|
99
|
+
const uploadDefaults = {
|
|
100
|
+
applyAccept
|
|
101
|
+
};
|
|
102
|
+
const userEvent = {
|
|
103
|
+
clear: (...args) => {
|
|
104
|
+
return _clear.clear.call(userEvent, ...args);
|
|
105
|
+
},
|
|
106
|
+
click: (...args) => {
|
|
107
|
+
args[1] = { ...pointerDefaults,
|
|
108
|
+
...clickDefaults,
|
|
109
|
+
...args[1]
|
|
110
|
+
};
|
|
111
|
+
return _click.click.call(userEvent, ...args);
|
|
112
|
+
},
|
|
113
|
+
dblClick: (...args) => {
|
|
114
|
+
args[1] = { ...pointerDefaults,
|
|
115
|
+
...clickDefaults,
|
|
116
|
+
...args[1]
|
|
117
|
+
};
|
|
118
|
+
return _click.dblClick.call(userEvent, ...args);
|
|
119
|
+
},
|
|
120
|
+
deselectOptions: (...args) => {
|
|
121
|
+
args[2] = { ...pointerDefaults,
|
|
122
|
+
...args[2]
|
|
123
|
+
};
|
|
124
|
+
return _selectOptions.deselectOptions.call(userEvent, ...args);
|
|
125
|
+
},
|
|
126
|
+
hover: (...args) => {
|
|
127
|
+
args[1] = { ...pointerDefaults,
|
|
128
|
+
...args[1]
|
|
129
|
+
};
|
|
130
|
+
return _hover.hover.call(userEvent, ...args);
|
|
131
|
+
},
|
|
132
|
+
// keyboard needs typecasting because of the overloading
|
|
133
|
+
keyboard: (...args) => {
|
|
134
|
+
args[1] = { ...keyboardDefaults,
|
|
135
|
+
...args[1],
|
|
136
|
+
keyboardState
|
|
137
|
+
};
|
|
138
|
+
const ret = (0, _keyboard.keyboard)(...args);
|
|
139
|
+
|
|
140
|
+
if (ret instanceof Promise) {
|
|
141
|
+
return ret.then(() => undefined);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
paste: (...args) => {
|
|
145
|
+
return _paste.paste.call(userEvent, ...args);
|
|
146
|
+
},
|
|
147
|
+
// pointer needs typecasting because of the overloading
|
|
148
|
+
pointer: (...args) => {
|
|
149
|
+
args[1] = { ...pointerApiDefaults,
|
|
150
|
+
...args[1],
|
|
151
|
+
pointerState,
|
|
152
|
+
keyboardState
|
|
153
|
+
};
|
|
154
|
+
const ret = (0, _pointer.pointer)(...args);
|
|
155
|
+
|
|
156
|
+
if (ret instanceof Promise) {
|
|
157
|
+
return ret.then(() => undefined);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
selectOptions: (...args) => {
|
|
161
|
+
args[2] = { ...pointerDefaults,
|
|
162
|
+
...args[2]
|
|
163
|
+
};
|
|
164
|
+
return _selectOptions.selectOptions.call(userEvent, ...args);
|
|
165
|
+
},
|
|
166
|
+
setup: options => {
|
|
167
|
+
return _setup({ ...keyboardDefaults,
|
|
168
|
+
...pointerDefaults,
|
|
169
|
+
...clickDefaults,
|
|
170
|
+
...options
|
|
171
|
+
}, {
|
|
172
|
+
keyboardState,
|
|
173
|
+
pointerState
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
tab: (...args) => {
|
|
177
|
+
return _tab.tab.call(userEvent, ...args);
|
|
178
|
+
},
|
|
179
|
+
tripleClick: (...args) => {
|
|
180
|
+
return _click.tripleClick.call(userEvent, ...args);
|
|
181
|
+
},
|
|
182
|
+
// type needs typecasting because of the overloading
|
|
183
|
+
type: (...args) => {
|
|
184
|
+
args[2] = { ...typeDefaults,
|
|
185
|
+
...args[2]
|
|
186
|
+
};
|
|
187
|
+
return _type.type.call(userEvent, ...args);
|
|
188
|
+
},
|
|
189
|
+
unhover: (...args) => {
|
|
190
|
+
args[1] = { ...pointerDefaults,
|
|
191
|
+
...args[1]
|
|
192
|
+
};
|
|
193
|
+
return _hover.unhover.call(userEvent, ...args);
|
|
194
|
+
},
|
|
195
|
+
upload: (...args) => {
|
|
196
|
+
args[3] = { ...uploadDefaults,
|
|
197
|
+
...args[3]
|
|
198
|
+
};
|
|
199
|
+
return _upload.upload.call(userEvent, ...args);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return userEvent;
|
|
203
|
+
}
|
package/dist/tab.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export interface tabOptions {
|
|
2
3
|
shift?: boolean;
|
|
3
|
-
focusTrap?: Document | Element;
|
|
4
4
|
}
|
|
5
|
-
declare function tab({ shift
|
|
6
|
-
export { tab };
|
|
5
|
+
export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
|
package/dist/tab.js
CHANGED
|
@@ -5,141 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.tab = tab;
|
|
7
7
|
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
var _focus = require("./focus");
|
|
13
|
-
|
|
14
|
-
var _blur = require("./blur");
|
|
15
|
-
|
|
16
|
-
function getNextElement(currentIndex, shift, elements, focusTrap) {
|
|
17
|
-
if ((0, _utils.isDocument)(focusTrap) && (currentIndex === 0 && shift || currentIndex === elements.length - 1 && !shift)) {
|
|
18
|
-
return focusTrap.body;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
22
|
-
const defaultIndex = shift ? elements.length - 1 : 0;
|
|
23
|
-
return elements[nextIndex] || elements[defaultIndex];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
8
|
function tab({
|
|
27
|
-
shift
|
|
28
|
-
focusTrap
|
|
9
|
+
shift
|
|
29
10
|
} = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
|
|
33
|
-
const previousElement = (0, _utils.getActiveElement)(doc);
|
|
34
|
-
|
|
35
|
-
if (!focusTrap) {
|
|
36
|
-
focusTrap = doc;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
|
|
40
|
-
const enabledElements = Array.from(focusableElements).filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !(0, _utils.isDisabled)(el) && // Hidden elements are not tabable
|
|
41
|
-
(0, _utils.isVisible)(el));
|
|
42
|
-
if (enabledElements.length === 0) return;
|
|
43
|
-
const orderedElements = enabledElements.map((el, idx) => ({
|
|
44
|
-
el,
|
|
45
|
-
idx
|
|
46
|
-
})).sort((a, b) => {
|
|
47
|
-
// tabindex has no effect if the active element has tabindex="-1"
|
|
48
|
-
if (previousElement && previousElement.getAttribute('tabindex') === '-1') {
|
|
49
|
-
return a.idx - b.idx;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const tabIndexA = Number(a.el.getAttribute('tabindex'));
|
|
53
|
-
const tabIndexB = Number(b.el.getAttribute('tabindex'));
|
|
54
|
-
const diff = tabIndexA - tabIndexB;
|
|
55
|
-
return diff === 0 ? a.idx - b.idx : diff;
|
|
56
|
-
}).map(({
|
|
57
|
-
el
|
|
58
|
-
}) => el); // TODO: verify/remove type casts
|
|
59
|
-
|
|
60
|
-
const checkedRadio = {};
|
|
61
|
-
let prunedElements = [];
|
|
62
|
-
orderedElements.forEach(currentElement => {
|
|
63
|
-
// For radio groups keep only the active radio
|
|
64
|
-
// If there is no active radio, keep only the checked radio
|
|
65
|
-
// If there is no checked radio, treat like everything else
|
|
66
|
-
const el = currentElement;
|
|
67
|
-
|
|
68
|
-
if (el.type === 'radio' && el.name) {
|
|
69
|
-
// If the active element is part of the group, add only that
|
|
70
|
-
const prev = previousElement;
|
|
71
|
-
|
|
72
|
-
if (prev && prev.type === el.type && prev.name === el.name) {
|
|
73
|
-
if (el === prev) {
|
|
74
|
-
prunedElements.push(el);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return;
|
|
78
|
-
} // If we stumble upon a checked radio, remove the others
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (el.checked) {
|
|
82
|
-
prunedElements = prunedElements.filter(e => e.type !== el.type || e.name !== el.name);
|
|
83
|
-
prunedElements.push(el);
|
|
84
|
-
checkedRadio[el.name] = el;
|
|
85
|
-
return;
|
|
86
|
-
} // If we already found the checked one, skip
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
prunedElements.push(el);
|
|
95
|
-
});
|
|
96
|
-
const index = prunedElements.findIndex(el => el === previousElement);
|
|
97
|
-
const nextElement = getNextElement(index, shift, prunedElements, focusTrap);
|
|
98
|
-
const shiftKeyInit = {
|
|
99
|
-
key: 'Shift',
|
|
100
|
-
keyCode: 16,
|
|
101
|
-
shiftKey: true
|
|
102
|
-
};
|
|
103
|
-
const tabKeyInit = {
|
|
104
|
-
key: 'Tab',
|
|
105
|
-
keyCode: 9,
|
|
106
|
-
shiftKey: shift
|
|
107
|
-
};
|
|
108
|
-
let continueToTab = true; // not sure how to make it so there's no previous element...
|
|
109
|
-
// istanbul ignore else
|
|
110
|
-
|
|
111
|
-
if (previousElement) {
|
|
112
|
-
// preventDefault on the shift key makes no difference
|
|
113
|
-
if (shift) _dom.fireEvent.keyDown(previousElement, { ...shiftKeyInit
|
|
114
|
-
});
|
|
115
|
-
continueToTab = _dom.fireEvent.keyDown(previousElement, { ...tabKeyInit
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const keyUpTarget = !continueToTab && previousElement ? previousElement : nextElement;
|
|
120
|
-
|
|
121
|
-
if (continueToTab) {
|
|
122
|
-
if (nextElement === doc.body) {
|
|
123
|
-
/* istanbul ignore else */
|
|
124
|
-
if (previousElement) {
|
|
125
|
-
(0, _blur.blur)(previousElement);
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
(0, _focus.focus)(nextElement);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...tabKeyInit
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
if (shift) {
|
|
136
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...shiftKeyInit,
|
|
137
|
-
shiftKey: false
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/*
|
|
142
|
-
eslint
|
|
143
|
-
complexity: "off",
|
|
144
|
-
max-statements: "off",
|
|
145
|
-
*/
|
|
11
|
+
this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
12
|
+
}
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export interface typeOptions {
|
|
3
|
+
delay?: number;
|
|
4
|
+
skipClick?: boolean;
|
|
5
|
+
skipAutoClose?: boolean;
|
|
6
|
+
initialSelectionStart?: number;
|
|
7
|
+
initialSelectionEnd?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function type(this: UserEvent, element: Element, text: string, options?: typeOptions & {
|
|
10
|
+
delay?: 0;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function type(this: UserEvent, element: Element, text: string, options: typeOptions & {
|
|
13
|
+
delay: number;
|
|
14
|
+
}): Promise<void>;
|
package/dist/type.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.type = type;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _document = require("./document");
|
|
11
|
+
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
|
|
14
|
+
var _keyboard = require("./keyboard");
|
|
15
|
+
|
|
16
|
+
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
|
|
17
|
+
// depending on whether it will be async.
|
|
18
|
+
function type(element, text, {
|
|
19
|
+
delay = 0,
|
|
20
|
+
...options
|
|
21
|
+
} = {}) {
|
|
22
|
+
(0, _document.prepareDocument)(element.ownerDocument); // we do not want to wrap in the asyncWrapper if we're not
|
|
23
|
+
// going to actually be doing anything async, so we only wrap
|
|
24
|
+
// if the delay is greater than 0
|
|
25
|
+
|
|
26
|
+
if (delay > 0) {
|
|
27
|
+
return (0, _dom.getConfig)().asyncWrapper(() => typeImplementation(this, element, text, {
|
|
28
|
+
delay,
|
|
29
|
+
...options
|
|
30
|
+
}));
|
|
31
|
+
} else {
|
|
32
|
+
return void typeImplementation(this, element, text, {
|
|
33
|
+
delay,
|
|
34
|
+
...options
|
|
35
|
+
}) // prevents users from dealing with UnhandledPromiseRejectionWarning
|
|
36
|
+
.catch(console.error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function typeImplementation(userEvent, element, text, {
|
|
41
|
+
delay,
|
|
42
|
+
skipClick = false,
|
|
43
|
+
skipAutoClose = false,
|
|
44
|
+
initialSelectionStart = undefined,
|
|
45
|
+
initialSelectionEnd = undefined
|
|
46
|
+
}) {
|
|
47
|
+
// TODO: properly type guard
|
|
48
|
+
// we use this workaround for now to prevent changing behavior
|
|
49
|
+
if (element.disabled) return;
|
|
50
|
+
if (!skipClick) userEvent.click(element);
|
|
51
|
+
|
|
52
|
+
if (initialSelectionStart !== undefined) {
|
|
53
|
+
(0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
promise,
|
|
58
|
+
releaseAllKeys
|
|
59
|
+
} = (0, _keyboard.keyboardImplementationWrapper)(text, {
|
|
60
|
+
delay,
|
|
61
|
+
document: element.ownerDocument
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (delay > 0) {
|
|
65
|
+
await promise;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!skipAutoClose) {
|
|
69
|
+
releaseAllKeys();
|
|
70
|
+
} // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return promise;
|
|
74
|
+
}
|