@testing-library/user-event 14.0.0-alpha.8 → 14.0.0-beta.3
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/clipboard/copy.d.ts +2 -0
- package/dist/clipboard/copy.js +36 -0
- package/dist/clipboard/cut.d.ts +2 -0
- package/dist/clipboard/cut.js +42 -0
- package/dist/clipboard/index.d.ts +3 -0
- package/dist/clipboard/index.js +44 -0
- package/dist/clipboard/paste.d.ts +2 -0
- package/dist/clipboard/paste.js +47 -0
- package/dist/convenience/click.d.ts +4 -0
- package/dist/convenience/click.js +52 -0
- package/dist/convenience/hover.d.ts +3 -0
- package/dist/convenience/hover.js +31 -0
- package/dist/convenience/index.d.ts +3 -0
- package/dist/convenience/index.js +44 -0
- package/dist/convenience/tab.d.ts +4 -0
- package/dist/convenience/tab.js +12 -0
- package/dist/index.d.ts +2 -7
- package/dist/index.js +3 -12
- package/dist/keyboard/getEventProps.d.ts +0 -2
- package/dist/keyboard/getEventProps.js +1 -7
- package/dist/keyboard/index.d.ts +6 -18
- package/dist/keyboard/index.js +9 -45
- package/dist/keyboard/keyMap.js +24 -48
- package/dist/keyboard/keyboardAction.d.ts +10 -0
- package/dist/keyboard/keyboardAction.js +156 -0
- package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/character.js +21 -14
- package/dist/keyboard/plugins/combination.js +3 -1
- package/dist/keyboard/plugins/functional.js +38 -20
- package/dist/keyboard/plugins/index.d.ts +0 -1
- package/dist/keyboard/plugins/index.js +1 -10
- package/dist/keyboard/types.d.ts +3 -19
- package/dist/options.d.ts +102 -0
- package/dist/options.js +36 -0
- package/dist/pointer/index.d.ts +6 -14
- package/dist/pointer/index.js +8 -42
- package/dist/pointer/parseKeyDef.d.ts +2 -2
- package/dist/pointer/parseKeyDef.js +1 -3
- package/dist/pointer/pointerAction.d.ts +3 -2
- package/dist/pointer/pointerAction.js +9 -15
- package/dist/pointer/pointerMove.d.ts +2 -1
- package/dist/pointer/pointerPress.d.ts +2 -1
- package/dist/pointer/pointerPress.js +13 -16
- package/dist/pointer/types.d.ts +0 -11
- package/dist/setup/api.d.ts +5 -0
- package/dist/setup/api.js +111 -0
- package/dist/setup/config.d.ts +10 -0
- package/dist/setup/config.js +8 -0
- package/dist/setup/directApi.d.ts +20 -0
- package/dist/setup/directApi.js +95 -0
- package/dist/setup/index.d.ts +30 -0
- package/dist/setup/index.js +27 -0
- package/dist/setup/setup.d.ts +74 -0
- package/dist/setup/setup.js +98 -0
- package/dist/setup/wrapAsync.d.ts +4 -0
- package/dist/setup/wrapAsync.js +15 -0
- package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
- package/dist/utility/clear.js +30 -0
- package/dist/utility/index.d.ts +4 -0
- package/dist/utility/index.js +57 -0
- package/dist/utility/selectOptions.d.ts +3 -0
- package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
- package/dist/utility/type.d.ts +9 -0
- package/dist/utility/type.js +37 -0
- package/dist/utility/upload.d.ts +5 -0
- package/dist/{upload.js → utility/upload.js} +12 -40
- package/dist/utils/dataTransfer/Blob.d.ts +1 -0
- package/dist/utils/dataTransfer/Blob.js +21 -0
- package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
- package/dist/utils/dataTransfer/Clipboard.js +188 -0
- package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/utils/dataTransfer/DataTransfer.js +158 -0
- package/dist/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/utils/dataTransfer/FileList.js +23 -0
- package/dist/utils/edit/calculateNewValue.d.ts +1 -3
- package/dist/utils/edit/calculateNewValue.js +1 -5
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +8 -20
- package/dist/utils/edit/prepareInput.d.ts +4 -1
- package/dist/utils/edit/prepareInput.js +56 -39
- package/dist/utils/edit/setFiles.d.ts +12 -0
- package/dist/utils/edit/setFiles.js +72 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/focus/getTabDestination.js +14 -1
- package/dist/utils/focus/selectAll.d.ts +1 -0
- package/dist/utils/focus/selectAll.js +13 -0
- package/dist/utils/index.d.ts +8 -2
- package/dist/utils/index.js +95 -17
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/dist/utils/misc/hasFormSubmit.js +1 -1
- package/dist/utils/misc/isVisible.js +8 -1
- package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
- package/dist/utils/pointer/firePointerEvents.js +67 -12
- package/package.json +1 -1
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/selectOptions.d.ts +0 -4
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/utils/edit/fireInputEvent.d.ts +0 -11
- package/dist/utils/pointer/fakeEvent.d.ts +0 -20
- package/dist/utils/pointer/fakeEvent.js +0 -91
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Options } from '../options';
|
|
2
|
+
import type { UserEvent } from './index';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
import * as userEventApi from './api';
|
|
5
|
+
/**
|
|
6
|
+
* Start a "session" with userEvent.
|
|
7
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setupMain(options?: Options): {
|
|
10
|
+
setup: typeof setupSub;
|
|
11
|
+
[Config]: Config;
|
|
12
|
+
click: typeof userEventApi.click;
|
|
13
|
+
dblClick: typeof userEventApi.dblClick;
|
|
14
|
+
tripleClick: typeof userEventApi.tripleClick;
|
|
15
|
+
hover: typeof userEventApi.hover;
|
|
16
|
+
unhover: typeof userEventApi.unhover;
|
|
17
|
+
tab: typeof userEventApi.tab;
|
|
18
|
+
keyboard: typeof userEventApi.keyboard;
|
|
19
|
+
copy: typeof userEventApi.copy;
|
|
20
|
+
cut: typeof userEventApi.cut;
|
|
21
|
+
paste: typeof userEventApi.paste;
|
|
22
|
+
pointer: typeof userEventApi.pointer;
|
|
23
|
+
clear: typeof userEventApi.clear;
|
|
24
|
+
deselectOptions: typeof userEventApi.deselectOptions;
|
|
25
|
+
selectOptions: typeof userEventApi.selectOptions;
|
|
26
|
+
type: typeof userEventApi.type;
|
|
27
|
+
upload: typeof userEventApi.upload;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Setup in direct call per `userEvent.anyApi()`
|
|
31
|
+
*/
|
|
32
|
+
export declare function setupDirect(options?: Partial<Config>, node?: Node): {
|
|
33
|
+
setup: typeof setupSub;
|
|
34
|
+
[Config]: Config;
|
|
35
|
+
click: typeof userEventApi.click;
|
|
36
|
+
dblClick: typeof userEventApi.dblClick;
|
|
37
|
+
tripleClick: typeof userEventApi.tripleClick;
|
|
38
|
+
hover: typeof userEventApi.hover;
|
|
39
|
+
unhover: typeof userEventApi.unhover;
|
|
40
|
+
tab: typeof userEventApi.tab;
|
|
41
|
+
keyboard: typeof userEventApi.keyboard;
|
|
42
|
+
copy: typeof userEventApi.copy;
|
|
43
|
+
cut: typeof userEventApi.cut;
|
|
44
|
+
paste: typeof userEventApi.paste;
|
|
45
|
+
pointer: typeof userEventApi.pointer;
|
|
46
|
+
clear: typeof userEventApi.clear;
|
|
47
|
+
deselectOptions: typeof userEventApi.deselectOptions;
|
|
48
|
+
selectOptions: typeof userEventApi.selectOptions;
|
|
49
|
+
type: typeof userEventApi.type;
|
|
50
|
+
upload: typeof userEventApi.upload;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setupSub(this: UserEvent, options: Options): {
|
|
56
|
+
setup: typeof setupSub;
|
|
57
|
+
[Config]: Config;
|
|
58
|
+
click: typeof userEventApi.click;
|
|
59
|
+
dblClick: typeof userEventApi.dblClick;
|
|
60
|
+
tripleClick: typeof userEventApi.tripleClick;
|
|
61
|
+
hover: typeof userEventApi.hover;
|
|
62
|
+
unhover: typeof userEventApi.unhover;
|
|
63
|
+
tab: typeof userEventApi.tab;
|
|
64
|
+
keyboard: typeof userEventApi.keyboard;
|
|
65
|
+
copy: typeof userEventApi.copy;
|
|
66
|
+
cut: typeof userEventApi.cut;
|
|
67
|
+
paste: typeof userEventApi.paste;
|
|
68
|
+
pointer: typeof userEventApi.pointer;
|
|
69
|
+
clear: typeof userEventApi.clear;
|
|
70
|
+
deselectOptions: typeof userEventApi.deselectOptions;
|
|
71
|
+
selectOptions: typeof userEventApi.selectOptions;
|
|
72
|
+
type: typeof userEventApi.type;
|
|
73
|
+
upload: typeof userEventApi.upload;
|
|
74
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setupDirect = setupDirect;
|
|
7
|
+
exports.setupMain = setupMain;
|
|
8
|
+
exports.setupSub = setupSub;
|
|
9
|
+
|
|
10
|
+
var _document = require("../document");
|
|
11
|
+
|
|
12
|
+
var _keyboard = require("../keyboard");
|
|
13
|
+
|
|
14
|
+
var _pointer = require("../pointer");
|
|
15
|
+
|
|
16
|
+
var _options = require("../options");
|
|
17
|
+
|
|
18
|
+
var _utils = require("../utils");
|
|
19
|
+
|
|
20
|
+
var _config = require("./config");
|
|
21
|
+
|
|
22
|
+
var userEventApi = _interopRequireWildcard(require("./api"));
|
|
23
|
+
|
|
24
|
+
var _wrapAsync = require("./wrapAsync");
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Start a "session" with userEvent.
|
|
32
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
33
|
+
*/
|
|
34
|
+
function setupMain(options = {}) {
|
|
35
|
+
var _doc$defaultView;
|
|
36
|
+
|
|
37
|
+
const doc = getDocument(options);
|
|
38
|
+
(0, _document.prepareDocument)(doc);
|
|
39
|
+
const view = (_doc$defaultView = doc.defaultView) != null ? _doc$defaultView :
|
|
40
|
+
/* istanbul ignore next */
|
|
41
|
+
window;
|
|
42
|
+
(0, _utils.attachClipboardStubToView)(view);
|
|
43
|
+
return doSetup({ ..._options.defaultOptionsSetup,
|
|
44
|
+
keyboardState: (0, _keyboard.createKeyboardState)(),
|
|
45
|
+
pointerState: (0, _pointer.createPointerState)(doc)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Setup in direct call per `userEvent.anyApi()`
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function setupDirect(options = {}, node) {
|
|
54
|
+
const doc = getDocument(options, node);
|
|
55
|
+
(0, _document.prepareDocument)(doc);
|
|
56
|
+
return doSetup({
|
|
57
|
+
keyboardState: (0, _keyboard.createKeyboardState)(),
|
|
58
|
+
pointerState: (0, _pointer.createPointerState)(doc),
|
|
59
|
+
..._options.defaultOptionsDirect,
|
|
60
|
+
...options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function setupSub(options) {
|
|
69
|
+
return doSetup({ ...this[_config.Config],
|
|
70
|
+
...options
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function wrapImpl(impl) {
|
|
75
|
+
function method(...args) {
|
|
76
|
+
return (0, _wrapAsync.wrapAsync)(() => impl.apply(this, args));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Object.defineProperty(method, 'name', {
|
|
80
|
+
get: () => impl.name
|
|
81
|
+
});
|
|
82
|
+
return method;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const wrappedApis = Object.fromEntries(Object.entries(userEventApi).map(([name, impl]) => [name, wrapImpl(impl)]));
|
|
86
|
+
|
|
87
|
+
function doSetup(config) {
|
|
88
|
+
return { ...wrappedApis,
|
|
89
|
+
setup: setupSub,
|
|
90
|
+
[_config.Config]: config
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getDocument(options, node) {
|
|
95
|
+
var _ref, _options$document;
|
|
96
|
+
|
|
97
|
+
return (_ref = (_options$document = options.document) != null ? _options$document : node && (0, _utils.getDocumentFromNode)(node)) != null ? _ref : document;
|
|
98
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wrapAsync = wrapAsync;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wrap an internal Promise
|
|
12
|
+
*/
|
|
13
|
+
function wrapAsync(implementation) {
|
|
14
|
+
return (0, _dom.getConfig)().asyncWrapper(implementation);
|
|
15
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { UserEvent } from '
|
|
2
|
-
export declare function clear(this: UserEvent, element: Element): void
|
|
1
|
+
import type { UserEvent } from '../setup';
|
|
2
|
+
export declare function clear(this: UserEvent, element: Element): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clear = clear;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
|
|
10
|
+
async function clear(element) {
|
|
11
|
+
var _prepareInput;
|
|
12
|
+
|
|
13
|
+
if (!(0, _utils.isEditable)(element) || (0, _utils.isDisabled)(element)) {
|
|
14
|
+
throw new Error('clear()` is only supported on editable elements.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
(0, _utils.focus)(element);
|
|
18
|
+
|
|
19
|
+
if (element.ownerDocument.activeElement !== element) {
|
|
20
|
+
throw new Error('The element to be cleared could not be focused.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
(0, _utils.selectAll)(element);
|
|
24
|
+
|
|
25
|
+
if (!(0, _utils.isAllSelected)(element)) {
|
|
26
|
+
throw new Error('The element content to be cleared could not be selected.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _clear = require("./clear");
|
|
8
|
+
|
|
9
|
+
Object.keys(_clear).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _clear[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _clear[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _selectOptions = require("./selectOptions");
|
|
21
|
+
|
|
22
|
+
Object.keys(_selectOptions).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _selectOptions[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _selectOptions[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _type = require("./type");
|
|
34
|
+
|
|
35
|
+
Object.keys(_type).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _type[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _type[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _upload = require("./upload");
|
|
47
|
+
|
|
48
|
+
Object.keys(_upload).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _upload[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _upload[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UserEvent } from '../setup';
|
|
2
|
+
export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;
|
|
3
|
+
export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;
|
|
@@ -8,19 +8,19 @@ exports.selectOptions = selectOptions;
|
|
|
8
8
|
|
|
9
9
|
var _dom = require("@testing-library/dom");
|
|
10
10
|
|
|
11
|
-
var _utils = require("
|
|
11
|
+
var _utils = require("../utils");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
var _setup = require("../setup");
|
|
14
|
+
|
|
15
|
+
async function selectOptions(select, values) {
|
|
16
|
+
return selectOptionsBase.call(this, true, select, values);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
function deselectOptions(select, values
|
|
18
|
-
return selectOptionsBase.call(this, false, select, values
|
|
19
|
+
async function deselectOptions(select, values) {
|
|
20
|
+
return selectOptionsBase.call(this, false, select, values);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
function selectOptionsBase(newValue, select, values
|
|
22
|
-
skipPointerEventsCheck
|
|
23
|
-
}) {
|
|
23
|
+
async function selectOptionsBase(newValue, select, values) {
|
|
24
24
|
if (!newValue && !select.multiple) {
|
|
25
25
|
throw (0, _dom.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
26
26
|
}
|
|
@@ -45,47 +45,45 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
45
45
|
if ((0, _utils.isElementType)(select, 'select')) {
|
|
46
46
|
if (select.multiple) {
|
|
47
47
|
for (const option of selectedOptions) {
|
|
48
|
-
const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(option); // events fired for multiple select are weird. Can't use hover...
|
|
48
|
+
const withPointerEvents = this[_setup.Config].skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(option); // events fired for multiple select are weird. Can't use hover...
|
|
49
49
|
|
|
50
50
|
if (withPointerEvents) {
|
|
51
|
-
_dom.fireEvent.pointerOver(option
|
|
51
|
+
_dom.fireEvent.pointerOver(option);
|
|
52
52
|
|
|
53
|
-
_dom.fireEvent.pointerEnter(select
|
|
53
|
+
_dom.fireEvent.pointerEnter(select);
|
|
54
54
|
|
|
55
55
|
_dom.fireEvent.mouseOver(option);
|
|
56
56
|
|
|
57
57
|
_dom.fireEvent.mouseEnter(select);
|
|
58
58
|
|
|
59
|
-
_dom.fireEvent.pointerMove(option
|
|
59
|
+
_dom.fireEvent.pointerMove(option);
|
|
60
60
|
|
|
61
|
-
_dom.fireEvent.mouseMove(option
|
|
61
|
+
_dom.fireEvent.mouseMove(option);
|
|
62
62
|
|
|
63
|
-
_dom.fireEvent.pointerDown(option
|
|
63
|
+
_dom.fireEvent.pointerDown(option);
|
|
64
64
|
|
|
65
|
-
_dom.fireEvent.mouseDown(option
|
|
65
|
+
_dom.fireEvent.mouseDown(option);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
(0, _utils.focus)(select);
|
|
69
69
|
|
|
70
70
|
if (withPointerEvents) {
|
|
71
|
-
_dom.fireEvent.pointerUp(option
|
|
71
|
+
_dom.fireEvent.pointerUp(option);
|
|
72
72
|
|
|
73
|
-
_dom.fireEvent.mouseUp(option
|
|
73
|
+
_dom.fireEvent.mouseUp(option);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
selectOption(option);
|
|
77
77
|
|
|
78
78
|
if (withPointerEvents) {
|
|
79
|
-
_dom.fireEvent.click(option
|
|
79
|
+
_dom.fireEvent.click(option);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
} else if (selectedOptions.length === 1) {
|
|
83
|
-
const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(select); // the click to open the select options
|
|
83
|
+
const withPointerEvents = this[_setup.Config].skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(select); // the click to open the select options
|
|
84
84
|
|
|
85
85
|
if (withPointerEvents) {
|
|
86
|
-
this.click(select
|
|
87
|
-
skipPointerEventsCheck: true
|
|
88
|
-
});
|
|
86
|
+
await this.click(select);
|
|
89
87
|
} else {
|
|
90
88
|
(0, _utils.focus)(select);
|
|
91
89
|
}
|
|
@@ -95,35 +93,28 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
95
93
|
if (withPointerEvents) {
|
|
96
94
|
// the browser triggers another click event on the select for the click on the option
|
|
97
95
|
// this second click has no 'down' phase
|
|
98
|
-
_dom.fireEvent.pointerOver(select
|
|
96
|
+
_dom.fireEvent.pointerOver(select);
|
|
99
97
|
|
|
100
|
-
_dom.fireEvent.pointerEnter(select
|
|
98
|
+
_dom.fireEvent.pointerEnter(select);
|
|
101
99
|
|
|
102
100
|
_dom.fireEvent.mouseOver(select);
|
|
103
101
|
|
|
104
102
|
_dom.fireEvent.mouseEnter(select);
|
|
105
103
|
|
|
106
|
-
_dom.fireEvent.pointerUp(select
|
|
104
|
+
_dom.fireEvent.pointerUp(select);
|
|
107
105
|
|
|
108
|
-
_dom.fireEvent.mouseUp(select
|
|
106
|
+
_dom.fireEvent.mouseUp(select);
|
|
109
107
|
|
|
110
|
-
_dom.fireEvent.click(select
|
|
108
|
+
_dom.fireEvent.click(select);
|
|
111
109
|
}
|
|
112
110
|
} else {
|
|
113
111
|
throw (0, _dom.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
114
112
|
}
|
|
115
113
|
} else if (select.getAttribute('role') === 'listbox') {
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.click(option, init, {
|
|
121
|
-
skipPointerEventsCheck
|
|
122
|
-
});
|
|
123
|
-
this.unhover(option, init, {
|
|
124
|
-
skipPointerEventsCheck
|
|
125
|
-
});
|
|
126
|
-
});
|
|
114
|
+
for (const option of selectedOptions) {
|
|
115
|
+
await this.click(option);
|
|
116
|
+
await this.unhover(option);
|
|
117
|
+
}
|
|
127
118
|
} else {
|
|
128
119
|
throw (0, _dom.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
129
120
|
}
|
|
@@ -133,10 +124,9 @@ function selectOptionsBase(newValue, select, values, init, {
|
|
|
133
124
|
(0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
|
|
134
125
|
bubbles: true,
|
|
135
126
|
cancelable: false,
|
|
136
|
-
composed: true
|
|
137
|
-
...init
|
|
127
|
+
composed: true
|
|
138
128
|
}));
|
|
139
129
|
|
|
140
|
-
_dom.fireEvent.change(select
|
|
130
|
+
_dom.fireEvent.change(select);
|
|
141
131
|
}
|
|
142
132
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UserEvent } from '../setup';
|
|
2
|
+
import { Config } from '../setup/config';
|
|
3
|
+
export interface typeOptions {
|
|
4
|
+
skipClick?: Config['skipClick'];
|
|
5
|
+
skipAutoClose?: Config['skipClick'];
|
|
6
|
+
initialSelectionStart?: number;
|
|
7
|
+
initialSelectionEnd?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function type(this: UserEvent, element: Element, text: string, { skipClick, skipAutoClose, initialSelectionStart, initialSelectionEnd, }?: typeOptions): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.type = type;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
|
|
10
|
+
var _keyboard = require("../keyboard");
|
|
11
|
+
|
|
12
|
+
var _config = require("../setup/config");
|
|
13
|
+
|
|
14
|
+
async function type(element, text, {
|
|
15
|
+
skipClick = this[_config.Config].skipClick,
|
|
16
|
+
skipAutoClose = this[_config.Config].skipAutoClose,
|
|
17
|
+
initialSelectionStart,
|
|
18
|
+
initialSelectionEnd
|
|
19
|
+
} = {}) {
|
|
20
|
+
// TODO: properly type guard
|
|
21
|
+
// we use this workaround for now to prevent changing behavior
|
|
22
|
+
if (element.disabled) return;
|
|
23
|
+
|
|
24
|
+
if (!skipClick) {
|
|
25
|
+
await this.click(element);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (initialSelectionStart !== undefined) {
|
|
29
|
+
(0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await this.keyboard(text);
|
|
33
|
+
|
|
34
|
+
if (!skipAutoClose) {
|
|
35
|
+
await (0, _keyboard.releaseAllKeys)(this[_config.Config]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -7,11 +7,11 @@ exports.upload = upload;
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
-
var _utils = require("
|
|
10
|
+
var _utils = require("../utils");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var _setup = require("../setup");
|
|
13
|
+
|
|
14
|
+
async function upload(element, fileOrFiles) {
|
|
15
15
|
var _input$files;
|
|
16
16
|
|
|
17
17
|
const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
|
|
@@ -23,8 +23,8 @@ function upload(element, fileOrFiles, init, {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if ((0, _utils.isDisabled)(element)) return;
|
|
26
|
-
this.click(element
|
|
27
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
26
|
+
await this.click(element);
|
|
27
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !this[_setup.Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
28
28
|
|
|
29
29
|
(0, _utils.blur)(element); // focus fires when they make their selection
|
|
30
30
|
|
|
@@ -36,41 +36,13 @@ function upload(element, fileOrFiles, init, {
|
|
|
36
36
|
return f === ((_input$files2 = input.files) == null ? void 0 : _input$files2.item(i));
|
|
37
37
|
})) {
|
|
38
38
|
return;
|
|
39
|
-
}
|
|
40
|
-
// but a new Event with a type set to "input" and "change"
|
|
41
|
-
// Kinda odd...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const inputFiles = { ...files,
|
|
45
|
-
length: files.length,
|
|
46
|
-
item: index => files[index],
|
|
47
|
-
|
|
48
|
-
[Symbol.iterator]() {
|
|
49
|
-
let i = 0;
|
|
50
|
-
return {
|
|
51
|
-
next: () => ({
|
|
52
|
-
done: i >= files.length,
|
|
53
|
-
value: files[i++]
|
|
54
|
-
})
|
|
55
|
-
};
|
|
56
|
-
}
|
|
39
|
+
}
|
|
57
40
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
bubbles: true,
|
|
64
|
-
cancelable: false,
|
|
65
|
-
composed: true
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
_dom.fireEvent.change(input, {
|
|
69
|
-
target: {
|
|
70
|
-
files: inputFiles
|
|
71
|
-
},
|
|
72
|
-
...(init == null ? void 0 : init.changeInit)
|
|
73
|
-
});
|
|
41
|
+
(0, _utils.setFiles)(input, (0, _utils.createFileList)(files));
|
|
42
|
+
|
|
43
|
+
_dom.fireEvent.input(input);
|
|
44
|
+
|
|
45
|
+
_dom.fireEvent.change(input);
|
|
74
46
|
}
|
|
75
47
|
|
|
76
48
|
function isAcceptableFile(file, accept) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readBlobText(blob: Blob): Promise<string>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.readBlobText = readBlobText;
|
|
7
|
+
|
|
8
|
+
// jsdom does not implement Blob.text()
|
|
9
|
+
function readBlobText(blob) {
|
|
10
|
+
return new Promise((res, rej) => {
|
|
11
|
+
const fr = new FileReader();
|
|
12
|
+
fr.onerror = rej;
|
|
13
|
+
fr.onabort = rej;
|
|
14
|
+
|
|
15
|
+
fr.onload = () => {
|
|
16
|
+
res(String(fr.result));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
fr.readAsText(blob);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function createClipboardItem(...blobs: Array<Blob | string>): ClipboardItem;
|
|
2
|
+
export declare function attachClipboardStubToView(window: Window & typeof globalThis): {
|
|
3
|
+
resetClipboardStub: () => void;
|
|
4
|
+
detachClipboardStub: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function resetClipboardStubOnView(window: Window & typeof globalThis): void;
|
|
7
|
+
export declare function detachClipboardStubFromView(window: Window & typeof globalThis): void;
|
|
8
|
+
export declare function readDataTransferFromClipboard(document: Document): Promise<DataTransfer>;
|
|
9
|
+
export declare function writeDataTransferToClipboard(document: Document, clipboardData: DataTransfer): Promise<void>;
|