@testing-library/react-native 14.0.0-alpha.6 → 14.0.0-beta.1
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 +30 -30
- package/build/config.js +10 -4
- package/build/config.js.map +1 -1
- package/build/event-builder/base.d.ts +7 -0
- package/build/{user-event/event-builder → event-builder}/base.js +1 -1
- package/build/event-builder/base.js.map +1 -0
- package/build/event-builder/common.d.ts +152 -0
- package/build/event-builder/common.js +80 -0
- package/build/event-builder/common.js.map +1 -0
- package/build/event-builder/index.d.ts +3 -0
- package/build/event-builder/index.js +39 -0
- package/build/event-builder/index.js.map +1 -0
- package/build/event-builder/scroll.d.ts +56 -0
- package/build/event-builder/scroll.js +51 -0
- package/build/event-builder/scroll.js.map +1 -0
- package/build/event-builder/text.d.ts +162 -0
- package/build/event-builder/text.js +113 -0
- package/build/event-builder/text.js.map +1 -0
- package/build/event-handler.d.ts +0 -1
- package/build/event-handler.js +0 -1
- package/build/event-handler.js.map +1 -1
- package/build/fire-event.d.ts +6 -7
- package/build/fire-event.js +47 -28
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +18 -15
- package/build/helpers/accessibility.js +64 -47
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +9 -9
- package/build/helpers/component-tree.js +17 -17
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/errors.d.ts +1 -3
- package/build/helpers/errors.js +3 -36
- package/build/helpers/errors.js.map +1 -1
- package/build/helpers/find-all.d.ts +2 -2
- package/build/helpers/find-all.js +1 -1
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +5 -5
- package/build/helpers/format-element.js +9 -9
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +13 -13
- package/build/helpers/host-component-names.js +18 -18
- package/build/helpers/host-component-names.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-state.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-state.js +6 -6
- package/build/helpers/matchers/match-accessibility-state.js.map +1 -1
- package/build/helpers/matchers/match-accessibility-value.d.ts +2 -2
- package/build/helpers/matchers/match-accessibility-value.js +2 -2
- package/build/helpers/matchers/match-accessibility-value.js.map +1 -1
- package/build/helpers/matchers/match-label-text.d.ts +2 -2
- package/build/helpers/matchers/match-label-text.js +2 -2
- package/build/helpers/matchers/match-label-text.js.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +5 -5
- package/build/helpers/matchers/match-text-content.js +5 -5
- package/build/helpers/matchers/match-text-content.js.map +1 -1
- package/build/helpers/pointer-events.d.ts +2 -2
- package/build/helpers/pointer-events.js +4 -4
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/text-content.d.ts +2 -2
- package/build/helpers/text-content.js +5 -5
- package/build/helpers/text-content.js.map +1 -1
- package/build/helpers/text-input.d.ts +3 -3
- package/build/helpers/text-input.js +6 -6
- package/build/helpers/text-input.js.map +1 -1
- package/build/helpers/validate-options.d.ts +9 -0
- package/build/helpers/validate-options.js +32 -0
- package/build/helpers/validate-options.js.map +1 -0
- package/build/matchers/to-be-busy.d.ts +2 -2
- package/build/matchers/to-be-busy.js +5 -5
- package/build/matchers/to-be-busy.js.map +1 -1
- package/build/matchers/to-be-checked.d.ts +2 -2
- package/build/matchers/to-be-checked.js +9 -9
- package/build/matchers/to-be-checked.js.map +1 -1
- package/build/matchers/to-be-disabled.d.ts +3 -3
- package/build/matchers/to-be-disabled.js +10 -10
- package/build/matchers/to-be-disabled.js.map +1 -1
- package/build/matchers/to-be-empty-element.d.ts +2 -2
- package/build/matchers/to-be-empty-element.js +4 -4
- package/build/matchers/to-be-empty-element.js.map +1 -1
- package/build/matchers/to-be-expanded.d.ts +3 -3
- package/build/matchers/to-be-expanded.js +10 -10
- package/build/matchers/to-be-expanded.js.map +1 -1
- package/build/matchers/to-be-on-the-screen.d.ts +2 -2
- package/build/matchers/to-be-on-the-screen.js +7 -7
- package/build/matchers/to-be-on-the-screen.js.map +1 -1
- package/build/matchers/to-be-partially-checked.d.ts +2 -2
- package/build/matchers/to-be-partially-checked.js +8 -8
- package/build/matchers/to-be-partially-checked.js.map +1 -1
- package/build/matchers/to-be-selected.d.ts +2 -2
- package/build/matchers/to-be-selected.js +4 -4
- package/build/matchers/to-be-selected.js.map +1 -1
- package/build/matchers/to-be-visible.d.ts +2 -2
- package/build/matchers/to-be-visible.js +12 -12
- package/build/matchers/to-be-visible.js.map +1 -1
- package/build/matchers/to-contain-element.d.ts +2 -2
- package/build/matchers/to-contain-element.js +6 -6
- package/build/matchers/to-contain-element.js.map +1 -1
- package/build/matchers/to-have-accessibility-value.d.ts +2 -2
- package/build/matchers/to-have-accessibility-value.js +6 -6
- package/build/matchers/to-have-accessibility-value.js.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +2 -2
- package/build/matchers/to-have-accessible-name.js +5 -10
- package/build/matchers/to-have-accessible-name.js.map +1 -1
- package/build/matchers/to-have-display-value.d.ts +2 -2
- package/build/matchers/to-have-display-value.js +6 -6
- package/build/matchers/to-have-display-value.js.map +1 -1
- package/build/matchers/to-have-prop.d.ts +2 -2
- package/build/matchers/to-have-prop.js +6 -6
- package/build/matchers/to-have-prop.js.map +1 -1
- package/build/matchers/to-have-style.d.ts +2 -2
- package/build/matchers/to-have-style.js +5 -5
- package/build/matchers/to-have-style.js.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +2 -2
- package/build/matchers/to-have-text-content.js +4 -4
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +20 -20
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +4 -4
- package/build/matchers/utils.js +6 -6
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +3 -3
- package/build/native-state.js +2 -2
- package/build/native-state.js.map +1 -1
- package/build/queries/display-value.d.ts +2 -2
- package/build/queries/display-value.js +12 -12
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +2 -2
- package/build/queries/hint-text.js +11 -11
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +2 -2
- package/build/queries/label-text.js +9 -9
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +8 -8
- package/build/queries/make-queries.js +11 -11
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +2 -2
- package/build/queries/placeholder-text.js +11 -11
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +2 -2
- package/build/queries/role.js +17 -27
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +2 -2
- package/build/queries/test-id.js +11 -11
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +2 -2
- package/build/queries/text.js +9 -9
- package/build/queries/text.js.map +1 -1
- package/build/render-hook.js +7 -1
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +4 -5
- package/build/render.js +22 -6
- package/build/render.js.map +1 -1
- package/build/screen.js.map +1 -1
- package/build/test-utils/react-version-gates.d.ts +1 -0
- package/build/test-utils/react-version-gates.js +28 -0
- package/build/test-utils/react-version-gates.js.map +1 -0
- package/build/test-utils/timers.d.ts +2 -0
- package/build/test-utils/timers.js +20 -0
- package/build/test-utils/timers.js.map +1 -0
- package/build/types.d.ts +7 -0
- package/build/types.js.map +1 -1
- package/build/user-event/clear.d.ts +2 -2
- package/build/user-event/clear.js +13 -13
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/index.d.ts +7 -7
- package/build/user-event/index.js +6 -6
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +2 -2
- package/build/user-event/paste.js +18 -18
- package/build/user-event/paste.js.map +1 -1
- package/build/user-event/press/press.d.ts +3 -3
- package/build/user-event/press/press.js +35 -35
- package/build/user-event/press/press.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +2 -2
- package/build/user-event/scroll/scroll-to.js +20 -20
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/setup/setup.d.ts +11 -11
- package/build/user-event/setup/setup.js +17 -3
- package/build/user-event/setup/setup.js.map +1 -1
- package/build/user-event/type/type.d.ts +3 -3
- package/build/user-event/type/type.js +27 -28
- package/build/user-event/type/type.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +3 -3
- package/build/user-event/utils/dispatch-event.js +4 -4
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/user-event/utils/index.d.ts +0 -1
- package/build/user-event/utils/index.js +0 -11
- package/build/user-event/utils/index.js.map +1 -1
- package/build/wait-for.js +8 -13
- package/build/wait-for.js.map +1 -1
- package/build/within.d.ts +3 -3
- package/build/within.js +10 -10
- package/build/within.js.map +1 -1
- package/package.json +38 -27
- package/build/react-versions.d.ts +0 -1
- package/build/react-versions.js +0 -14
- package/build/react-versions.js.map +0 -1
- package/build/tsconfig.release.tsbuildinfo +0 -1
- package/build/user-event/event-builder/base.d.ts +0 -3
- package/build/user-event/event-builder/base.js.map +0 -1
- package/build/user-event/event-builder/common.d.ts +0 -150
- package/build/user-event/event-builder/common.js +0 -77
- package/build/user-event/event-builder/common.js.map +0 -1
- package/build/user-event/event-builder/index.d.ts +0 -306
- package/build/user-event/event-builder/index.js +0 -15
- package/build/user-event/event-builder/index.js.map +0 -1
- package/build/user-event/event-builder/scroll-view.d.ts +0 -57
- package/build/user-event/event-builder/scroll-view.js +0 -53
- package/build/user-event/event-builder/scroll-view.js.map +0 -1
- package/build/user-event/event-builder/text-input.d.ts +0 -159
- package/build/user-event/event-builder/text-input.js +0 -105
- package/build/user-event/event-builder/text-input.js.map +0 -1
- package/build/user-event/utils/text-range.d.ts +0 -4
- package/build/user-event/utils/text-range.js +0 -6
- package/build/user-event/utils/text-range.js.map +0 -1
|
@@ -4,43 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.clear = clear;
|
|
7
|
+
var _eventBuilder = require("../event-builder");
|
|
7
8
|
var _errors = require("../helpers/errors");
|
|
8
9
|
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
10
|
var _pointerEvents = require("../helpers/pointer-events");
|
|
10
11
|
var _textInput = require("../helpers/text-input");
|
|
11
|
-
var _eventBuilder = require("./event-builder");
|
|
12
12
|
var _type = require("./type/type");
|
|
13
13
|
var _utils = require("./utils");
|
|
14
|
-
async function clear(
|
|
15
|
-
if (!(0, _hostComponentNames.isHostTextInput)(
|
|
16
|
-
throw new _errors.ErrorWithStack(`clear() only supports host "TextInput"
|
|
14
|
+
async function clear(instance) {
|
|
15
|
+
if (!(0, _hostComponentNames.isHostTextInput)(instance)) {
|
|
16
|
+
throw new _errors.ErrorWithStack(`clear() only supports host "TextInput" instances. Passed instance has type: "${instance.type}".`, clear);
|
|
17
17
|
}
|
|
18
|
-
if (!(0, _textInput.isEditableTextInput)(
|
|
18
|
+
if (!(0, _textInput.isEditableTextInput)(instance) || !(0, _pointerEvents.isPointerEventEnabled)(instance)) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// 1. Enter
|
|
23
|
-
await (0, _utils.dispatchEvent)(
|
|
22
|
+
// 1. Enter instance
|
|
23
|
+
await (0, _utils.dispatchEvent)(instance, 'focus', (0, _eventBuilder.buildFocusEvent)());
|
|
24
24
|
|
|
25
25
|
// 2. Select all
|
|
26
|
-
const textToClear = (0, _textInput.getTextInputValue)(
|
|
26
|
+
const textToClear = (0, _textInput.getTextInputValue)(instance);
|
|
27
27
|
const selectionRange = {
|
|
28
28
|
start: 0,
|
|
29
29
|
end: textToClear.length
|
|
30
30
|
};
|
|
31
|
-
await (0, _utils.dispatchEvent)(
|
|
31
|
+
await (0, _utils.dispatchEvent)(instance, 'selectionChange', (0, _eventBuilder.buildTextSelectionChangeEvent)(selectionRange));
|
|
32
32
|
|
|
33
33
|
// 3. Press backspace with selected text
|
|
34
34
|
const emptyText = '';
|
|
35
|
-
await (0, _type.emitTypingEvents)(
|
|
35
|
+
await (0, _type.emitTypingEvents)(instance, {
|
|
36
36
|
config: this.config,
|
|
37
37
|
key: 'Backspace',
|
|
38
38
|
text: emptyText
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
// 4. Exit
|
|
41
|
+
// 4. Exit instance
|
|
42
42
|
await (0, _utils.wait)(this.config);
|
|
43
|
-
await (0, _utils.dispatchEvent)(
|
|
44
|
-
await (0, _utils.dispatchEvent)(
|
|
43
|
+
await (0, _utils.dispatchEvent)(instance, 'endEditing', (0, _eventBuilder.buildEndEditingEvent)(emptyText));
|
|
44
|
+
await (0, _utils.dispatchEvent)(instance, 'blur', (0, _eventBuilder.buildBlurEvent)());
|
|
45
45
|
}
|
|
46
46
|
//# sourceMappingURL=clear.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.js","names":["
|
|
1
|
+
{"version":3,"file":"clear.js","names":["_eventBuilder","require","_errors","_hostComponentNames","_pointerEvents","_textInput","_type","_utils","clear","instance","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","buildFocusEvent","textToClear","getTextInputValue","selectionRange","start","end","length","buildTextSelectionChangeEvent","emptyText","emitTypingEvents","config","key","text","wait","buildEndEditingEvent","buildBlurEvent"],"sources":["../../src/user-event/clear.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport {\n buildBlurEvent,\n buildEndEditingEvent,\n buildFocusEvent,\n buildTextSelectionChangeEvent,\n} from '../event-builder';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport type { UserEventInstance } from './setup';\nimport { emitTypingEvents } from './type/type';\nimport { dispatchEvent, wait } from './utils';\n\nexport async function clear(this: UserEventInstance, instance: TestInstance): Promise<void> {\n if (!isHostTextInput(instance)) {\n throw new ErrorWithStack(\n `clear() only supports host \"TextInput\" instances. Passed instance has type: \"${instance.type}\".`,\n clear,\n );\n }\n\n if (!isEditableTextInput(instance) || !isPointerEventEnabled(instance)) {\n return;\n }\n\n // 1. Enter instance\n await dispatchEvent(instance, 'focus', buildFocusEvent());\n\n // 2. Select all\n const textToClear = getTextInputValue(instance);\n const selectionRange = {\n start: 0,\n end: textToClear.length,\n };\n await dispatchEvent(instance, 'selectionChange', buildTextSelectionChangeEvent(selectionRange));\n\n // 3. Press backspace with selected text\n const emptyText = '';\n await emitTypingEvents(instance, {\n config: this.config,\n key: 'Backspace',\n text: emptyText,\n });\n\n // 4. Exit instance\n await wait(this.config);\n await dispatchEvent(instance, 'endEditing', buildEndEditingEvent(emptyText));\n await dispatchEvent(instance, 'blur', buildBlurEvent());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAA0BC,QAAsB,EAAiB;EAC1F,IAAI,CAAC,IAAAC,mCAAe,EAACD,QAAQ,CAAC,EAAE;IAC9B,MAAM,IAAIE,sBAAc,CACtB,gFAAgFF,QAAQ,CAACG,IAAI,IAAI,EACjGJ,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAK,8BAAmB,EAACJ,QAAQ,CAAC,IAAI,CAAC,IAAAK,oCAAqB,EAACL,QAAQ,CAAC,EAAE;IACtE;EACF;;EAEA;EACA,MAAM,IAAAM,oBAAa,EAACN,QAAQ,EAAE,OAAO,EAAE,IAAAO,6BAAe,EAAC,CAAC,CAAC;;EAEzD;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACT,QAAQ,CAAC;EAC/C,MAAMU,cAAc,GAAG;IACrBC,KAAK,EAAE,CAAC;IACRC,GAAG,EAAEJ,WAAW,CAACK;EACnB,CAAC;EACD,MAAM,IAAAP,oBAAa,EAACN,QAAQ,EAAE,iBAAiB,EAAE,IAAAc,2CAA6B,EAACJ,cAAc,CAAC,CAAC;;EAE/F;EACA,MAAMK,SAAS,GAAG,EAAE;EACpB,MAAM,IAAAC,sBAAgB,EAAChB,QAAQ,EAAE;IAC/BiB,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,WAAW;IAChBC,IAAI,EAAEJ;EACR,CAAC,CAAC;;EAEF;EACA,MAAM,IAAAK,WAAI,EAAC,IAAI,CAACH,MAAM,CAAC;EACvB,MAAM,IAAAX,oBAAa,EAACN,QAAQ,EAAE,YAAY,EAAE,IAAAqB,kCAAoB,EAACN,SAAS,CAAC,CAAC;EAC5E,MAAM,IAAAT,oBAAa,EAACN,QAAQ,EAAE,MAAM,EAAE,IAAAsB,4BAAc,EAAC,CAAC,CAAC;AACzD","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { PressOptions } from './press';
|
|
3
3
|
import type { ScrollToOptions } from './scroll';
|
|
4
4
|
import { setup } from './setup';
|
|
@@ -6,10 +6,10 @@ import type { TypeOptions } from './type';
|
|
|
6
6
|
export { UserEventConfig } from './setup';
|
|
7
7
|
export declare const userEvent: {
|
|
8
8
|
setup: typeof setup;
|
|
9
|
-
press: (
|
|
10
|
-
longPress: (
|
|
11
|
-
type: (
|
|
12
|
-
clear: (
|
|
13
|
-
paste: (
|
|
14
|
-
scrollTo: (
|
|
9
|
+
press: (instance: TestInstance) => Promise<void>;
|
|
10
|
+
longPress: (instance: TestInstance, options?: PressOptions) => Promise<void>;
|
|
11
|
+
type: (instance: TestInstance, text: string, options?: TypeOptions) => Promise<void>;
|
|
12
|
+
clear: (instance: TestInstance) => Promise<void>;
|
|
13
|
+
paste: (instance: TestInstance, text: string) => Promise<void>;
|
|
14
|
+
scrollTo: (instance: TestInstance, options: ScrollToOptions) => Promise<void>;
|
|
15
15
|
};
|
|
@@ -14,11 +14,11 @@ var _setup = require("./setup");
|
|
|
14
14
|
const userEvent = exports.userEvent = {
|
|
15
15
|
setup: _setup.setup,
|
|
16
16
|
// Direct access for User Event v13 compatibility
|
|
17
|
-
press:
|
|
18
|
-
longPress: (
|
|
19
|
-
type: (
|
|
20
|
-
clear:
|
|
21
|
-
paste: (
|
|
22
|
-
scrollTo: (
|
|
17
|
+
press: instance => (0, _setup.setup)().press(instance),
|
|
18
|
+
longPress: (instance, options) => (0, _setup.setup)().longPress(instance, options),
|
|
19
|
+
type: (instance, text, options) => (0, _setup.setup)().type(instance, text, options),
|
|
20
|
+
clear: instance => (0, _setup.setup)().clear(instance),
|
|
21
|
+
paste: (instance, text) => (0, _setup.setup)().paste(instance, text),
|
|
22
|
+
scrollTo: (instance, options) => (0, _setup.setup)().scrollTo(instance, options)
|
|
23
23
|
};
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_setup","require","userEvent","exports","setup","press","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_setup","require","userEvent","exports","setup","press","instance","longPress","options","type","text","clear","paste","scrollTo"],"sources":["../../src/user-event/index.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport type { PressOptions } from './press';\nimport type { ScrollToOptions } from './scroll';\nimport { setup } from './setup';\nimport type { TypeOptions } from './type';\n\nexport { UserEventConfig } from './setup';\n\nexport const userEvent = {\n setup,\n\n // Direct access for User Event v13 compatibility\n press: (instance: TestInstance) => setup().press(instance),\n longPress: (instance: TestInstance, options?: PressOptions) =>\n setup().longPress(instance, options),\n type: (instance: TestInstance, text: string, options?: TypeOptions) =>\n setup().type(instance, text, options),\n clear: (instance: TestInstance) => setup().clear(instance),\n paste: (instance: TestInstance, text: string) => setup().paste(instance, text),\n scrollTo: (instance: TestInstance, options: ScrollToOptions) =>\n setup().scrollTo(instance, options),\n};\n"],"mappings":";;;;;;;;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AAKO,MAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACvBE,KAAK,EAALA,YAAK;EAEL;EACAC,KAAK,EAAGC,QAAsB,IAAK,IAAAF,YAAK,EAAC,CAAC,CAACC,KAAK,CAACC,QAAQ,CAAC;EAC1DC,SAAS,EAAEA,CAACD,QAAsB,EAAEE,OAAsB,KACxD,IAAAJ,YAAK,EAAC,CAAC,CAACG,SAAS,CAACD,QAAQ,EAAEE,OAAO,CAAC;EACtCC,IAAI,EAAEA,CAACH,QAAsB,EAAEI,IAAY,EAAEF,OAAqB,KAChE,IAAAJ,YAAK,EAAC,CAAC,CAACK,IAAI,CAACH,QAAQ,EAAEI,IAAI,EAAEF,OAAO,CAAC;EACvCG,KAAK,EAAGL,QAAsB,IAAK,IAAAF,YAAK,EAAC,CAAC,CAACO,KAAK,CAACL,QAAQ,CAAC;EAC1DM,KAAK,EAAEA,CAACN,QAAsB,EAAEI,IAAY,KAAK,IAAAN,YAAK,EAAC,CAAC,CAACQ,KAAK,CAACN,QAAQ,EAAEI,IAAI,CAAC;EAC9EG,QAAQ,EAAEA,CAACP,QAAsB,EAAEE,OAAwB,KACzD,IAAAJ,YAAK,EAAC,CAAC,CAACS,QAAQ,CAACP,QAAQ,EAAEE,OAAO;AACtC,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { UserEventInstance } from './setup';
|
|
3
|
-
export declare function paste(this: UserEventInstance,
|
|
3
|
+
export declare function paste(this: UserEventInstance, instance: TestInstance, text: string): Promise<void>;
|
|
@@ -4,53 +4,53 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.paste = paste;
|
|
7
|
+
var _eventBuilder = require("../event-builder");
|
|
7
8
|
var _errors = require("../helpers/errors");
|
|
8
9
|
var _hostComponentNames = require("../helpers/host-component-names");
|
|
9
10
|
var _pointerEvents = require("../helpers/pointer-events");
|
|
10
11
|
var _textInput = require("../helpers/text-input");
|
|
11
12
|
var _nativeState = require("../native-state");
|
|
12
|
-
var _eventBuilder = require("./event-builder");
|
|
13
13
|
var _utils = require("./utils");
|
|
14
|
-
async function paste(
|
|
15
|
-
if (!(0, _hostComponentNames.isHostTextInput)(
|
|
16
|
-
throw new _errors.ErrorWithStack(`paste() only supports host "TextInput"
|
|
14
|
+
async function paste(instance, text) {
|
|
15
|
+
if (!(0, _hostComponentNames.isHostTextInput)(instance)) {
|
|
16
|
+
throw new _errors.ErrorWithStack(`paste() only supports host "TextInput" instances. Passed instance has type: "${instance.type}".`, paste);
|
|
17
17
|
}
|
|
18
|
-
if (!(0, _textInput.isEditableTextInput)(
|
|
18
|
+
if (!(0, _textInput.isEditableTextInput)(instance) || !(0, _pointerEvents.isPointerEventEnabled)(instance)) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// 1. Enter
|
|
23
|
-
await (0, _utils.dispatchEvent)(
|
|
22
|
+
// 1. Enter instance
|
|
23
|
+
await (0, _utils.dispatchEvent)(instance, 'focus', (0, _eventBuilder.buildFocusEvent)());
|
|
24
24
|
|
|
25
25
|
// 2. Select all
|
|
26
|
-
const textToClear = (0, _textInput.getTextInputValue)(
|
|
26
|
+
const textToClear = (0, _textInput.getTextInputValue)(instance);
|
|
27
27
|
const rangeToClear = {
|
|
28
28
|
start: 0,
|
|
29
29
|
end: textToClear.length
|
|
30
30
|
};
|
|
31
|
-
await (0, _utils.dispatchEvent)(
|
|
31
|
+
await (0, _utils.dispatchEvent)(instance, 'selectionChange', (0, _eventBuilder.buildTextSelectionChangeEvent)(rangeToClear));
|
|
32
32
|
|
|
33
33
|
// 3. Paste the text
|
|
34
|
-
_nativeState.nativeState.
|
|
35
|
-
await (0, _utils.dispatchEvent)(
|
|
36
|
-
await (0, _utils.dispatchEvent)(
|
|
34
|
+
_nativeState.nativeState.valueForInstance.set(instance, text);
|
|
35
|
+
await (0, _utils.dispatchEvent)(instance, 'change', (0, _eventBuilder.buildTextChangeEvent)(text));
|
|
36
|
+
await (0, _utils.dispatchEvent)(instance, 'changeText', text);
|
|
37
37
|
const rangeAfter = {
|
|
38
38
|
start: text.length,
|
|
39
39
|
end: text.length
|
|
40
40
|
};
|
|
41
|
-
await (0, _utils.dispatchEvent)(
|
|
41
|
+
await (0, _utils.dispatchEvent)(instance, 'selectionChange', (0, _eventBuilder.buildTextSelectionChangeEvent)(rangeAfter));
|
|
42
42
|
|
|
43
43
|
// According to the docs only multiline TextInput emits contentSizeChange event
|
|
44
44
|
// @see: https://reactnative.dev/docs/textinput#oncontentsizechange
|
|
45
|
-
const isMultiline =
|
|
45
|
+
const isMultiline = instance.props.multiline === true;
|
|
46
46
|
if (isMultiline) {
|
|
47
47
|
const contentSize = (0, _utils.getTextContentSize)(text);
|
|
48
|
-
await (0, _utils.dispatchEvent)(
|
|
48
|
+
await (0, _utils.dispatchEvent)(instance, 'contentSizeChange', (0, _eventBuilder.buildContentSizeChangeEvent)(contentSize));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// 4. Exit
|
|
51
|
+
// 4. Exit instance
|
|
52
52
|
await (0, _utils.wait)(this.config);
|
|
53
|
-
await (0, _utils.dispatchEvent)(
|
|
54
|
-
await (0, _utils.dispatchEvent)(
|
|
53
|
+
await (0, _utils.dispatchEvent)(instance, 'endEditing', (0, _eventBuilder.buildEndEditingEvent)(text));
|
|
54
|
+
await (0, _utils.dispatchEvent)(instance, 'blur', (0, _eventBuilder.buildBlurEvent)());
|
|
55
55
|
}
|
|
56
56
|
//# sourceMappingURL=paste.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.js","names":["
|
|
1
|
+
{"version":3,"file":"paste.js","names":["_eventBuilder","require","_errors","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_utils","paste","instance","text","isHostTextInput","ErrorWithStack","type","isEditableTextInput","isPointerEventEnabled","dispatchEvent","buildFocusEvent","textToClear","getTextInputValue","rangeToClear","start","end","length","buildTextSelectionChangeEvent","nativeState","valueForInstance","set","buildTextChangeEvent","rangeAfter","isMultiline","props","multiline","contentSize","getTextContentSize","buildContentSizeChangeEvent","wait","config","buildEndEditingEvent","buildBlurEvent"],"sources":["../../src/user-event/paste.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport {\n buildBlurEvent,\n buildContentSizeChangeEvent,\n buildEndEditingEvent,\n buildFocusEvent,\n buildTextChangeEvent,\n buildTextSelectionChangeEvent,\n} from '../event-builder';\nimport { ErrorWithStack } from '../helpers/errors';\nimport { isHostTextInput } from '../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../helpers/pointer-events';\nimport { getTextInputValue, isEditableTextInput } from '../helpers/text-input';\nimport { nativeState } from '../native-state';\nimport type { UserEventInstance } from './setup';\nimport { dispatchEvent, getTextContentSize, wait } from './utils';\n\nexport async function paste(\n this: UserEventInstance,\n instance: TestInstance,\n text: string,\n): Promise<void> {\n if (!isHostTextInput(instance)) {\n throw new ErrorWithStack(\n `paste() only supports host \"TextInput\" instances. Passed instance has type: \"${instance.type}\".`,\n paste,\n );\n }\n\n if (!isEditableTextInput(instance) || !isPointerEventEnabled(instance)) {\n return;\n }\n\n // 1. Enter instance\n await dispatchEvent(instance, 'focus', buildFocusEvent());\n\n // 2. Select all\n const textToClear = getTextInputValue(instance);\n const rangeToClear = { start: 0, end: textToClear.length };\n await dispatchEvent(instance, 'selectionChange', buildTextSelectionChangeEvent(rangeToClear));\n\n // 3. Paste the text\n nativeState.valueForInstance.set(instance, text);\n await dispatchEvent(instance, 'change', buildTextChangeEvent(text));\n await dispatchEvent(instance, 'changeText', text);\n\n const rangeAfter = { start: text.length, end: text.length };\n await dispatchEvent(instance, 'selectionChange', buildTextSelectionChangeEvent(rangeAfter));\n\n // According to the docs only multiline TextInput emits contentSizeChange event\n // @see: https://reactnative.dev/docs/textinput#oncontentsizechange\n const isMultiline = instance.props.multiline === true;\n if (isMultiline) {\n const contentSize = getTextContentSize(text);\n await dispatchEvent(instance, 'contentSizeChange', buildContentSizeChangeEvent(contentSize));\n }\n\n // 4. Exit instance\n await wait(this.config);\n await dispatchEvent(instance, 'endEditing', buildEndEditingEvent(text));\n await dispatchEvent(instance, 'blur', buildBlurEvent());\n}\n"],"mappings":";;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAEO,eAAeO,KAAKA,CAEzBC,QAAsB,EACtBC,IAAY,EACG;EACf,IAAI,CAAC,IAAAC,mCAAe,EAACF,QAAQ,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACtB,gFAAgFH,QAAQ,CAACI,IAAI,IAAI,EACjGL,KACF,CAAC;EACH;EAEA,IAAI,CAAC,IAAAM,8BAAmB,EAACL,QAAQ,CAAC,IAAI,CAAC,IAAAM,oCAAqB,EAACN,QAAQ,CAAC,EAAE;IACtE;EACF;;EAEA;EACA,MAAM,IAAAO,oBAAa,EAACP,QAAQ,EAAE,OAAO,EAAE,IAAAQ,6BAAe,EAAC,CAAC,CAAC;;EAEzD;EACA,MAAMC,WAAW,GAAG,IAAAC,4BAAiB,EAACV,QAAQ,CAAC;EAC/C,MAAMW,YAAY,GAAG;IAAEC,KAAK,EAAE,CAAC;IAAEC,GAAG,EAAEJ,WAAW,CAACK;EAAO,CAAC;EAC1D,MAAM,IAAAP,oBAAa,EAACP,QAAQ,EAAE,iBAAiB,EAAE,IAAAe,2CAA6B,EAACJ,YAAY,CAAC,CAAC;;EAE7F;EACAK,wBAAW,CAACC,gBAAgB,CAACC,GAAG,CAAClB,QAAQ,EAAEC,IAAI,CAAC;EAChD,MAAM,IAAAM,oBAAa,EAACP,QAAQ,EAAE,QAAQ,EAAE,IAAAmB,kCAAoB,EAAClB,IAAI,CAAC,CAAC;EACnE,MAAM,IAAAM,oBAAa,EAACP,QAAQ,EAAE,YAAY,EAAEC,IAAI,CAAC;EAEjD,MAAMmB,UAAU,GAAG;IAAER,KAAK,EAAEX,IAAI,CAACa,MAAM;IAAED,GAAG,EAAEZ,IAAI,CAACa;EAAO,CAAC;EAC3D,MAAM,IAAAP,oBAAa,EAACP,QAAQ,EAAE,iBAAiB,EAAE,IAAAe,2CAA6B,EAACK,UAAU,CAAC,CAAC;;EAE3F;EACA;EACA,MAAMC,WAAW,GAAGrB,QAAQ,CAACsB,KAAK,CAACC,SAAS,KAAK,IAAI;EACrD,IAAIF,WAAW,EAAE;IACf,MAAMG,WAAW,GAAG,IAAAC,yBAAkB,EAACxB,IAAI,CAAC;IAC5C,MAAM,IAAAM,oBAAa,EAACP,QAAQ,EAAE,mBAAmB,EAAE,IAAA0B,yCAA2B,EAACF,WAAW,CAAC,CAAC;EAC9F;;EAEA;EACA,MAAM,IAAAG,WAAI,EAAC,IAAI,CAACC,MAAM,CAAC;EACvB,MAAM,IAAArB,oBAAa,EAACP,QAAQ,EAAE,YAAY,EAAE,IAAA6B,kCAAoB,EAAC5B,IAAI,CAAC,CAAC;EACvE,MAAM,IAAAM,oBAAa,EAACP,QAAQ,EAAE,MAAM,EAAE,IAAA8B,4BAAc,EAAC,CAAC,CAAC;AACzD","ignoreList":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { UserEventInstance } from '../setup';
|
|
3
3
|
export declare const DEFAULT_MIN_PRESS_DURATION = 130;
|
|
4
4
|
export declare const DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
5
5
|
export interface PressOptions {
|
|
6
6
|
duration?: number;
|
|
7
7
|
}
|
|
8
|
-
export declare function press(this: UserEventInstance,
|
|
9
|
-
export declare function longPress(this: UserEventInstance,
|
|
8
|
+
export declare function press(this: UserEventInstance, instance: TestInstance): Promise<void>;
|
|
9
|
+
export declare function longPress(this: UserEventInstance, instance: TestInstance, options?: PressOptions): Promise<void>;
|
|
@@ -7,95 +7,95 @@ exports.DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_LONG_PRESS_DELAY_MS = void
|
|
|
7
7
|
exports.longPress = longPress;
|
|
8
8
|
exports.press = press;
|
|
9
9
|
var _act = require("../../act");
|
|
10
|
+
var _eventBuilder = require("../../event-builder");
|
|
10
11
|
var _eventHandler = require("../../event-handler");
|
|
11
12
|
var _componentTree = require("../../helpers/component-tree");
|
|
12
13
|
var _errors = require("../../helpers/errors");
|
|
13
14
|
var _hostComponentNames = require("../../helpers/host-component-names");
|
|
14
15
|
var _pointerEvents = require("../../helpers/pointer-events");
|
|
15
|
-
var _eventBuilder = require("../event-builder");
|
|
16
16
|
var _utils = require("../utils");
|
|
17
17
|
// These are constants defined in the React Native repo
|
|
18
18
|
// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264
|
|
19
19
|
const DEFAULT_MIN_PRESS_DURATION = exports.DEFAULT_MIN_PRESS_DURATION = 130;
|
|
20
20
|
const DEFAULT_LONG_PRESS_DELAY_MS = exports.DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
|
21
|
-
async function press(
|
|
22
|
-
if (!(0, _componentTree.
|
|
23
|
-
throw new _errors.ErrorWithStack(`press() works only with host
|
|
21
|
+
async function press(instance) {
|
|
22
|
+
if (!(0, _componentTree.isTestInstance)(instance)) {
|
|
23
|
+
throw new _errors.ErrorWithStack(`press() works only with host instances.`, press);
|
|
24
24
|
}
|
|
25
|
-
await basePress(this.config,
|
|
25
|
+
await basePress(this.config, instance, {
|
|
26
26
|
type: 'press'
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
async function longPress(
|
|
30
|
-
if (!(0, _componentTree.
|
|
31
|
-
throw new _errors.ErrorWithStack(`longPress() works only with host
|
|
29
|
+
async function longPress(instance, options) {
|
|
30
|
+
if (!(0, _componentTree.isTestInstance)(instance)) {
|
|
31
|
+
throw new _errors.ErrorWithStack(`longPress() works only with host instances.`, longPress);
|
|
32
32
|
}
|
|
33
|
-
await basePress(this.config,
|
|
33
|
+
await basePress(this.config, instance, {
|
|
34
34
|
type: 'longPress',
|
|
35
35
|
duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
const basePress = async (config,
|
|
39
|
-
if (isEnabledHostElement(
|
|
40
|
-
await emitDirectPressEvents(config,
|
|
38
|
+
const basePress = async (config, instance, options) => {
|
|
39
|
+
if (isEnabledHostElement(instance) && hasPressEventHandler(instance)) {
|
|
40
|
+
await emitDirectPressEvents(config, instance, options);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
if (isEnabledTouchResponder(
|
|
44
|
-
await emitPressabilityPressEvents(config,
|
|
43
|
+
if (isEnabledTouchResponder(instance)) {
|
|
44
|
+
await emitPressabilityPressEvents(config, instance, options);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
if (!
|
|
47
|
+
if (!instance.parent) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
await basePress(config,
|
|
50
|
+
await basePress(config, instance.parent, options);
|
|
51
51
|
};
|
|
52
|
-
function isEnabledHostElement(
|
|
53
|
-
if (!(0, _pointerEvents.isPointerEventEnabled)(
|
|
52
|
+
function isEnabledHostElement(instance) {
|
|
53
|
+
if (!(0, _pointerEvents.isPointerEventEnabled)(instance)) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
-
if ((0, _hostComponentNames.isHostText)(
|
|
57
|
-
return
|
|
56
|
+
if ((0, _hostComponentNames.isHostText)(instance)) {
|
|
57
|
+
return instance.props.disabled !== true;
|
|
58
58
|
}
|
|
59
|
-
if ((0, _hostComponentNames.isHostTextInput)(
|
|
60
|
-
return
|
|
59
|
+
if ((0, _hostComponentNames.isHostTextInput)(instance)) {
|
|
60
|
+
return instance.props.editable !== false;
|
|
61
61
|
}
|
|
62
62
|
return true;
|
|
63
63
|
}
|
|
64
|
-
function isEnabledTouchResponder(
|
|
65
|
-
return (0, _pointerEvents.isPointerEventEnabled)(
|
|
64
|
+
function isEnabledTouchResponder(instance) {
|
|
65
|
+
return (0, _pointerEvents.isPointerEventEnabled)(instance) && instance.props.onStartShouldSetResponder?.();
|
|
66
66
|
}
|
|
67
|
-
function hasPressEventHandler(
|
|
68
|
-
return (0, _eventHandler.getEventHandlerFromProps)(
|
|
67
|
+
function hasPressEventHandler(instance) {
|
|
68
|
+
return (0, _eventHandler.getEventHandlerFromProps)(instance.props, 'press') || (0, _eventHandler.getEventHandlerFromProps)(instance.props, 'longPress') || (0, _eventHandler.getEventHandlerFromProps)(instance.props, 'pressIn') || (0, _eventHandler.getEventHandlerFromProps)(instance.props, 'pressOut');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* Dispatches a press event sequence for host
|
|
72
|
+
* Dispatches a press event sequence for host instances that have `onPress*` event handlers.
|
|
73
73
|
*/
|
|
74
|
-
async function emitDirectPressEvents(config,
|
|
74
|
+
async function emitDirectPressEvents(config, instance, options) {
|
|
75
75
|
await (0, _utils.wait)(config);
|
|
76
|
-
await (0, _utils.dispatchEvent)(
|
|
76
|
+
await (0, _utils.dispatchEvent)(instance, 'pressIn', (0, _eventBuilder.buildTouchEvent)());
|
|
77
77
|
await (0, _utils.wait)(config, options.duration);
|
|
78
78
|
|
|
79
79
|
// Long press events are emitted before `pressOut`.
|
|
80
80
|
if (options.type === 'longPress') {
|
|
81
|
-
await (0, _utils.dispatchEvent)(
|
|
81
|
+
await (0, _utils.dispatchEvent)(instance, 'longPress', (0, _eventBuilder.buildTouchEvent)());
|
|
82
82
|
}
|
|
83
|
-
await (0, _utils.dispatchEvent)(
|
|
83
|
+
await (0, _utils.dispatchEvent)(instance, 'pressOut', (0, _eventBuilder.buildTouchEvent)());
|
|
84
84
|
|
|
85
85
|
// Regular press events are emitted after `pressOut` according to the React Native docs.
|
|
86
86
|
// See: https://reactnative.dev/docs/pressable#onpress
|
|
87
87
|
// Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but
|
|
88
88
|
// we will ignore that as in reality most pressed would be above the 130ms threshold.
|
|
89
89
|
if (options.type === 'press') {
|
|
90
|
-
await (0, _utils.dispatchEvent)(
|
|
90
|
+
await (0, _utils.dispatchEvent)(instance, 'press', (0, _eventBuilder.buildTouchEvent)());
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
async function emitPressabilityPressEvents(config,
|
|
93
|
+
async function emitPressabilityPressEvents(config, instance, options) {
|
|
94
94
|
await (0, _utils.wait)(config);
|
|
95
|
-
await (0, _utils.dispatchEvent)(
|
|
95
|
+
await (0, _utils.dispatchEvent)(instance, 'responderGrant', (0, _eventBuilder.buildResponderGrantEvent)());
|
|
96
96
|
const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;
|
|
97
97
|
await (0, _utils.wait)(config, duration);
|
|
98
|
-
await (0, _utils.dispatchEvent)(
|
|
98
|
+
await (0, _utils.dispatchEvent)(instance, 'responderRelease', (0, _eventBuilder.buildResponderReleaseEvent)());
|
|
99
99
|
|
|
100
100
|
// React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION
|
|
101
101
|
// before emitting the `pressOut` event. We need to wait here, so that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.js","names":["_act","require","_eventHandler","_componentTree","_errors","_hostComponentNames","_pointerEvents","
|
|
1
|
+
{"version":3,"file":"press.js","names":["_act","require","_eventBuilder","_eventHandler","_componentTree","_errors","_hostComponentNames","_pointerEvents","_utils","DEFAULT_MIN_PRESS_DURATION","exports","DEFAULT_LONG_PRESS_DELAY_MS","press","instance","isTestInstance","ErrorWithStack","basePress","config","type","longPress","options","duration","isEnabledHostElement","hasPressEventHandler","emitDirectPressEvents","isEnabledTouchResponder","emitPressabilityPressEvents","parent","isPointerEventEnabled","isHostText","props","disabled","isHostTextInput","editable","onStartShouldSetResponder","getEventHandlerFromProps","wait","dispatchEvent","buildTouchEvent","buildResponderGrantEvent","buildResponderReleaseEvent","act"],"sources":["../../../src/user-event/press/press.ts"],"sourcesContent":["import type { TestInstance } from 'test-renderer';\n\nimport { act } from '../../act';\nimport {\n buildResponderGrantEvent,\n buildResponderReleaseEvent,\n buildTouchEvent,\n} from '../../event-builder';\nimport { getEventHandlerFromProps } from '../../event-handler';\nimport { isTestInstance } from '../../helpers/component-tree';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostText, isHostTextInput } from '../../helpers/host-component-names';\nimport { isPointerEventEnabled } from '../../helpers/pointer-events';\nimport type { UserEventConfig, UserEventInstance } from '../setup';\nimport { dispatchEvent, wait } from '../utils';\n\n// These are constants defined in the React Native repo\n// See: https://github.com/facebook/react-native/blob/50e38cc9f1e6713228a91ad50f426c4f65e65e1a/packages/react-native/Libraries/Pressability/Pressability.js#L264\nexport const DEFAULT_MIN_PRESS_DURATION = 130;\nexport const DEFAULT_LONG_PRESS_DELAY_MS = 500;\n\nexport interface PressOptions {\n duration?: number;\n}\n\nexport async function press(this: UserEventInstance, instance: TestInstance): Promise<void> {\n if (!isTestInstance(instance)) {\n throw new ErrorWithStack(`press() works only with host instances.`, press);\n }\n\n await basePress(this.config, instance, {\n type: 'press',\n });\n}\n\nexport async function longPress(\n this: UserEventInstance,\n instance: TestInstance,\n options?: PressOptions,\n): Promise<void> {\n if (!isTestInstance(instance)) {\n throw new ErrorWithStack(`longPress() works only with host instances.`, longPress);\n }\n\n await basePress(this.config, instance, {\n type: 'longPress',\n duration: options?.duration ?? DEFAULT_LONG_PRESS_DELAY_MS,\n });\n}\n\ninterface BasePressOptions {\n type: 'press' | 'longPress';\n duration?: number;\n}\n\nconst basePress = async (\n config: UserEventConfig,\n instance: TestInstance,\n options: BasePressOptions,\n): Promise<void> => {\n if (isEnabledHostElement(instance) && hasPressEventHandler(instance)) {\n await emitDirectPressEvents(config, instance, options);\n return;\n }\n\n if (isEnabledTouchResponder(instance)) {\n await emitPressabilityPressEvents(config, instance, options);\n return;\n }\n\n if (!instance.parent) {\n return;\n }\n\n await basePress(config, instance.parent, options);\n};\n\nfunction isEnabledHostElement(instance: TestInstance) {\n if (!isPointerEventEnabled(instance)) {\n return false;\n }\n\n if (isHostText(instance)) {\n return instance.props.disabled !== true;\n }\n\n if (isHostTextInput(instance)) {\n return instance.props.editable !== false;\n }\n\n return true;\n}\n\nfunction isEnabledTouchResponder(instance: TestInstance) {\n return isPointerEventEnabled(instance) && instance.props.onStartShouldSetResponder?.();\n}\n\nfunction hasPressEventHandler(instance: TestInstance) {\n return (\n getEventHandlerFromProps(instance.props, 'press') ||\n getEventHandlerFromProps(instance.props, 'longPress') ||\n getEventHandlerFromProps(instance.props, 'pressIn') ||\n getEventHandlerFromProps(instance.props, 'pressOut')\n );\n}\n\n/**\n * Dispatches a press event sequence for host instances that have `onPress*` event handlers.\n */\nasync function emitDirectPressEvents(\n config: UserEventConfig,\n instance: TestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n await dispatchEvent(instance, 'pressIn', buildTouchEvent());\n\n await wait(config, options.duration);\n\n // Long press events are emitted before `pressOut`.\n if (options.type === 'longPress') {\n await dispatchEvent(instance, 'longPress', buildTouchEvent());\n }\n\n await dispatchEvent(instance, 'pressOut', buildTouchEvent());\n\n // Regular press events are emitted after `pressOut` according to the React Native docs.\n // See: https://reactnative.dev/docs/pressable#onpress\n // Experimentally for very short presses (< 130ms) `press` events are actually emitted before `onPressOut`, but\n // we will ignore that as in reality most pressed would be above the 130ms threshold.\n if (options.type === 'press') {\n await dispatchEvent(instance, 'press', buildTouchEvent());\n }\n}\n\nasync function emitPressabilityPressEvents(\n config: UserEventConfig,\n instance: TestInstance,\n options: BasePressOptions,\n) {\n await wait(config);\n\n await dispatchEvent(instance, 'responderGrant', buildResponderGrantEvent());\n\n const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;\n await wait(config, duration);\n\n await dispatchEvent(instance, 'responderRelease', buildResponderReleaseEvent());\n\n // React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION\n // before emitting the `pressOut` event. We need to wait here, so that\n // `press()` function does not return before that.\n if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {\n await act(() => wait(config, DEFAULT_MIN_PRESS_DURATION - duration));\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAEA;AACA;AACO,MAAMQ,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,GAAG;AACtC,MAAME,2BAA2B,GAAAD,OAAA,CAAAC,2BAAA,GAAG,GAAG;AAMvC,eAAeC,KAAKA,CAA0BC,QAAsB,EAAiB;EAC1F,IAAI,CAAC,IAAAC,6BAAc,EAACD,QAAQ,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CAAC,yCAAyC,EAAEH,KAAK,CAAC;EAC5E;EAEA,MAAMI,SAAS,CAAC,IAAI,CAACC,MAAM,EAAEJ,QAAQ,EAAE;IACrCK,IAAI,EAAE;EACR,CAAC,CAAC;AACJ;AAEO,eAAeC,SAASA,CAE7BN,QAAsB,EACtBO,OAAsB,EACP;EACf,IAAI,CAAC,IAAAN,6BAAc,EAACD,QAAQ,CAAC,EAAE;IAC7B,MAAM,IAAIE,sBAAc,CAAC,6CAA6C,EAAEI,SAAS,CAAC;EACpF;EAEA,MAAMH,SAAS,CAAC,IAAI,CAACC,MAAM,EAAEJ,QAAQ,EAAE;IACrCK,IAAI,EAAE,WAAW;IACjBG,QAAQ,EAAED,OAAO,EAAEC,QAAQ,IAAIV;EACjC,CAAC,CAAC;AACJ;AAOA,MAAMK,SAAS,GAAG,MAAAA,CAChBC,MAAuB,EACvBJ,QAAsB,EACtBO,OAAyB,KACP;EAClB,IAAIE,oBAAoB,CAACT,QAAQ,CAAC,IAAIU,oBAAoB,CAACV,QAAQ,CAAC,EAAE;IACpE,MAAMW,qBAAqB,CAACP,MAAM,EAAEJ,QAAQ,EAAEO,OAAO,CAAC;IACtD;EACF;EAEA,IAAIK,uBAAuB,CAACZ,QAAQ,CAAC,EAAE;IACrC,MAAMa,2BAA2B,CAACT,MAAM,EAAEJ,QAAQ,EAAEO,OAAO,CAAC;IAC5D;EACF;EAEA,IAAI,CAACP,QAAQ,CAACc,MAAM,EAAE;IACpB;EACF;EAEA,MAAMX,SAAS,CAACC,MAAM,EAAEJ,QAAQ,CAACc,MAAM,EAAEP,OAAO,CAAC;AACnD,CAAC;AAED,SAASE,oBAAoBA,CAACT,QAAsB,EAAE;EACpD,IAAI,CAAC,IAAAe,oCAAqB,EAACf,QAAQ,CAAC,EAAE;IACpC,OAAO,KAAK;EACd;EAEA,IAAI,IAAAgB,8BAAU,EAAChB,QAAQ,CAAC,EAAE;IACxB,OAAOA,QAAQ,CAACiB,KAAK,CAACC,QAAQ,KAAK,IAAI;EACzC;EAEA,IAAI,IAAAC,mCAAe,EAACnB,QAAQ,CAAC,EAAE;IAC7B,OAAOA,QAAQ,CAACiB,KAAK,CAACG,QAAQ,KAAK,KAAK;EAC1C;EAEA,OAAO,IAAI;AACb;AAEA,SAASR,uBAAuBA,CAACZ,QAAsB,EAAE;EACvD,OAAO,IAAAe,oCAAqB,EAACf,QAAQ,CAAC,IAAIA,QAAQ,CAACiB,KAAK,CAACI,yBAAyB,GAAG,CAAC;AACxF;AAEA,SAASX,oBAAoBA,CAACV,QAAsB,EAAE;EACpD,OACE,IAAAsB,sCAAwB,EAACtB,QAAQ,CAACiB,KAAK,EAAE,OAAO,CAAC,IACjD,IAAAK,sCAAwB,EAACtB,QAAQ,CAACiB,KAAK,EAAE,WAAW,CAAC,IACrD,IAAAK,sCAAwB,EAACtB,QAAQ,CAACiB,KAAK,EAAE,SAAS,CAAC,IACnD,IAAAK,sCAAwB,EAACtB,QAAQ,CAACiB,KAAK,EAAE,UAAU,CAAC;AAExD;;AAEA;AACA;AACA;AACA,eAAeN,qBAAqBA,CAClCP,MAAuB,EACvBJ,QAAsB,EACtBO,OAAyB,EACzB;EACA,MAAM,IAAAgB,WAAI,EAACnB,MAAM,CAAC;EAClB,MAAM,IAAAoB,oBAAa,EAACxB,QAAQ,EAAE,SAAS,EAAE,IAAAyB,6BAAe,EAAC,CAAC,CAAC;EAE3D,MAAM,IAAAF,WAAI,EAACnB,MAAM,EAAEG,OAAO,CAACC,QAAQ,CAAC;;EAEpC;EACA,IAAID,OAAO,CAACF,IAAI,KAAK,WAAW,EAAE;IAChC,MAAM,IAAAmB,oBAAa,EAACxB,QAAQ,EAAE,WAAW,EAAE,IAAAyB,6BAAe,EAAC,CAAC,CAAC;EAC/D;EAEA,MAAM,IAAAD,oBAAa,EAACxB,QAAQ,EAAE,UAAU,EAAE,IAAAyB,6BAAe,EAAC,CAAC,CAAC;;EAE5D;EACA;EACA;EACA;EACA,IAAIlB,OAAO,CAACF,IAAI,KAAK,OAAO,EAAE;IAC5B,MAAM,IAAAmB,oBAAa,EAACxB,QAAQ,EAAE,OAAO,EAAE,IAAAyB,6BAAe,EAAC,CAAC,CAAC;EAC3D;AACF;AAEA,eAAeZ,2BAA2BA,CACxCT,MAAuB,EACvBJ,QAAsB,EACtBO,OAAyB,EACzB;EACA,MAAM,IAAAgB,WAAI,EAACnB,MAAM,CAAC;EAElB,MAAM,IAAAoB,oBAAa,EAACxB,QAAQ,EAAE,gBAAgB,EAAE,IAAA0B,sCAAwB,EAAC,CAAC,CAAC;EAE3E,MAAMlB,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAIZ,0BAA0B;EAC/D,MAAM,IAAA2B,WAAI,EAACnB,MAAM,EAAEI,QAAQ,CAAC;EAE5B,MAAM,IAAAgB,oBAAa,EAACxB,QAAQ,EAAE,kBAAkB,EAAE,IAAA2B,wCAA0B,EAAC,CAAC,CAAC;;EAE/E;EACA;EACA;EACA,IAAI/B,0BAA0B,GAAGY,QAAQ,GAAG,CAAC,EAAE;IAC7C,MAAM,IAAAoB,QAAG,EAAC,MAAM,IAAAL,WAAI,EAACnB,MAAM,EAAER,0BAA0B,GAAGY,QAAQ,CAAC,CAAC;EACtE;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TestInstance } from 'test-renderer';
|
|
2
2
|
import type { Size } from '../../types';
|
|
3
3
|
import type { UserEventInstance } from '../setup';
|
|
4
4
|
interface CommonScrollToOptions {
|
|
@@ -18,5 +18,5 @@ export interface HorizontalScrollToOptions extends CommonScrollToOptions {
|
|
|
18
18
|
momentumY?: never;
|
|
19
19
|
}
|
|
20
20
|
export type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;
|
|
21
|
-
export declare function scrollTo(this: UserEventInstance,
|
|
21
|
+
export declare function scrollTo(this: UserEventInstance, instance: TestInstance, options: ScrollToOptions): Promise<void>;
|
|
22
22
|
export {};
|
|
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.scrollTo = scrollTo;
|
|
7
7
|
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
8
|
+
var _eventBuilder = require("../../event-builder");
|
|
8
9
|
var _errors = require("../../helpers/errors");
|
|
9
10
|
var _hostComponentNames = require("../../helpers/host-component-names");
|
|
10
11
|
var _object = require("../../helpers/object");
|
|
11
12
|
var _nativeState = require("../../native-state");
|
|
12
|
-
var _eventBuilder = require("../event-builder");
|
|
13
13
|
var _utils = require("../utils");
|
|
14
14
|
var _utils2 = require("./utils");
|
|
15
|
-
async function scrollTo(
|
|
16
|
-
if (!(0, _hostComponentNames.isHostScrollView)(
|
|
17
|
-
throw new _errors.ErrorWithStack(`scrollTo() works only with host "ScrollView"
|
|
15
|
+
async function scrollTo(instance, options) {
|
|
16
|
+
if (!(0, _hostComponentNames.isHostScrollView)(instance)) {
|
|
17
|
+
throw new _errors.ErrorWithStack(`scrollTo() works only with host "ScrollView" instances. Passed instance has type "${instance.type}".`, scrollTo);
|
|
18
18
|
}
|
|
19
|
-
ensureScrollViewDirection(
|
|
20
|
-
await (0, _utils.dispatchEvent)(
|
|
21
|
-
const initialOffset = _nativeState.nativeState.
|
|
19
|
+
ensureScrollViewDirection(instance, options);
|
|
20
|
+
await (0, _utils.dispatchEvent)(instance, 'contentSizeChange', options.contentSize?.width ?? 0, options.contentSize?.height ?? 0);
|
|
21
|
+
const initialOffset = _nativeState.nativeState.contentOffsetForInstance.get(instance) ?? {
|
|
22
22
|
x: 0,
|
|
23
23
|
y: 0
|
|
24
24
|
};
|
|
@@ -26,54 +26,54 @@ async function scrollTo(element, options) {
|
|
|
26
26
|
y: options.y,
|
|
27
27
|
x: options.x
|
|
28
28
|
}, initialOffset, _utils2.linearInterpolator);
|
|
29
|
-
await emitDragScrollEvents(this.config,
|
|
29
|
+
await emitDragScrollEvents(this.config, instance, dragSteps, options);
|
|
30
30
|
const momentumStart = dragSteps.at(-1) ?? initialOffset;
|
|
31
31
|
const momentumSteps = (0, _utils2.createScrollSteps)({
|
|
32
32
|
y: options.momentumY,
|
|
33
33
|
x: options.momentumX
|
|
34
34
|
}, momentumStart, _utils2.inertialInterpolator);
|
|
35
|
-
await emitMomentumScrollEvents(this.config,
|
|
35
|
+
await emitMomentumScrollEvents(this.config, instance, momentumSteps, options);
|
|
36
36
|
const finalOffset = momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialOffset;
|
|
37
|
-
_nativeState.nativeState.
|
|
37
|
+
_nativeState.nativeState.contentOffsetForInstance.set(instance, finalOffset);
|
|
38
38
|
}
|
|
39
|
-
async function emitDragScrollEvents(config,
|
|
39
|
+
async function emitDragScrollEvents(config, instance, scrollSteps, scrollOptions) {
|
|
40
40
|
if (scrollSteps.length === 0) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
await (0, _utils.wait)(config);
|
|
44
|
-
await (0, _utils.dispatchEvent)(
|
|
44
|
+
await (0, _utils.dispatchEvent)(instance, 'scrollBeginDrag', (0, _eventBuilder.buildScrollEvent)(scrollSteps[0], scrollOptions));
|
|
45
45
|
|
|
46
46
|
// Note: experimentally, in case of drag scroll the last scroll step
|
|
47
47
|
// will not trigger `scroll` event.
|
|
48
48
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
49
49
|
for (let i = 1; i < scrollSteps.length - 1; i += 1) {
|
|
50
50
|
await (0, _utils.wait)(config);
|
|
51
|
-
await (0, _utils.dispatchEvent)(
|
|
51
|
+
await (0, _utils.dispatchEvent)(instance, 'scroll', (0, _eventBuilder.buildScrollEvent)(scrollSteps[i], scrollOptions));
|
|
52
52
|
}
|
|
53
53
|
await (0, _utils.wait)(config);
|
|
54
54
|
const lastStep = scrollSteps.at(-1);
|
|
55
|
-
await (0, _utils.dispatchEvent)(
|
|
55
|
+
await (0, _utils.dispatchEvent)(instance, 'scrollEndDrag', (0, _eventBuilder.buildScrollEvent)(lastStep, scrollOptions));
|
|
56
56
|
}
|
|
57
|
-
async function emitMomentumScrollEvents(config,
|
|
57
|
+
async function emitMomentumScrollEvents(config, instance, scrollSteps, scrollOptions) {
|
|
58
58
|
if (scrollSteps.length === 0) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
await (0, _utils.wait)(config);
|
|
62
|
-
await (0, _utils.dispatchEvent)(
|
|
62
|
+
await (0, _utils.dispatchEvent)(instance, 'momentumScrollBegin', (0, _eventBuilder.buildScrollEvent)(scrollSteps[0], scrollOptions));
|
|
63
63
|
|
|
64
64
|
// Note: experimentally, in case of momentum scroll the last scroll step
|
|
65
65
|
// will trigger `scroll` event.
|
|
66
66
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
67
67
|
for (let i = 1; i < scrollSteps.length; i += 1) {
|
|
68
68
|
await (0, _utils.wait)(config);
|
|
69
|
-
await (0, _utils.dispatchEvent)(
|
|
69
|
+
await (0, _utils.dispatchEvent)(instance, 'scroll', (0, _eventBuilder.buildScrollEvent)(scrollSteps[i], scrollOptions));
|
|
70
70
|
}
|
|
71
71
|
await (0, _utils.wait)(config);
|
|
72
72
|
const lastStep = scrollSteps.at(-1);
|
|
73
|
-
await (0, _utils.dispatchEvent)(
|
|
73
|
+
await (0, _utils.dispatchEvent)(instance, 'momentumScrollEnd', (0, _eventBuilder.buildScrollEvent)(lastStep, scrollOptions));
|
|
74
74
|
}
|
|
75
|
-
function ensureScrollViewDirection(
|
|
76
|
-
const isVerticalScrollView =
|
|
75
|
+
function ensureScrollViewDirection(instance, options) {
|
|
76
|
+
const isVerticalScrollView = instance.props.horizontal !== true;
|
|
77
77
|
const hasHorizontalScrollOptions = options.x !== undefined || options.momentumX !== undefined;
|
|
78
78
|
if (isVerticalScrollView && hasHorizontalScrollOptions) {
|
|
79
79
|
throw new _errors.ErrorWithStack(`scrollTo() expected only vertical scroll options: "y" and "momentumY" for vertical "ScrollView" element but received ${(0, _jestMatcherUtils.stringify)((0, _object.pick)(options, ['x', 'momentumX']))}`, scrollTo);
|