@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.
Files changed (120) hide show
  1. package/dist/clipboard/copy.d.ts +2 -0
  2. package/dist/clipboard/copy.js +36 -0
  3. package/dist/clipboard/cut.d.ts +2 -0
  4. package/dist/clipboard/cut.js +42 -0
  5. package/dist/clipboard/index.d.ts +3 -0
  6. package/dist/clipboard/index.js +44 -0
  7. package/dist/clipboard/paste.d.ts +2 -0
  8. package/dist/clipboard/paste.js +47 -0
  9. package/dist/convenience/click.d.ts +4 -0
  10. package/dist/convenience/click.js +52 -0
  11. package/dist/convenience/hover.d.ts +3 -0
  12. package/dist/convenience/hover.js +31 -0
  13. package/dist/convenience/index.d.ts +3 -0
  14. package/dist/convenience/index.js +44 -0
  15. package/dist/convenience/tab.d.ts +4 -0
  16. package/dist/convenience/tab.js +12 -0
  17. package/dist/index.d.ts +2 -7
  18. package/dist/index.js +3 -12
  19. package/dist/keyboard/getEventProps.d.ts +0 -2
  20. package/dist/keyboard/getEventProps.js +1 -7
  21. package/dist/keyboard/index.d.ts +6 -18
  22. package/dist/keyboard/index.js +9 -45
  23. package/dist/keyboard/keyMap.js +24 -48
  24. package/dist/keyboard/keyboardAction.d.ts +10 -0
  25. package/dist/keyboard/keyboardAction.js +156 -0
  26. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
  27. package/dist/keyboard/parseKeyDef.js +61 -0
  28. package/dist/keyboard/plugins/character.js +21 -14
  29. package/dist/keyboard/plugins/combination.js +3 -1
  30. package/dist/keyboard/plugins/functional.js +38 -20
  31. package/dist/keyboard/plugins/index.d.ts +0 -1
  32. package/dist/keyboard/plugins/index.js +1 -10
  33. package/dist/keyboard/types.d.ts +3 -19
  34. package/dist/options.d.ts +102 -0
  35. package/dist/options.js +36 -0
  36. package/dist/pointer/index.d.ts +6 -14
  37. package/dist/pointer/index.js +8 -42
  38. package/dist/pointer/parseKeyDef.d.ts +2 -2
  39. package/dist/pointer/parseKeyDef.js +1 -3
  40. package/dist/pointer/pointerAction.d.ts +3 -2
  41. package/dist/pointer/pointerAction.js +9 -15
  42. package/dist/pointer/pointerMove.d.ts +2 -1
  43. package/dist/pointer/pointerPress.d.ts +2 -1
  44. package/dist/pointer/pointerPress.js +13 -16
  45. package/dist/pointer/types.d.ts +0 -11
  46. package/dist/setup/api.d.ts +5 -0
  47. package/dist/setup/api.js +111 -0
  48. package/dist/setup/config.d.ts +10 -0
  49. package/dist/setup/config.js +8 -0
  50. package/dist/setup/directApi.d.ts +20 -0
  51. package/dist/setup/directApi.js +95 -0
  52. package/dist/setup/index.d.ts +30 -0
  53. package/dist/setup/index.js +27 -0
  54. package/dist/setup/setup.d.ts +74 -0
  55. package/dist/setup/setup.js +98 -0
  56. package/dist/setup/wrapAsync.d.ts +4 -0
  57. package/dist/setup/wrapAsync.js +15 -0
  58. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  59. package/dist/utility/clear.js +30 -0
  60. package/dist/utility/index.d.ts +4 -0
  61. package/dist/utility/index.js +57 -0
  62. package/dist/utility/selectOptions.d.ts +3 -0
  63. package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
  64. package/dist/utility/type.d.ts +9 -0
  65. package/dist/utility/type.js +37 -0
  66. package/dist/utility/upload.d.ts +5 -0
  67. package/dist/{upload.js → utility/upload.js} +12 -40
  68. package/dist/utils/dataTransfer/Blob.d.ts +1 -0
  69. package/dist/utils/dataTransfer/Blob.js +21 -0
  70. package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
  71. package/dist/utils/dataTransfer/Clipboard.js +188 -0
  72. package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
  73. package/dist/utils/dataTransfer/DataTransfer.js +158 -0
  74. package/dist/utils/dataTransfer/FileList.d.ts +1 -0
  75. package/dist/utils/dataTransfer/FileList.js +23 -0
  76. package/dist/utils/edit/calculateNewValue.d.ts +1 -3
  77. package/dist/utils/edit/calculateNewValue.js +1 -5
  78. package/dist/utils/edit/editInputElement.d.ts +16 -0
  79. package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +8 -20
  80. package/dist/utils/edit/prepareInput.d.ts +4 -1
  81. package/dist/utils/edit/prepareInput.js +56 -39
  82. package/dist/utils/edit/setFiles.d.ts +12 -0
  83. package/dist/utils/edit/setFiles.js +72 -0
  84. package/dist/utils/focus/copySelection.d.ts +1 -0
  85. package/dist/utils/focus/copySelection.js +36 -0
  86. package/dist/utils/focus/getTabDestination.js +14 -1
  87. package/dist/utils/focus/selectAll.d.ts +1 -0
  88. package/dist/utils/focus/selectAll.js +13 -0
  89. package/dist/utils/index.d.ts +8 -2
  90. package/dist/utils/index.js +95 -17
  91. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  92. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  93. package/dist/utils/misc/hasFormSubmit.js +1 -1
  94. package/dist/utils/misc/isVisible.js +8 -1
  95. package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
  96. package/dist/utils/pointer/firePointerEvents.js +67 -12
  97. package/package.json +1 -1
  98. package/dist/clear.js +0 -46
  99. package/dist/click.d.ts +0 -9
  100. package/dist/click.js +0 -62
  101. package/dist/hover.d.ts +0 -4
  102. package/dist/hover.js +0 -43
  103. package/dist/keyboard/getNextKeyDef.js +0 -85
  104. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  105. package/dist/keyboard/keyboardImplementation.js +0 -169
  106. package/dist/keyboard/specialCharMap.d.ts +0 -22
  107. package/dist/keyboard/specialCharMap.js +0 -30
  108. package/dist/paste.d.ts +0 -7
  109. package/dist/paste.js +0 -60
  110. package/dist/selectOptions.d.ts +0 -4
  111. package/dist/setup.d.ts +0 -92
  112. package/dist/setup.js +0 -203
  113. package/dist/tab.d.ts +0 -5
  114. package/dist/tab.js +0 -12
  115. package/dist/type.d.ts +0 -14
  116. package/dist/type.js +0 -74
  117. package/dist/upload.d.ts +0 -10
  118. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  119. package/dist/utils/pointer/fakeEvent.d.ts +0 -20
  120. package/dist/utils/pointer/fakeEvent.js +0 -91
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getNextKeyDef = getNextKeyDef;
7
-
8
- var _utils = require("../utils");
9
-
10
- var legacyModifiers;
11
-
12
- (function (legacyModifiers) {
13
- legacyModifiers["alt"] = "alt";
14
- legacyModifiers["ctrl"] = "ctrl";
15
- legacyModifiers["meta"] = "meta";
16
- legacyModifiers["shift"] = "shift";
17
- })(legacyModifiers || (legacyModifiers = {}));
18
-
19
- var legacyKeyMap;
20
- /**
21
- * Get the next key from keyMap
22
- *
23
- * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
24
- * Everything else will be interpreted as a typed character - e.g. `a`.
25
- * Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
26
- * Keeping the key pressed can be written as `{key>}`.
27
- * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
28
- * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
29
- * Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
30
- */
31
-
32
- (function (legacyKeyMap) {
33
- legacyKeyMap["ctrl"] = "Control";
34
- legacyKeyMap["del"] = "Delete";
35
- legacyKeyMap["esc"] = "Escape";
36
- legacyKeyMap["space"] = " ";
37
- })(legacyKeyMap || (legacyKeyMap = {}));
38
-
39
- function getNextKeyDef(text, options) {
40
- var _options$keyboardMap$;
41
-
42
- const {
43
- type,
44
- descriptor,
45
- consumedLength,
46
- releasePrevious,
47
- releaseSelf = !(type === '{' && getEnumValue(legacyModifiers, descriptor.toLowerCase())),
48
- repeat
49
- } = (0, _utils.readNextDescriptor)(text);
50
- const keyDef = (_options$keyboardMap$ = options.keyboardMap.find(def => {
51
- if (type === '[') {
52
- var _def$code;
53
-
54
- return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
55
- } else if (type === '{') {
56
- var _def$key;
57
-
58
- const key = mapLegacyKey(descriptor);
59
- return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === key.toLowerCase();
60
- }
61
-
62
- return def.key === descriptor;
63
- })) != null ? _options$keyboardMap$ : {
64
- key: 'Unknown',
65
- code: 'Unknown',
66
- [type === '[' ? 'code' : 'key']: descriptor
67
- };
68
- return {
69
- keyDef,
70
- consumedLength,
71
- releasePrevious,
72
- releaseSelf,
73
- repeat
74
- };
75
- }
76
-
77
- function getEnumValue(f, key) {
78
- return f[key];
79
- }
80
-
81
- function mapLegacyKey(descriptor) {
82
- var _getEnumValue;
83
-
84
- return (_getEnumValue = getEnumValue(legacyKeyMap, descriptor)) != null ? _getEnumValue : descriptor;
85
- }
@@ -1,3 +0,0 @@
1
- import { keyboardState, keyboardOptions } from './types';
2
- export declare function keyboardImplementation(text: string, options: keyboardOptions, state: keyboardState): Promise<void>;
3
- export declare function releaseAllKeys(options: keyboardOptions, state: keyboardState): void;
@@ -1,169 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyboardImplementation = keyboardImplementation;
7
- exports.releaseAllKeys = releaseAllKeys;
8
-
9
- var _dom = require("@testing-library/dom");
10
-
11
- var _utils = require("../utils");
12
-
13
- var _getNextKeyDef = require("./getNextKeyDef");
14
-
15
- var plugins = _interopRequireWildcard(require("./plugins"));
16
-
17
- var _getEventProps = require("./getEventProps");
18
-
19
- 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); }
20
-
21
- 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; }
22
-
23
- async function keyboardImplementation(text, options, state) {
24
- var _state$repeatKey;
25
-
26
- const {
27
- document
28
- } = options;
29
-
30
- const getCurrentElement = () => getActive(document);
31
-
32
- const {
33
- keyDef,
34
- consumedLength,
35
- releasePrevious,
36
- releaseSelf,
37
- repeat
38
- } = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
39
- const replace = applyPlugins(plugins.replaceBehavior, keyDef, getCurrentElement(), options, state);
40
-
41
- if (!replace) {
42
- const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
43
- // Do not release the key on iterations on `state.repeatKey`.
44
-
45
- if (pressed && !state.repeatKey) {
46
- keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
47
- }
48
-
49
- if (!releasePrevious) {
50
- const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
51
-
52
- if (unpreventedDefault && hasKeyPress(keyDef, state)) {
53
- keypress(keyDef, getCurrentElement, options, state);
54
- } // Release the key only on the last iteration on `state.repeatKey`.
55
-
56
-
57
- if (releaseSelf && repeat <= 1) {
58
- keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
59
- }
60
- }
61
- }
62
-
63
- if (repeat > 1) {
64
- state.repeatKey = {
65
- // don't consume again on the next iteration
66
- consumedLength: 0,
67
- keyDef,
68
- releasePrevious,
69
- releaseSelf,
70
- repeat: repeat - 1
71
- };
72
- } else {
73
- delete state.repeatKey;
74
- }
75
-
76
- if (text.length > consumedLength || repeat > 1) {
77
- if (options.delay > 0) {
78
- await (0, _utils.wait)(options.delay);
79
- }
80
-
81
- return keyboardImplementation(text.slice(consumedLength), options, state);
82
- }
83
-
84
- return void undefined;
85
- }
86
-
87
- function getActive(document) {
88
- var _getActiveElement;
89
-
90
- return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
91
- /* istanbul ignore next */
92
- document.body;
93
- }
94
-
95
- function releaseAllKeys(options, state) {
96
- const getCurrentElement = () => getActive(options.document);
97
-
98
- for (const k of state.pressed) {
99
- keyup(k.keyDef, getCurrentElement, options, state, k.unpreventedDefault);
100
- }
101
- }
102
-
103
- function keydown(keyDef, getCurrentElement, options, state) {
104
- const element = getCurrentElement(); // clear carried characters when focus is moved
105
-
106
- if (element !== state.activeElement) {
107
- state.carryValue = undefined;
108
- state.carryChar = '';
109
- }
110
-
111
- state.activeElement = element;
112
- applyPlugins(plugins.preKeydownBehavior, keyDef, element, options, state);
113
-
114
- const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
115
-
116
- state.pressed.push({
117
- keyDef,
118
- unpreventedDefault
119
- });
120
-
121
- if (unpreventedDefault) {
122
- // all default behavior like keypress/submit etc is applied to the currentElement
123
- applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), options, state);
124
- }
125
-
126
- return unpreventedDefault;
127
- }
128
-
129
- function keypress(keyDef, getCurrentElement, options, state) {
130
- const element = getCurrentElement();
131
-
132
- const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
133
- charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
134
- });
135
-
136
- if (unpreventedDefault) {
137
- applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
138
- }
139
- }
140
-
141
- function keyup(keyDef, getCurrentElement, options, state, unprevented) {
142
- const element = getCurrentElement();
143
- applyPlugins(plugins.preKeyupBehavior, keyDef, element, options, state);
144
-
145
- const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
146
-
147
- if (unprevented && unpreventedDefault) {
148
- applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), options, state);
149
- }
150
-
151
- state.pressed = state.pressed.filter(k => k.keyDef !== keyDef);
152
- applyPlugins(plugins.postKeyupBehavior, keyDef, element, options, state);
153
- }
154
-
155
- function applyPlugins(pluginCollection, keyDef, element, options, state) {
156
- const plugin = pluginCollection.find(p => p.matches(keyDef, element, options, state));
157
-
158
- if (plugin) {
159
- plugin.handle(keyDef, element, options, state);
160
- }
161
-
162
- return !!plugin;
163
- }
164
-
165
- function hasKeyPress(keyDef, state) {
166
- var _keyDef$key;
167
-
168
- return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !state.modifiers.ctrl && !state.modifiers.alt;
169
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * @deprecated This list of strings with special meaning is no longer necessary
3
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
4
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
5
- */
6
- export declare const specialCharMap: {
7
- readonly arrowLeft: "{arrowleft}";
8
- readonly arrowRight: "{arrowright}";
9
- readonly arrowDown: "{arrowdown}";
10
- readonly arrowUp: "{arrowup}";
11
- readonly enter: "{enter}";
12
- readonly escape: "{esc}";
13
- readonly delete: "{del}";
14
- readonly backspace: "{backspace}";
15
- readonly home: "{home}";
16
- readonly end: "{end}";
17
- readonly selectAll: "{selectall}";
18
- readonly space: "{space}";
19
- readonly whitespace: " ";
20
- readonly pageUp: "{pageUp}";
21
- readonly pageDown: "{pageDown}";
22
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.specialCharMap = void 0;
7
-
8
- /**
9
- * @deprecated This list of strings with special meaning is no longer necessary
10
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
11
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
12
- */
13
- const specialCharMap = {
14
- arrowLeft: '{arrowleft}',
15
- arrowRight: '{arrowright}',
16
- arrowDown: '{arrowdown}',
17
- arrowUp: '{arrowup}',
18
- enter: '{enter}',
19
- escape: '{esc}',
20
- delete: '{del}',
21
- backspace: '{backspace}',
22
- home: '{home}',
23
- end: '{end}',
24
- selectAll: '{selectall}',
25
- space: '{space}',
26
- whitespace: ' ',
27
- pageUp: '{pageUp}',
28
- pageDown: '{pageDown}'
29
- };
30
- exports.specialCharMap = specialCharMap;
package/dist/paste.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- interface pasteOptions {
3
- initialSelectionStart?: number;
4
- initialSelectionEnd?: number;
5
- }
6
- export declare function paste(this: UserEvent, element: HTMLElement, text: string, init?: ClipboardEventInit, { initialSelectionStart, initialSelectionEnd }?: pasteOptions): void;
7
- export {};
package/dist/paste.js DELETED
@@ -1,60 +0,0 @@
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 _utils = require("./utils");
11
-
12
- function isSupportedElement(element) {
13
- return (0, _utils.isElementType)(element, 'input') && Boolean(_utils.editableInputTypes[element.type]) || (0, _utils.isElementType)(element, 'textarea');
14
- }
15
-
16
- function paste(element, text, init, {
17
- initialSelectionStart,
18
- initialSelectionEnd
19
- } = {}) {
20
- var _prepareInput;
21
-
22
- // TODO: implement for contenteditable
23
- if (!isSupportedElement(element)) {
24
- throw new TypeError(`The given ${element.tagName} element is currently unsupported.
25
- A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event`);
26
- }
27
-
28
- if ((0, _utils.isDisabled)(element)) {
29
- return;
30
- }
31
-
32
- (0, _utils.eventWrapper)(() => element.focus()); // by default, a new element has it's selection start and end at 0
33
- // but most of the time when people call "paste", they expect it to paste
34
- // at the end of the current input value. So, if the selection start
35
- // and end are both the default of 0, then we'll go ahead and change
36
- // them to the length of the current value.
37
- // the only time it would make sense to pass the initialSelectionStart or
38
- // initialSelectionEnd is if you have an input with a value and want to
39
- // explicitely start typing with the cursor at 0. Not super common.
40
-
41
- if (element.selectionStart === 0 && element.selectionEnd === 0) {
42
- (0, _utils.setSelectionRange)(element, initialSelectionStart != null ? initialSelectionStart : element.value.length, initialSelectionEnd != null ? initialSelectionEnd : element.value.length);
43
- }
44
-
45
- _dom.fireEvent.paste(element, init);
46
-
47
- if (element.readOnly) {
48
- return;
49
- }
50
-
51
- text = text.substr(0, (0, _utils.getSpaceUntilMaxLength)(element));
52
- const inputRange = (0, _utils.getInputRange)(element);
53
- /* istanbul ignore if */
54
-
55
- if (!inputRange) {
56
- return;
57
- }
58
-
59
- (_prepareInput = (0, _utils.prepareInput)(text, element, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
60
- }
@@ -1,4 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, init?: MouseEventInit, options?: PointerOptions): void;
4
- export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, init?: MouseEventInit, options?: PointerOptions): void;
package/dist/setup.d.ts DELETED
@@ -1,92 +0,0 @@
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 DELETED
@@ -1,203 +0,0 @@
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[2] = { ...pointerDefaults,
108
- ...clickDefaults,
109
- ...args[2]
110
- };
111
- return _click.click.call(userEvent, ...args);
112
- },
113
- dblClick: (...args) => {
114
- args[2] = { ...pointerDefaults,
115
- ...clickDefaults,
116
- ...args[2]
117
- };
118
- return _click.dblClick.call(userEvent, ...args);
119
- },
120
- deselectOptions: (...args) => {
121
- args[3] = { ...pointerDefaults,
122
- ...args[3]
123
- };
124
- return _selectOptions.deselectOptions.call(userEvent, ...args);
125
- },
126
- hover: (...args) => {
127
- args[2] = { ...pointerDefaults,
128
- ...args[2]
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[3] = { ...pointerDefaults,
162
- ...args[3]
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[2] = { ...pointerDefaults,
191
- ...args[2]
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 DELETED
@@ -1,5 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface tabOptions {
3
- shift?: boolean;
4
- }
5
- export declare function tab(this: UserEvent, { shift }?: tabOptions): void;