@testing-library/user-event 14.0.0-alpha.12 → 14.0.0-alpha.16
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 -5
- package/dist/index.js +7 -8
- package/dist/keyboard/index.d.ts +6 -17
- package/dist/keyboard/index.js +13 -41
- 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 -5
- package/dist/keyboard/parseKeyDef.js +61 -0
- package/dist/keyboard/plugins/character.js +16 -10
- package/dist/keyboard/plugins/combination.js +3 -1
- package/dist/keyboard/plugins/functional.js +38 -20
- package/dist/keyboard/types.d.ts +3 -17
- 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/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 +21 -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/{clear.js → utility/clear.js} +2 -5
- 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} +15 -24
- 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} +6 -6
- 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 +13 -0
- package/dist/utils/focus/copySelection.d.ts +1 -0
- package/dist/utils/focus/copySelection.js +36 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +78 -0
- package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/utils/misc/getDocumentFromNode.js +14 -0
- package/package.json +1 -1
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -61
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getNextKeyDef.js +0 -55
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -165
- 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 -9
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copy = copy;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function copy() {
|
|
15
|
+
var _doc$activeElement;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
22
|
+
|
|
23
|
+
if (clipboardData.items.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_dom.fireEvent.copy(target, {
|
|
28
|
+
clipboardData
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (this[_setup.Config].writeToClipboard) {
|
|
32
|
+
await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return clipboardData;
|
|
36
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cut = cut;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function cut() {
|
|
15
|
+
var _doc$activeElement;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const clipboardData = (0, _utils.copySelection)(target);
|
|
22
|
+
|
|
23
|
+
if (clipboardData.items.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_dom.fireEvent.cut(target, {
|
|
28
|
+
clipboardData
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if ((0, _utils.isEditable)(target)) {
|
|
32
|
+
var _prepareInput;
|
|
33
|
+
|
|
34
|
+
(_prepareInput = (0, _utils.prepareInput)('', target, 'deleteByCut')) == null ? void 0 : _prepareInput.commit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (this[_setup.Config].writeToClipboard) {
|
|
38
|
+
await (0, _utils.writeDataTransferToClipboard)(doc, clipboardData);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return clipboardData;
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _copy = require("./copy");
|
|
8
|
+
|
|
9
|
+
Object.keys(_copy).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _copy[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _copy[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _cut = require("./cut");
|
|
21
|
+
|
|
22
|
+
Object.keys(_cut).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _cut[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _cut[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _paste = require("./paste");
|
|
34
|
+
|
|
35
|
+
Object.keys(_paste).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _paste[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _paste[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.paste = paste;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _setup = require("../setup");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function paste(clipboardData) {
|
|
15
|
+
var _doc$activeElement, _ref;
|
|
16
|
+
|
|
17
|
+
const doc = this[_setup.Config].document;
|
|
18
|
+
const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
doc.body;
|
|
21
|
+
const data = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _ref : await (0, _utils.readDataTransferFromClipboard)(doc).catch(() => {
|
|
22
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
23
|
+
});
|
|
24
|
+
return pasteImpl(target, data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function pasteImpl(target, clipboardData) {
|
|
28
|
+
_dom.fireEvent.paste(target, {
|
|
29
|
+
clipboardData
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if ((0, _utils.isEditable)(target)) {
|
|
33
|
+
const data = clipboardData.getData('text').substr(0, (0, _utils.getSpaceUntilMaxLength)(target));
|
|
34
|
+
|
|
35
|
+
if (data) {
|
|
36
|
+
var _prepareInput;
|
|
37
|
+
|
|
38
|
+
(_prepareInput = (0, _utils.prepareInput)(data, target, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getClipboardDataFromString(text) {
|
|
44
|
+
const dt = (0, _utils.createDataTransfer)();
|
|
45
|
+
dt.setData('text', text);
|
|
46
|
+
return dt;
|
|
47
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UserEvent } from '../setup';
|
|
2
|
+
export declare function click(this: UserEvent, element: Element): Promise<void>;
|
|
3
|
+
export declare function dblClick(this: UserEvent, element: Element): Promise<void>;
|
|
4
|
+
export declare function tripleClick(this: UserEvent, element: Element): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.click = click;
|
|
7
|
+
exports.dblClick = dblClick;
|
|
8
|
+
exports.tripleClick = tripleClick;
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
var _setup = require("../setup");
|
|
13
|
+
|
|
14
|
+
async function click(element) {
|
|
15
|
+
if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
16
|
+
throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const pointerIn = [];
|
|
20
|
+
|
|
21
|
+
if (!this[_setup.Config].skipHover) {
|
|
22
|
+
pointerIn.push({
|
|
23
|
+
target: element
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
pointerIn.push({
|
|
28
|
+
keys: '[MouseLeft]',
|
|
29
|
+
target: element
|
|
30
|
+
});
|
|
31
|
+
return this.pointer(pointerIn);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function dblClick(element) {
|
|
35
|
+
if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
36
|
+
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.pointer([{
|
|
40
|
+
target: element
|
|
41
|
+
}, '[MouseLeft][MouseLeft]']);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function tripleClick(element) {
|
|
45
|
+
if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
46
|
+
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return this.pointer([{
|
|
50
|
+
target: element
|
|
51
|
+
}, '[MouseLeft][MouseLeft][MouseLeft]']);
|
|
52
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hover = hover;
|
|
7
|
+
exports.unhover = unhover;
|
|
8
|
+
|
|
9
|
+
var _setup = require("../setup");
|
|
10
|
+
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
|
|
13
|
+
async function hover(element) {
|
|
14
|
+
if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
15
|
+
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return this.pointer({
|
|
19
|
+
target: element
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function unhover(element) {
|
|
24
|
+
if (!this[_setup.Config].skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
25
|
+
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this.pointer({
|
|
29
|
+
target: element.ownerDocument.body
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _click = require("./click");
|
|
8
|
+
|
|
9
|
+
Object.keys(_click).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _click[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _click[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _hover = require("./hover");
|
|
21
|
+
|
|
22
|
+
Object.keys(_hover).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _hover[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _hover[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _tab = require("./tab");
|
|
34
|
+
|
|
35
|
+
Object.keys(_tab).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _tab[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _tab[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tab = tab;
|
|
7
|
+
|
|
8
|
+
async function tab({
|
|
9
|
+
shift
|
|
10
|
+
} = {}) {
|
|
11
|
+
return this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
12
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare const userEvent: UserEventApis & {
|
|
3
|
-
setup: typeof setup;
|
|
4
|
-
};
|
|
5
|
-
export default userEvent;
|
|
1
|
+
export { userEvent as default } from './setup';
|
|
6
2
|
export type { keyboardKey } from './keyboard';
|
|
3
|
+
export type { pointerKey } from './pointer';
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _setup.userEvent;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
setup: _setup.setup
|
|
12
|
-
};
|
|
13
|
-
var _default = userEvent;
|
|
14
|
-
exports.default = _default;
|
|
13
|
+
var _setup = require("./setup");
|
package/dist/keyboard/index.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function keyboard(text: string, options: Partial<keyboardOptions & {
|
|
8
|
-
keyboardState: keyboardState;
|
|
9
|
-
delay: number;
|
|
10
|
-
}>): Promise<keyboardState>;
|
|
11
|
-
export declare function keyboardImplementationWrapper(text: string, config?: Partial<keyboardOptions & {
|
|
12
|
-
keyboardState: keyboardState;
|
|
13
|
-
}>): {
|
|
14
|
-
promise: Promise<void>;
|
|
15
|
-
state: keyboardState;
|
|
16
|
-
releaseAllKeys: () => void;
|
|
17
|
-
};
|
|
1
|
+
import { UserEvent } from '../setup';
|
|
2
|
+
import { releaseAllKeys } from './keyboardAction';
|
|
3
|
+
import type { keyboardState, keyboardKey } from './types';
|
|
4
|
+
export { releaseAllKeys };
|
|
5
|
+
export type { keyboardKey, keyboardState };
|
|
6
|
+
export declare function keyboard(this: UserEvent, text: string): Promise<void>;
|
|
18
7
|
export declare function createKeyboardState(): keyboardState;
|
package/dist/keyboard/index.js
CHANGED
|
@@ -5,53 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createKeyboardState = createKeyboardState;
|
|
7
7
|
exports.keyboard = keyboard;
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _keyboardImplementation = require("./keyboardImplementation");
|
|
15
|
-
|
|
16
|
-
var _keyMap = require("./keyMap");
|
|
8
|
+
Object.defineProperty(exports, "releaseAllKeys", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _keyboardAction.releaseAllKeys;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
var _options$delay;
|
|
15
|
+
var _setup = require("../setup");
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
promise,
|
|
23
|
-
state
|
|
24
|
-
} = keyboardImplementationWrapper(text, options);
|
|
17
|
+
var _keyboardAction = require("./keyboardAction");
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
return (0, _dom.getConfig)().asyncWrapper(() => promise.then(() => state));
|
|
28
|
-
} else {
|
|
29
|
-
// prevent users from dealing with UnhandledPromiseRejectionWarning in sync call
|
|
30
|
-
promise.catch(console.error);
|
|
31
|
-
return state;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
19
|
+
var _parseKeyDef = require("./parseKeyDef");
|
|
34
20
|
|
|
35
|
-
function
|
|
21
|
+
async function keyboard(text) {
|
|
36
22
|
const {
|
|
37
|
-
keyboardState: state = createKeyboardState(),
|
|
38
|
-
delay = 0,
|
|
39
|
-
document: doc = document,
|
|
40
|
-
autoModify = false,
|
|
41
|
-
keyboardMap = _keyMap.defaultKeyMap
|
|
42
|
-
} = config;
|
|
43
|
-
const options = {
|
|
44
|
-
delay,
|
|
45
|
-
document: doc,
|
|
46
|
-
autoModify,
|
|
47
23
|
keyboardMap
|
|
48
|
-
};
|
|
49
|
-
(0,
|
|
50
|
-
return
|
|
51
|
-
promise: (0, _keyboardImplementation.keyboardImplementation)(text, options, state),
|
|
52
|
-
state,
|
|
53
|
-
releaseAllKeys: () => (0, _keyboardImplementation.releaseAllKeys)(options, state)
|
|
54
|
-
};
|
|
24
|
+
} = this[_setup.Config];
|
|
25
|
+
const actions = (0, _parseKeyDef.parseKeyDef)(keyboardMap, text);
|
|
26
|
+
return (0, _keyboardAction.keyboardAction)(this[_setup.Config], actions);
|
|
55
27
|
}
|
|
56
28
|
|
|
57
29
|
function createKeyboardState() {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Config } from '../setup';
|
|
2
|
+
import { keyboardKey } from './types';
|
|
3
|
+
export interface KeyboardAction {
|
|
4
|
+
keyDef: keyboardKey;
|
|
5
|
+
releasePrevious: boolean;
|
|
6
|
+
releaseSelf: boolean;
|
|
7
|
+
repeat: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function keyboardAction(config: Config, actions: KeyboardAction[]): Promise<void>;
|
|
10
|
+
export declare function releaseAllKeys(config: Config): Promise<void>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keyboardAction = keyboardAction;
|
|
7
|
+
exports.releaseAllKeys = releaseAllKeys;
|
|
8
|
+
|
|
9
|
+
var _dom = require("@testing-library/dom");
|
|
10
|
+
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
|
|
13
|
+
var plugins = _interopRequireWildcard(require("./plugins"));
|
|
14
|
+
|
|
15
|
+
var _getEventProps = require("./getEventProps");
|
|
16
|
+
|
|
17
|
+
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); }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
async function keyboardAction(config, actions) {
|
|
22
|
+
for (let i = 0; i < actions.length; i++) {
|
|
23
|
+
await keyboardKeyAction(config, actions[i]);
|
|
24
|
+
|
|
25
|
+
if (typeof config.delay === 'number' && i < actions.length - 1) {
|
|
26
|
+
await (0, _utils.wait)(config.delay);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function keyboardKeyAction(config, {
|
|
32
|
+
keyDef,
|
|
33
|
+
releasePrevious,
|
|
34
|
+
releaseSelf,
|
|
35
|
+
repeat
|
|
36
|
+
}) {
|
|
37
|
+
const {
|
|
38
|
+
document,
|
|
39
|
+
keyboardState,
|
|
40
|
+
delay
|
|
41
|
+
} = config;
|
|
42
|
+
|
|
43
|
+
const getCurrentElement = () => getActive(document); // Release the key automatically if it was pressed before.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef);
|
|
47
|
+
|
|
48
|
+
if (pressed) {
|
|
49
|
+
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!releasePrevious) {
|
|
53
|
+
let unpreventedDefault = true;
|
|
54
|
+
|
|
55
|
+
for (let i = 1; i <= repeat; i++) {
|
|
56
|
+
unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
|
|
57
|
+
|
|
58
|
+
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
59
|
+
await keypress(keyDef, getCurrentElement, config);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof delay === 'number' && i < repeat) {
|
|
63
|
+
await (0, _utils.wait)(delay);
|
|
64
|
+
}
|
|
65
|
+
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (releaseSelf) {
|
|
69
|
+
await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getActive(document) {
|
|
75
|
+
var _getActiveElement;
|
|
76
|
+
|
|
77
|
+
return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
|
|
78
|
+
/* istanbul ignore next */
|
|
79
|
+
document.body;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function releaseAllKeys(config) {
|
|
83
|
+
const getCurrentElement = () => getActive(config.document);
|
|
84
|
+
|
|
85
|
+
for (const k of config.keyboardState.pressed) {
|
|
86
|
+
await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function keydown(keyDef, getCurrentElement, config) {
|
|
91
|
+
const element = getCurrentElement(); // clear carried characters when focus is moved
|
|
92
|
+
|
|
93
|
+
if (element !== config.keyboardState.activeElement) {
|
|
94
|
+
config.keyboardState.carryValue = undefined;
|
|
95
|
+
config.keyboardState.carryChar = '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
config.keyboardState.activeElement = element;
|
|
99
|
+
applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
|
|
100
|
+
|
|
101
|
+
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
102
|
+
|
|
103
|
+
config.keyboardState.pressed.push({
|
|
104
|
+
keyDef,
|
|
105
|
+
unpreventedDefault
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (unpreventedDefault) {
|
|
109
|
+
// all default behavior like keypress/submit etc is applied to the currentElement
|
|
110
|
+
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return unpreventedDefault;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function keypress(keyDef, getCurrentElement, config) {
|
|
117
|
+
const element = getCurrentElement();
|
|
118
|
+
|
|
119
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
|
|
120
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (unpreventedDefault) {
|
|
124
|
+
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
129
|
+
const element = getCurrentElement();
|
|
130
|
+
applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
|
|
131
|
+
|
|
132
|
+
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
133
|
+
|
|
134
|
+
if (unprevented && unpreventedDefault) {
|
|
135
|
+
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
|
|
139
|
+
applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
143
|
+
const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
|
|
144
|
+
|
|
145
|
+
if (plugin) {
|
|
146
|
+
plugin.handle(keyDef, element, config);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return !!plugin;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function hasKeyPress(keyDef, config) {
|
|
153
|
+
var _keyDef$key;
|
|
154
|
+
|
|
155
|
+
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
|
|
156
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { keyboardKey
|
|
1
|
+
import { keyboardKey } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parse key defintions per `keyboardMap`
|
|
4
4
|
*
|
|
5
5
|
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
6
6
|
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
@@ -9,10 +9,9 @@ import { keyboardKey, keyboardOptions } from './types';
|
|
|
9
9
|
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
10
10
|
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function parseKeyDef(keyboardMap: keyboardKey[], text: string): {
|
|
13
13
|
keyDef: keyboardKey;
|
|
14
|
-
consumedLength: number;
|
|
15
14
|
releasePrevious: boolean;
|
|
16
15
|
releaseSelf: boolean;
|
|
17
16
|
repeat: number;
|
|
18
|
-
};
|
|
17
|
+
}[];
|