@testing-library/react-native 13.2.0 → 14.0.0-alpha.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/build/act.d.ts +5 -4
- package/build/act.js +3 -6
- package/build/act.js.map +1 -1
- package/build/config.d.ts +0 -10
- package/build/config.js +1 -2
- package/build/config.js.map +1 -1
- package/build/event-handler.d.ts +2 -2
- package/build/event-handler.js.map +1 -1
- package/build/fire-event.d.ts +7 -7
- package/build/fire-event.js +26 -4
- package/build/fire-event.js.map +1 -1
- package/build/helpers/accessibility.d.ts +14 -14
- package/build/helpers/accessibility.js +2 -2
- package/build/helpers/accessibility.js.map +1 -1
- package/build/helpers/component-tree.d.ts +7 -31
- package/build/helpers/component-tree.js +15 -73
- package/build/helpers/component-tree.js.map +1 -1
- package/build/helpers/debug.d.ts +2 -2
- package/build/helpers/debug.js +5 -4
- package/build/helpers/debug.js.map +1 -1
- package/build/helpers/find-all.d.ts +2 -3
- package/build/helpers/find-all.js +5 -5
- package/build/helpers/find-all.js.map +1 -1
- package/build/helpers/format-element.d.ts +4 -4
- package/build/helpers/format-element.js +6 -7
- package/build/helpers/format-element.js.map +1 -1
- package/build/helpers/host-component-names.d.ts +8 -8
- package/build/helpers/host-component-names.js +9 -7
- 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.map +1 -1
- package/build/helpers/matchers/match-accessibility-value.d.ts +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.map +1 -1
- package/build/helpers/matchers/match-text-content.d.ts +2 -2
- 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 +1 -2
- package/build/helpers/pointer-events.js.map +1 -1
- package/build/helpers/text-content.d.ts +2 -2
- package/build/helpers/text-content.js.map +1 -1
- package/build/helpers/text-input.d.ts +3 -3
- package/build/helpers/text-input.js.map +1 -1
- package/build/helpers/wrap-async.d.ts +1 -0
- package/build/helpers/wrap-async.js +1 -0
- package/build/helpers/wrap-async.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.flow.js +0 -1
- package/build/index.js +11 -1
- package/build/index.js.map +1 -1
- package/build/matchers/to-be-busy.d.ts +2 -2
- 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.map +1 -1
- package/build/matchers/to-be-disabled.d.ts +3 -3
- package/build/matchers/to-be-disabled.js +1 -2
- 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 +2 -3
- 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.map +1 -1
- package/build/matchers/to-be-on-the-screen.d.ts +2 -2
- package/build/matchers/to-be-on-the-screen.js +1 -1
- 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.map +1 -1
- package/build/matchers/to-be-selected.d.ts +2 -2
- 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 +1 -2
- 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 +2 -1
- 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.map +1 -1
- package/build/matchers/to-have-accessible-name.d.ts +2 -2
- 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.map +1 -1
- package/build/matchers/to-have-prop.d.ts +2 -2
- 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.map +1 -1
- package/build/matchers/to-have-text-content.d.ts +2 -2
- package/build/matchers/to-have-text-content.js.map +1 -1
- package/build/matchers/types.d.ts +2 -2
- package/build/matchers/types.js.map +1 -1
- package/build/matchers/utils.d.ts +3 -3
- package/build/matchers/utils.js +3 -4
- package/build/matchers/utils.js.map +1 -1
- package/build/native-state.d.ts +3 -3
- package/build/native-state.js.map +1 -1
- package/build/pure.d.ts +1 -1
- package/build/pure.js +2 -2
- package/build/pure.js.map +1 -1
- package/build/queries/display-value.d.ts +2 -2
- package/build/queries/display-value.js.map +1 -1
- package/build/queries/hint-text.d.ts +2 -2
- package/build/queries/hint-text.js.map +1 -1
- package/build/queries/label-text.d.ts +2 -2
- package/build/queries/label-text.js.map +1 -1
- package/build/queries/make-queries.d.ts +9 -9
- package/build/queries/make-queries.js.map +1 -1
- package/build/queries/placeholder-text.d.ts +2 -2
- package/build/queries/placeholder-text.js.map +1 -1
- package/build/queries/role.d.ts +2 -2
- package/build/queries/role.js.map +1 -1
- package/build/queries/test-id.d.ts +2 -2
- package/build/queries/test-id.js.map +1 -1
- package/build/queries/text.d.ts +2 -2
- package/build/queries/text.js.map +1 -1
- package/build/render-hook.js +1 -1
- package/build/render-hook.js.map +1 -1
- package/build/render.d.ts +20 -121
- package/build/render.js +27 -67
- package/build/render.js.map +1 -1
- package/build/screen.js +1 -9
- package/build/screen.js.map +1 -1
- package/build/tsconfig.release.tsbuildinfo +1 -1
- package/build/user-event/clear.d.ts +2 -2
- package/build/user-event/clear.js.map +1 -1
- package/build/user-event/index.d.ts +7 -7
- package/build/user-event/index.js.map +1 -1
- package/build/user-event/paste.d.ts +2 -2
- 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 +1 -10
- 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.map +1 -1
- package/build/user-event/setup/setup.d.ts +7 -7
- 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.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +2 -2
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/build/within.d.ts +20 -36
- package/build/within.js +3 -7
- package/build/within.js.map +1 -1
- package/package.json +8 -8
- package/typings/index.flow.js +0 -1
- package/build/helpers/ensure-peer-deps.d.ts +0 -3
- package/build/helpers/ensure-peer-deps.js +0 -32
- package/build/helpers/ensure-peer-deps.js.map +0 -1
- package/build/helpers/string-validation.d.ts +0 -2
- package/build/helpers/string-validation.js +0 -31
- package/build/helpers/string-validation.js.map +0 -1
- package/build/queries/unsafe-props.d.ts +0 -10
- package/build/queries/unsafe-props.js +0 -49
- package/build/queries/unsafe-props.js.map +0 -1
- package/build/queries/unsafe-type.d.ts +0 -10
- package/build/queries/unsafe-type.js +0 -49
- package/build/queries/unsafe-type.js.map +0 -1
- package/build/render-act.d.ts +0 -2
- package/build/render-act.js +0 -22
- package/build/render-act.js.map +0 -1
package/build/act.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
type ReactAct = 0 extends 1 & typeof React.act ? typeof reactTestRendererAct : typeof React.act;
|
|
2
|
+
type ReactAct = typeof React.act;
|
|
4
3
|
declare global {
|
|
5
4
|
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
6
5
|
}
|
|
7
6
|
declare function setIsReactActEnvironment(isReactActEnvironment: boolean | undefined): void;
|
|
8
7
|
declare function getIsReactActEnvironment(): boolean | undefined;
|
|
9
|
-
declare const act: ReactAct
|
|
8
|
+
declare const act: (callback: Parameters<ReactAct>[0]) => Promise<unknown> | {
|
|
9
|
+
then: (resolve: (value: never) => never, reject: (value: never) => never) => void;
|
|
10
|
+
};
|
|
10
11
|
export default act;
|
|
11
|
-
export {
|
|
12
|
+
export { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };
|
package/build/act.js
CHANGED
|
@@ -7,14 +7,11 @@ exports.default = void 0;
|
|
|
7
7
|
exports.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
8
8
|
exports.setReactActEnvironment = setIsReactActEnvironment;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactTestRenderer = require("react-test-renderer");
|
|
11
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
12
|
// This file and the act() implementation is sourced from react-testing-library
|
|
14
13
|
// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/types/index.d.ts
|
|
15
14
|
|
|
16
|
-
const reactAct = typeof React.act === 'function' ? React.act : _reactTestRenderer.act;
|
|
17
|
-
|
|
18
15
|
// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT
|
|
19
16
|
|
|
20
17
|
function setIsReactActEnvironment(isReactActEnvironment) {
|
|
@@ -47,9 +44,11 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
47
44
|
// eslint-disable-next-line promise/always-return
|
|
48
45
|
returnValue => {
|
|
49
46
|
setIsReactActEnvironment(previousActEnvironment);
|
|
47
|
+
// @ts-expect-error too strict typing
|
|
50
48
|
resolve(returnValue);
|
|
51
49
|
}, error => {
|
|
52
50
|
setIsReactActEnvironment(previousActEnvironment);
|
|
51
|
+
// @ts-expect-error too strict typing
|
|
53
52
|
reject(error);
|
|
54
53
|
});
|
|
55
54
|
}
|
|
@@ -66,8 +65,6 @@ function withGlobalActEnvironment(actImplementation) {
|
|
|
66
65
|
}
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
// @ts-expect-error: typings get too complex
|
|
71
|
-
const act = withGlobalActEnvironment(reactAct);
|
|
68
|
+
const act = withGlobalActEnvironment(React.act);
|
|
72
69
|
var _default = exports.default = act;
|
|
73
70
|
//# sourceMappingURL=act.js.map
|
package/build/act.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","
|
|
1
|
+
{"version":3,"file":"act.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","setIsReactActEnvironment","isReactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","getIsReactActEnvironment","withGlobalActEnvironment","actImplementation","callback","previousActEnvironment","callbackNeedsToBeAwaited","actResult","result","then","thenable","resolve","reject","returnValue","error","act","_default","exports"],"sources":["../src/act.ts"],"sourcesContent":["// This file and the act() implementation is sourced from react-testing-library\n// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/types/index.d.ts\nimport * as React from 'react';\n\ntype ReactAct = typeof React.act;\n\n// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT\ndeclare global {\n // eslint-disable-next-line no-var\n var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;\n}\n\nfunction setIsReactActEnvironment(isReactActEnvironment: boolean | undefined) {\n globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;\n}\n\nfunction getIsReactActEnvironment() {\n return globalThis.IS_REACT_ACT_ENVIRONMENT;\n}\n\nfunction withGlobalActEnvironment(actImplementation: ReactAct) {\n return (callback: Parameters<ReactAct>[0]) => {\n const previousActEnvironment = getIsReactActEnvironment();\n setIsReactActEnvironment(true);\n\n try {\n // The return value of `act` is always a thenable.\n let callbackNeedsToBeAwaited = false;\n const actResult = actImplementation(() => {\n const result = callback();\n // @ts-expect-error TS is too strict here\n if (result !== null && typeof result === 'object' && typeof result.then === 'function') {\n callbackNeedsToBeAwaited = true;\n }\n return result;\n });\n\n if (callbackNeedsToBeAwaited) {\n const thenable = actResult;\n return {\n then: (resolve: (value: never) => never, reject: (value: never) => never) => {\n // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then\n thenable.then(\n // eslint-disable-next-line promise/always-return\n (returnValue) => {\n setIsReactActEnvironment(previousActEnvironment);\n // @ts-expect-error too strict typing\n resolve(returnValue);\n },\n (error) => {\n setIsReactActEnvironment(previousActEnvironment);\n // @ts-expect-error too strict typing\n reject(error);\n },\n );\n },\n };\n } else {\n setIsReactActEnvironment(previousActEnvironment);\n return actResult;\n }\n } catch (error) {\n // Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT\n // or if we have to await the callback first.\n setIsReactActEnvironment(previousActEnvironment);\n throw error;\n }\n };\n}\n\nconst act = withGlobalActEnvironment(React.act);\n\nexport default act;\nexport { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA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AAC;IAE9B,IAAI;MACF;MACA,IAAIS,wBAAwB,GAAG,KAAK;MACpC,MAAMC,SAAS,GAAGJ,iBAAiB,CAAC,MAAM;QACxC,MAAMK,MAAM,GAAGJ,QAAQ,CAAC,CAAC;QACzB;QACA,IAAII,MAAM,KAAK,IAAI,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EAAE;UACtFH,wBAAwB,GAAG,IAAI;QACjC;QACA,OAAOE,MAAM;MACf,CAAC,CAAC;MAEF,IAAIF,wBAAwB,EAAE;QAC5B,MAAMI,QAAQ,GAAGH,SAAS;QAC1B,OAAO;UACLE,IAAI,EAAEA,CAACE,OAAgC,EAAEC,MAA+B,KAAK;YAC3E;YACAF,QAAQ,CAACD,IAAI;YACX;YACCI,WAAW,IAAK;cACfhB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChD;cACAM,OAAO,CAACE,WAAW,CAAC;YACtB,CAAC,EACAC,KAAK,IAAK;cACTjB,wBAAwB,CAACQ,sBAAsB,CAAC;cAChD;cACAO,MAAM,CAACE,KAAK,CAAC;YACf,CACF,CAAC;UACH;QACF,CAAC;MACH,CAAC,MAAM;QACLjB,wBAAwB,CAACQ,sBAAsB,CAAC;QAChD,OAAOE,SAAS;MAClB;IACF,CAAC,CAAC,OAAOO,KAAK,EAAE;MACd;MACA;MACAjB,wBAAwB,CAACQ,sBAAsB,CAAC;MAChD,MAAMS,KAAK;IACb;EACF,CAAC;AACH;AAEA,MAAMC,GAAG,GAAGb,wBAAwB,CAAC5B,KAAK,CAACyC,GAAG,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAlC,OAAA,GAEjCgC,GAAG","ignoreList":[]}
|
package/build/config.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ export type Config = {
|
|
|
9
9
|
defaultIncludeHiddenElements: boolean;
|
|
10
10
|
/** Default options for `debug` helper. */
|
|
11
11
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
12
|
-
/**
|
|
13
|
-
* Set to `false` to disable concurrent rendering.
|
|
14
|
-
* Otherwise `render` will default to concurrent rendering.
|
|
15
|
-
*/
|
|
16
|
-
concurrentRoot: boolean;
|
|
17
12
|
};
|
|
18
13
|
export type ConfigAliasOptions = {
|
|
19
14
|
/** RTL-compatibility alias to `defaultIncludeHiddenElements` */
|
|
@@ -31,9 +26,4 @@ export declare function getConfig(): {
|
|
|
31
26
|
defaultIncludeHiddenElements: boolean;
|
|
32
27
|
/** Default options for `debug` helper. */
|
|
33
28
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
34
|
-
/**
|
|
35
|
-
* Set to `false` to disable concurrent rendering.
|
|
36
|
-
* Otherwise `render` will default to concurrent rendering.
|
|
37
|
-
*/
|
|
38
|
-
concurrentRoot: boolean;
|
|
39
29
|
};
|
package/build/config.js
CHANGED
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","
|
|
1
|
+
{"version":3,"file":"config.js","names":["defaultConfig","asyncUtilTimeout","defaultIncludeHiddenElements","config","configure","options","defaultHidden","restOptions","resetToDefaults","getConfig"],"sources":["../src/config.ts"],"sourcesContent":["import type { DebugOptions } from './helpers/debug';\n\n/**\n * Global configuration options for React Native Testing Library.\n */\n\nexport type Config = {\n /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */\n asyncUtilTimeout: number;\n\n /** Default value for `includeHiddenElements` query option. */\n defaultIncludeHiddenElements: boolean;\n\n /** Default options for `debug` helper. */\n defaultDebugOptions?: Partial<DebugOptions>;\n};\n\nexport type ConfigAliasOptions = {\n /** RTL-compatibility alias to `defaultIncludeHiddenElements` */\n defaultHidden: boolean;\n};\n\nconst defaultConfig: Config = {\n asyncUtilTimeout: 1000,\n defaultIncludeHiddenElements: false,\n};\n\nlet config = { ...defaultConfig };\n\n/**\n * Configure global options for React Native Testing Library.\n */\nexport function configure(options: Partial<Config & ConfigAliasOptions>) {\n const { defaultHidden, ...restOptions } = options;\n\n const defaultIncludeHiddenElements =\n restOptions.defaultIncludeHiddenElements ??\n defaultHidden ??\n config.defaultIncludeHiddenElements;\n\n config = {\n ...config,\n ...restOptions,\n defaultIncludeHiddenElements,\n };\n}\n\nexport function resetToDefaults() {\n config = { ...defaultConfig };\n}\n\nexport function getConfig() {\n return config;\n}\n"],"mappings":";;;;;;;;AAEA;AACA;AACA;;AAkBA,MAAMA,aAAqB,GAAG;EAC5BC,gBAAgB,EAAE,IAAI;EACtBC,4BAA4B,EAAE;AAChC,CAAC;AAED,IAAIC,MAAM,GAAG;EAAE,GAAGH;AAAc,CAAC;;AAEjC;AACA;AACA;AACO,SAASI,SAASA,CAACC,OAA6C,EAAE;EACvE,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAY,CAAC,GAAGF,OAAO;EAEjD,MAAMH,4BAA4B,GAChCK,WAAW,CAACL,4BAA4B,IACxCI,aAAa,IACbH,MAAM,CAACD,4BAA4B;EAErCC,MAAM,GAAG;IACP,GAAGA,MAAM;IACT,GAAGI,WAAW;IACdL;EACF,CAAC;AACH;AAEO,SAASM,eAAeA,CAAA,EAAG;EAChCL,MAAM,GAAG;IAAE,GAAGH;EAAc,CAAC;AAC/B;AAEO,SAASS,SAASA,CAAA,EAAG;EAC1B,OAAON,MAAM;AACf","ignoreList":[]}
|
package/build/event-handler.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
2
2
|
export type EventHandlerOptions = {
|
|
3
3
|
/** Include check for event handler named without adding `on*` prefix. */
|
|
4
4
|
loose?: boolean;
|
|
5
5
|
};
|
|
6
|
-
export declare function getEventHandler(element:
|
|
6
|
+
export declare function getEventHandler(element: HostElement, eventName: string, options?: EventHandlerOptions): any;
|
|
7
7
|
export declare function getEventHandlerName(eventName: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.js","names":["getEventHandler","element","eventName","options","handlerName","getEventHandlerName","props","loose","undefined","capitalizeFirstLetter","str","charAt","toUpperCase","slice"],"sources":["../src/event-handler.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"event-handler.js","names":["getEventHandler","element","eventName","options","handlerName","getEventHandlerName","props","loose","undefined","capitalizeFirstLetter","str","charAt","toUpperCase","slice"],"sources":["../src/event-handler.ts"],"sourcesContent":["import type { HostElement } from 'universal-test-renderer';\n\nexport type EventHandlerOptions = {\n /** Include check for event handler named without adding `on*` prefix. */\n loose?: boolean;\n};\n\nexport function getEventHandler(\n element: HostElement,\n eventName: string,\n options?: EventHandlerOptions,\n) {\n const handlerName = getEventHandlerName(eventName);\n if (typeof element.props[handlerName] === 'function') {\n return element.props[handlerName];\n }\n\n if (options?.loose && typeof element.props[eventName] === 'function') {\n return element.props[eventName];\n }\n\n if (typeof element.props[`testOnly_${handlerName}`] === 'function') {\n return element.props[`testOnly_${handlerName}`];\n }\n\n if (options?.loose && typeof element.props[`testOnly_${eventName}`] === 'function') {\n return element.props[`testOnly_${eventName}`];\n }\n\n return undefined;\n}\n\nexport function getEventHandlerName(eventName: string) {\n return `on${capitalizeFirstLetter(eventName)}`;\n}\n\nfunction capitalizeFirstLetter(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"],"mappings":";;;;;;;AAOO,SAASA,eAAeA,CAC7BC,OAAoB,EACpBC,SAAiB,EACjBC,OAA6B,EAC7B;EACA,MAAMC,WAAW,GAAGC,mBAAmB,CAACH,SAAS,CAAC;EAClD,IAAI,OAAOD,OAAO,CAACK,KAAK,CAACF,WAAW,CAAC,KAAK,UAAU,EAAE;IACpD,OAAOH,OAAO,CAACK,KAAK,CAACF,WAAW,CAAC;EACnC;EAEA,IAAID,OAAO,EAAEI,KAAK,IAAI,OAAON,OAAO,CAACK,KAAK,CAACJ,SAAS,CAAC,KAAK,UAAU,EAAE;IACpE,OAAOD,OAAO,CAACK,KAAK,CAACJ,SAAS,CAAC;EACjC;EAEA,IAAI,OAAOD,OAAO,CAACK,KAAK,CAAC,YAAYF,WAAW,EAAE,CAAC,KAAK,UAAU,EAAE;IAClE,OAAOH,OAAO,CAACK,KAAK,CAAC,YAAYF,WAAW,EAAE,CAAC;EACjD;EAEA,IAAID,OAAO,EAAEI,KAAK,IAAI,OAAON,OAAO,CAACK,KAAK,CAAC,YAAYJ,SAAS,EAAE,CAAC,KAAK,UAAU,EAAE;IAClF,OAAOD,OAAO,CAACK,KAAK,CAAC,YAAYJ,SAAS,EAAE,CAAC;EAC/C;EAEA,OAAOM,SAAS;AAClB;AAEO,SAASH,mBAAmBA,CAACH,SAAiB,EAAE;EACrD,OAAO,KAAKO,qBAAqB,CAACP,SAAS,CAAC,EAAE;AAChD;AAEA,SAASO,qBAAqBA,CAACC,GAAW,EAAE;EAC1C,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC;AACnD","ignoreList":[]}
|
package/build/fire-event.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { PressableProps, ScrollViewProps, TextInputProps, TextProps, ViewProps } from 'react-native';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
3
3
|
import type { StringWithAutocomplete } from './types';
|
|
4
|
-
export declare function isTouchResponder(element:
|
|
5
|
-
export declare function isEventEnabled(element:
|
|
4
|
+
export declare function isTouchResponder(element: HostElement): boolean;
|
|
5
|
+
export declare function isEventEnabled(element: HostElement, eventName: string, nearestTouchResponder?: HostElement): boolean;
|
|
6
6
|
type EventNameExtractor<T> = keyof {
|
|
7
7
|
[K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];
|
|
8
8
|
};
|
|
9
9
|
type EventName = StringWithAutocomplete<EventNameExtractor<ViewProps> | EventNameExtractor<TextProps> | EventNameExtractor<TextInputProps> | EventNameExtractor<PressableProps> | EventNameExtractor<ScrollViewProps>>;
|
|
10
|
-
declare function fireEvent(element:
|
|
10
|
+
declare function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]): undefined;
|
|
11
11
|
declare namespace fireEvent {
|
|
12
|
-
var press: (element:
|
|
13
|
-
var changeText: (element:
|
|
14
|
-
var scroll: (element:
|
|
12
|
+
var press: (element: HostElement, ...data: unknown[]) => void;
|
|
13
|
+
var changeText: (element: HostElement, ...data: unknown[]) => undefined;
|
|
14
|
+
var scroll: (element: HostElement, ...data: unknown[]) => undefined;
|
|
15
15
|
}
|
|
16
16
|
export default fireEvent;
|
package/build/fire-event.js
CHANGED
|
@@ -13,9 +13,10 @@ var _hostComponentNames = require("./helpers/host-component-names");
|
|
|
13
13
|
var _pointerEvents = require("./helpers/pointer-events");
|
|
14
14
|
var _textInput = require("./helpers/text-input");
|
|
15
15
|
var _nativeState = require("./native-state");
|
|
16
|
+
var _eventBuilder = require("./user-event/event-builder");
|
|
16
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
18
|
function isTouchResponder(element) {
|
|
18
|
-
if (!(0, _componentTree.
|
|
19
|
+
if (!(0, _componentTree.isValidElement)(element)) {
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
22
|
return Boolean(element.props.onStartShouldSetResponder) || (0, _hostComponentNames.isHostTextInput)(element);
|
|
@@ -27,7 +28,7 @@ function isTouchResponder(element) {
|
|
|
27
28
|
* Note: `fireEvent` is accepting both `press` and `onPress` for event names,
|
|
28
29
|
* so we need cover both forms.
|
|
29
30
|
*/
|
|
30
|
-
const eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);
|
|
31
|
+
const eventsAffectedByPointerEventsProp = new Set(['press', 'onPress', 'responderGrant', 'responderRelease', 'longPress', 'pressIn', 'pressOut']);
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* List of `TextInput` events not affected by `editable` prop.
|
|
@@ -55,7 +56,9 @@ function findEventHandler(element, eventName, nearestTouchResponder) {
|
|
|
55
56
|
const handler = (0, _eventHandler.getEventHandler)(element, eventName, {
|
|
56
57
|
loose: true
|
|
57
58
|
});
|
|
58
|
-
if (handler && isEventEnabled(element, eventName, touchResponder))
|
|
59
|
+
if (handler && isEventEnabled(element, eventName, touchResponder)) {
|
|
60
|
+
return handler;
|
|
61
|
+
}
|
|
59
62
|
|
|
60
63
|
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
61
64
|
if (element.parent === null || element.parent.parent === null) {
|
|
@@ -81,7 +84,26 @@ function fireEvent(element, eventName, ...data) {
|
|
|
81
84
|
});
|
|
82
85
|
return returnValue;
|
|
83
86
|
}
|
|
84
|
-
fireEvent.press = (element, ...data) =>
|
|
87
|
+
fireEvent.press = (element, ...data) => {
|
|
88
|
+
const nativeData = data.length === 1 && typeof data[0] === 'object' && data[0] !== null && 'nativeEvent' in data[0] && typeof data[0].nativeEvent === 'object' ? data[0].nativeEvent : null;
|
|
89
|
+
const responderGrantEvent = _eventBuilder.EventBuilder.Common.responderGrant();
|
|
90
|
+
if (nativeData) {
|
|
91
|
+
responderGrantEvent.nativeEvent = {
|
|
92
|
+
...responderGrantEvent.nativeEvent,
|
|
93
|
+
...nativeData
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
fireEvent(element, 'responderGrant', responderGrantEvent);
|
|
97
|
+
fireEvent(element, 'press', ...data);
|
|
98
|
+
const responderReleaseEvent = _eventBuilder.EventBuilder.Common.responderRelease();
|
|
99
|
+
if (nativeData) {
|
|
100
|
+
responderReleaseEvent.nativeEvent = {
|
|
101
|
+
...responderReleaseEvent.nativeEvent,
|
|
102
|
+
...nativeData
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
fireEvent(element, 'responderRelease', responderReleaseEvent);
|
|
106
|
+
};
|
|
85
107
|
fireEvent.changeText = (element, ...data) => fireEvent(element, 'changeText', ...data);
|
|
86
108
|
fireEvent.scroll = (element, ...data) => fireEvent(element, 'scroll', ...data);
|
|
87
109
|
var _default = exports.default = fireEvent;
|
package/build/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","e","__esModule","default","isTouchResponder","element","isHostElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","loose","parent","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","nativeEvent","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport act from './act';\nimport { getEventHandler } from './event-handler';\nimport { isElementMounted, isHostElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: ReactTestInstance) {\n if (!isHostElement(element)) {\n return false;\n }\n\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set(['press', 'onPress']);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n) {\n if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: ReactTestInstance,\n eventName: string,\n nearestTouchResponder?: ReactTestInstance,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName, { loose: true });\n if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nfunction fireEvent(element: ReactTestInstance, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'press', ...data);\n\nfireEvent.changeText = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: ReactTestInstance, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: ReactTestInstance, eventName: string, value: unknown) {\n if (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAA6C,SAAAD,uBA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OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAO;QACLD,CAAC,EAAEE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC;QAC7BC,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fire-event.js","names":["_act","_interopRequireDefault","require","_eventHandler","_componentTree","_hostComponentNames","_pointerEvents","_textInput","_nativeState","_eventBuilder","e","__esModule","default","isTouchResponder","element","isValidElement","Boolean","props","onStartShouldSetResponder","isHostTextInput","eventsAffectedByPointerEventsProp","Set","textInputEventsIgnoringEditableProp","isEventEnabled","eventName","nearestTouchResponder","isEditableTextInput","has","isPointerEventEnabled","touchStart","touchMove","onMoveShouldSetResponder","undefined","findEventHandler","touchResponder","handler","getEventHandler","loose","parent","fireEvent","data","isElementMounted","setNativeStateIfNeeded","returnValue","act","press","nativeData","length","nativeEvent","responderGrantEvent","EventBuilder","Common","responderGrant","responderReleaseEvent","responderRelease","changeText","scroll","_default","exports","scrollEventNames","value","nativeState","valueForElement","set","isHostScrollView","contentOffset","tryGetContentOffset","contentOffsetForElement","event","x","y","Number","isFinite"],"sources":["../src/fire-event.ts"],"sourcesContent":["import type {\n PressableProps,\n ScrollViewProps,\n TextInputProps,\n TextProps,\n ViewProps,\n} from 'react-native';\nimport type { HostElement } from 'universal-test-renderer';\n\nimport act from './act';\nimport { getEventHandler } from './event-handler';\nimport { isElementMounted, isValidElement } from './helpers/component-tree';\nimport { isHostScrollView, isHostTextInput } from './helpers/host-component-names';\nimport { isPointerEventEnabled } from './helpers/pointer-events';\nimport { isEditableTextInput } from './helpers/text-input';\nimport { nativeState } from './native-state';\nimport type { Point, StringWithAutocomplete } from './types';\nimport { EventBuilder } from './user-event/event-builder';\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nexport function isTouchResponder(element: HostElement) {\n if (!isValidElement(element)) {\n return false;\n }\n\n return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);\n}\n\n/**\n * List of events affected by `pointerEvents` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst eventsAffectedByPointerEventsProp = new Set([\n 'press',\n 'onPress',\n 'responderGrant',\n 'responderRelease',\n 'longPress',\n 'pressIn',\n 'pressOut',\n]);\n\n/**\n * List of `TextInput` events not affected by `editable` prop.\n *\n * Note: `fireEvent` is accepting both `press` and `onPress` for event names,\n * so we need cover both forms.\n */\nconst textInputEventsIgnoringEditableProp = new Set([\n 'contentSizeChange',\n 'onContentSizeChange',\n 'layout',\n 'onLayout',\n 'scroll',\n 'onScroll',\n]);\n\nexport function isEventEnabled(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n) {\n if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) {\n return (\n isEditableTextInput(nearestTouchResponder) ||\n textInputEventsIgnoringEditableProp.has(eventName)\n );\n }\n\n if (eventsAffectedByPointerEventsProp.has(eventName) && !isPointerEventEnabled(element)) {\n return false;\n }\n\n const touchStart = nearestTouchResponder?.props.onStartShouldSetResponder?.();\n const touchMove = nearestTouchResponder?.props.onMoveShouldSetResponder?.();\n if (touchStart || touchMove) {\n return true;\n }\n\n return touchStart === undefined && touchMove === undefined;\n}\n\nfunction findEventHandler(\n element: HostElement,\n eventName: string,\n nearestTouchResponder?: HostElement,\n): EventHandler | null {\n const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;\n\n const handler = getEventHandler(element, eventName, { loose: true });\n if (handler && isEventEnabled(element, eventName, touchResponder)) {\n return handler;\n }\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (element.parent === null || element.parent.parent === null) {\n return null;\n }\n\n return findEventHandler(element.parent, eventName, touchResponder);\n}\n\n// String union type of keys of T that start with on, stripped of 'on'\ntype EventNameExtractor<T> = keyof {\n [K in keyof T as K extends `on${infer Rest}` ? Uncapitalize<Rest> : never]: T[K];\n};\n\ntype EventName = StringWithAutocomplete<\n | EventNameExtractor<ViewProps>\n | EventNameExtractor<TextProps>\n | EventNameExtractor<TextInputProps>\n | EventNameExtractor<PressableProps>\n | EventNameExtractor<ScrollViewProps>\n>;\n\nfunction fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]) {\n if (!isElementMounted(element)) {\n return;\n }\n\n setNativeStateIfNeeded(element, eventName, data[0]);\n\n const handler = findEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n let returnValue;\n void act(() => {\n returnValue = handler(...data);\n });\n\n return returnValue;\n}\n\nfireEvent.press = (element: HostElement, ...data: unknown[]) => {\n const nativeData =\n data.length === 1 &&\n typeof data[0] === 'object' &&\n data[0] !== null &&\n 'nativeEvent' in data[0] &&\n typeof data[0].nativeEvent === 'object'\n ? data[0].nativeEvent\n : null;\n\n const responderGrantEvent = EventBuilder.Common.responderGrant();\n if (nativeData) {\n responderGrantEvent.nativeEvent = {\n ...responderGrantEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderGrant', responderGrantEvent);\n\n fireEvent(element, 'press', ...data);\n\n const responderReleaseEvent = EventBuilder.Common.responderRelease();\n if (nativeData) {\n responderReleaseEvent.nativeEvent = {\n ...responderReleaseEvent.nativeEvent,\n ...nativeData,\n };\n }\n fireEvent(element, 'responderRelease', responderReleaseEvent);\n};\n\nfireEvent.changeText = (element: HostElement, ...data: unknown[]) =>\n fireEvent(element, 'changeText', ...data);\n\nfireEvent.scroll = (element: HostElement, ...data: unknown[]) =>\n fireEvent(element, 'scroll', ...data);\n\nexport default fireEvent;\n\nconst scrollEventNames = new Set([\n 'scroll',\n 'scrollBeginDrag',\n 'scrollEndDrag',\n 'momentumScrollBegin',\n 'momentumScrollEnd',\n]);\n\nfunction setNativeStateIfNeeded(element: HostElement, eventName: string, value: unknown) {\n if (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) {\n nativeState.valueForElement.set(element, value);\n }\n\n if (scrollEventNames.has(eventName) && isHostScrollView(element)) {\n const contentOffset = tryGetContentOffset(value);\n if (contentOffset) {\n nativeState.contentOffsetForElement.set(element, contentOffset);\n }\n }\n}\n\nfunction tryGetContentOffset(event: unknown): Point | null {\n try {\n // @ts-expect-error: try to extract contentOffset from the event value\n const contentOffset = event?.nativeEvent?.contentOffset;\n const x = contentOffset?.x;\n const y = contentOffset?.y;\n if (typeof x === 'number' || typeof y === 'number') {\n return {\n x: Number.isFinite(x) ? x : 0,\n y: Number.isFinite(y) ? y : 0,\n };\n }\n } catch {\n // Do nothing\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAEA,IAAAO,aAAA,GAAAP,OAAA;AAA0D,SAAAD,uBAAAS,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAInD,SAASG,gBAAgBA,CAACC,OAAoB,EAAE;EACrD,IAAI,CAAC,IAAAC,6BAAc,EAACD,OAAO,CAAC,EAAE;IAC5B,OAAO,KAAK;EACd;EAEA,OAAOE,OAAO,CAACF,OAAO,CAACG,KAAK,CAACC,yBAAyB,CAAC,IAAI,IAAAC,mCAAe,EAACL,OAAO,CAAC;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,iCAAiC,GAAG,IAAIC,GAAG,CAAC,CAChD,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,kBAAkB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C,GAAG,CAACH,SAAS,CAAC,IAAI,IAAAwC,oCAAgB,EAAClD,OAAO,CAAC,EAAE;IAChE,MAAMmD,aAAa,GAAGC,mBAAmB,CAACN,KAAK,CAAC;IAChD,IAAIK,aAAa,EAAE;MACjBJ,wBAAW,CAACM,uBAAuB,CAACJ,GAAG,CAACjD,OAAO,EAAEmD,aAAa,CAAC;IACjE;EACF;AACF;AAEA,SAASC,mBAAmBA,CAACE,KAAc,EAAgB;EACzD,IAAI;IACF;IACA,MAAMH,aAAa,GAAGG,KAAK,EAAEpB,WAAW,EAAEiB,aAAa;IACvD,MAAMI,CAAC,GAAGJ,aAAa,EAAEI,CAAC;IAC1B,MAAMC,CAAC,GAAGL,aAAa,EAAEK,CAAC;IAC1B,IAAI,OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;MAClD,OAAO;QACLD,CAAC,EAAEE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC;QAC7BC,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,GAAGA,CAAC,GAAG;MAC9B,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAGF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
3
3
|
type IsInaccessibleOptions = {
|
|
4
|
-
cache?: WeakMap<
|
|
4
|
+
cache?: WeakMap<HostElement, boolean>;
|
|
5
5
|
};
|
|
6
6
|
export declare const accessibilityStateKeys: (keyof AccessibilityState)[];
|
|
7
7
|
export declare const accessibilityValueKeys: (keyof AccessibilityValue)[];
|
|
8
|
-
export declare function isHiddenFromAccessibility(element:
|
|
8
|
+
export declare function isHiddenFromAccessibility(element: HostElement | null, { cache }?: IsInaccessibleOptions): boolean;
|
|
9
9
|
/** RTL-compatibility alias for `isHiddenFromAccessibility` */
|
|
10
10
|
export declare const isInaccessible: typeof isHiddenFromAccessibility;
|
|
11
|
-
export declare function isAccessibilityElement(element:
|
|
11
|
+
export declare function isAccessibilityElement(element: HostElement | null): boolean;
|
|
12
12
|
/**
|
|
13
13
|
* Returns the accessibility role for given element. It will return explicit
|
|
14
14
|
* role from either `role` or `accessibilityRole` props if set.
|
|
@@ -22,7 +22,7 @@ export declare function isAccessibilityElement(element: ReactTestInstance | null
|
|
|
22
22
|
* @param element
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
export declare function getRole(element:
|
|
25
|
+
export declare function getRole(element: HostElement): Role | AccessibilityRole;
|
|
26
26
|
/**
|
|
27
27
|
* There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.
|
|
28
28
|
* Resolve them by using ARIA `Role` type where possible.
|
|
@@ -31,15 +31,15 @@ export declare function getRole(element: ReactTestInstance): Role | Accessibilit
|
|
|
31
31
|
* @returns Normalized role
|
|
32
32
|
*/
|
|
33
33
|
export declare function normalizeRole(role: string): Role | AccessibilityRole;
|
|
34
|
-
export declare function computeAriaModal(element:
|
|
35
|
-
export declare function computeAriaLabel(element:
|
|
36
|
-
export declare function computeAriaBusy({ props }:
|
|
37
|
-
export declare function computeAriaChecked(element:
|
|
38
|
-
export declare function computeAriaDisabled(element:
|
|
39
|
-
export declare function computeAriaExpanded({ props }:
|
|
40
|
-
export declare function computeAriaSelected({ props }:
|
|
41
|
-
export declare function computeAriaValue(element:
|
|
42
|
-
export declare function computeAccessibleName(element:
|
|
34
|
+
export declare function computeAriaModal(element: HostElement): boolean | undefined;
|
|
35
|
+
export declare function computeAriaLabel(element: HostElement): string | undefined;
|
|
36
|
+
export declare function computeAriaBusy({ props }: HostElement): boolean;
|
|
37
|
+
export declare function computeAriaChecked(element: HostElement): AccessibilityState['checked'];
|
|
38
|
+
export declare function computeAriaDisabled(element: HostElement): boolean;
|
|
39
|
+
export declare function computeAriaExpanded({ props }: HostElement): boolean | undefined;
|
|
40
|
+
export declare function computeAriaSelected({ props }: HostElement): boolean;
|
|
41
|
+
export declare function computeAriaValue(element: HostElement): AccessibilityValue;
|
|
42
|
+
export declare function computeAccessibleName(element: HostElement): string | undefined;
|
|
43
43
|
type RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;
|
|
44
44
|
export declare const rolesSupportingCheckedState: RoleSupportMap;
|
|
45
45
|
export {};
|
|
@@ -147,8 +147,8 @@ function computeAriaModal(element) {
|
|
|
147
147
|
function computeAriaLabel(element) {
|
|
148
148
|
const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
|
|
149
149
|
if (labelElementId) {
|
|
150
|
-
const rootElement = (0, _componentTree.
|
|
151
|
-
const labelElement = (0, _findAll.findAll)(rootElement, node => (0, _componentTree.
|
|
150
|
+
const rootElement = (0, _componentTree.getContainerElement)(element);
|
|
151
|
+
const labelElement = (0, _findAll.findAll)(rootElement, node => (0, _componentTree.isValidElement)(node) && node.props.nativeID === labelElementId, {
|
|
152
152
|
includeHiddenElements: true
|
|
153
153
|
});
|
|
154
154
|
if (labelElement.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","rootElement","getUnsafeRootElement","labelElement","findAll","node","isHostElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { ReactTestInstance } from 'react-test-renderer';\n\nimport { getHostSiblings, getUnsafeRootElement, isHostElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<ReactTestInstance, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: ReactTestInstance | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: ReactTestInstance | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: ReactTestInstance): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: ReactTestInstance | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: ReactTestInstance): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: ReactTestInstance): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: ReactTestInstance): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const rootElement = getUnsafeRootElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isHostElement(node) && node.props.nativeID === labelElementId,\n { includeHiddenElements: true },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: ReactTestInstance): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: ReactTestInstance): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: ReactTestInstance): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: ReactTestInstance): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: ReactTestInstance): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: ReactTestInstance): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: ReactTestInstance): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAy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B,EAAEK,GAAG;IAC5CC,GAAG,EAAEJ,YAAY,IAAIF,kBAAkB,EAAEM,GAAG;IAC5CC,GAAG,EAAEJ,YAAY,IAAIH,kBAAkB,EAAEO,GAAG;IAC5CC,IAAI,EAAEJ,aAAa,IAAIJ,kBAAkB,EAAEQ;EAC7C,CAAC;AACH;AAEO,SAASC,qBAAqBA,CAAC3E,OAA0B,EAAsB;EACpF,OAAOoC,gBAAgB,CAACpC,OAAO,CAAC,IAAI,IAAAgD,2BAAc,EAAChD,OAAO,CAAC;AAC7D;AAIO,MAAMwD,2BAA2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"accessibility.js","names":["_reactNative","require","_componentTree","_findAll","_hostComponentNames","_textContent","_textInput","accessibilityStateKeys","exports","accessibilityValueKeys","isHiddenFromAccessibility","element","cache","current","isCurrentSubtreeInaccessible","get","undefined","isSubtreeInaccessible","set","parent","isInaccessible","props","accessibilityElementsHidden","importantForAccessibility","flatStyle","StyleSheet","flatten","style","display","hostSiblings","getHostSiblings","some","sibling","computeAriaModal","isAccessibilityElement","isHostImage","alt","accessible","isHostText","isHostTextInput","isHostSwitch","getRole","explicitRole","role","accessibilityRole","normalizeRole","accessibilityViewIsModal","computeAriaLabel","labelElementId","accessibilityLabelledBy","rootElement","getContainerElement","labelElement","findAll","node","isValidElement","nativeID","includeHiddenElements","length","getTextContent","explicitLabel","accessibilityLabel","computeAriaBusy","accessibilityState","busy","computeAriaChecked","value","rolesSupportingCheckedState","checked","computeAriaDisabled","isEditableTextInput","disabled","computeAriaExpanded","expanded","computeAriaSelected","selected","computeAriaValue","accessibilityValue","ariaValueMax","ariaValueMin","ariaValueNow","ariaValueText","max","min","now","text","computeAccessibleName","checkbox","radio","switch"],"sources":["../../src/helpers/accessibility.ts"],"sourcesContent":["import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native';\nimport { StyleSheet } from 'react-native';\nimport type { HostElement } from 'universal-test-renderer';\n\nimport { getContainerElement, getHostSiblings, isValidElement } from './component-tree';\nimport { findAll } from './find-all';\nimport { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';\nimport { getTextContent } from './text-content';\nimport { isEditableTextInput } from './text-input';\n\ntype IsInaccessibleOptions = {\n cache?: WeakMap<HostElement, boolean>;\n};\n\nexport const accessibilityStateKeys: (keyof AccessibilityState)[] = [\n 'disabled',\n 'selected',\n 'checked',\n 'busy',\n 'expanded',\n];\n\nexport const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text'];\n\nexport function isHiddenFromAccessibility(\n element: HostElement | null,\n { cache }: IsInaccessibleOptions = {},\n): boolean {\n if (element == null) {\n return true;\n }\n\n let current: HostElement | null = element;\n while (current) {\n let isCurrentSubtreeInaccessible = cache?.get(current);\n\n if (isCurrentSubtreeInaccessible === undefined) {\n isCurrentSubtreeInaccessible = isSubtreeInaccessible(current);\n cache?.set(current, isCurrentSubtreeInaccessible);\n }\n\n if (isCurrentSubtreeInaccessible) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n}\n\n/** RTL-compatibility alias for `isHiddenFromAccessibility` */\nexport const isInaccessible = isHiddenFromAccessibility;\n\nfunction isSubtreeInaccessible(element: HostElement): boolean {\n // Null props can happen for React.Fragments\n if (element.props == null) {\n return false;\n }\n\n // See: https://reactnative.dev/docs/accessibility#aria-hidden\n if (element.props['aria-hidden']) {\n return true;\n }\n\n // iOS: accessibilityElementsHidden\n // See: https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios\n if (element.props.accessibilityElementsHidden) {\n return true;\n }\n\n // Android: importantForAccessibility\n // See: https://reactnative.dev/docs/accessibility#importantforaccessibility-android\n if (element.props.importantForAccessibility === 'no-hide-descendants') {\n return true;\n }\n\n // Note that `opacity: 0` is not treated as inaccessible on iOS\n const flatStyle = StyleSheet.flatten(element.props.style) ?? {};\n if (flatStyle.display === 'none') return true;\n\n // iOS: accessibilityViewIsModal or aria-modal\n // See: https://reactnative.dev/docs/accessibility#accessibilityviewismodal-ios\n const hostSiblings = getHostSiblings(element);\n if (hostSiblings.some((sibling) => computeAriaModal(sibling))) {\n return true;\n }\n\n return false;\n}\n\nexport function isAccessibilityElement(element: HostElement | null): boolean {\n if (element == null) {\n return false;\n }\n\n // https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L172\n if (isHostImage(element) && element.props.alt !== undefined) {\n return true;\n }\n\n if (element.props.accessible !== undefined) {\n return element.props.accessible;\n }\n\n return isHostText(element) || isHostTextInput(element) || isHostSwitch(element);\n}\n\n/**\n * Returns the accessibility role for given element. It will return explicit\n * role from either `role` or `accessibilityRole` props if set.\n *\n * If explicit role is not available, it would try to return default element\n * role:\n * - `text` for `Text` elements\n *\n * In all other cases this functions returns `none`.\n *\n * @param element\n * @returns\n */\nexport function getRole(element: HostElement): Role | AccessibilityRole {\n const explicitRole = element.props.role ?? element.props.accessibilityRole;\n if (explicitRole) {\n return normalizeRole(explicitRole);\n }\n\n if (isHostText(element)) {\n return 'text';\n }\n\n // Note: host Image elements report \"image\" role in screen reader only on Android, but not on iOS.\n // It's better to require explicit role for Image elements.\n\n return 'none';\n}\n\n/**\n * There are some duplications between (ARIA) `Role` and `AccessibilityRole` types.\n * Resolve them by using ARIA `Role` type where possible.\n *\n * @param role Role to normalize\n * @returns Normalized role\n */\nexport function normalizeRole(role: string): Role | AccessibilityRole {\n if (role === 'image') {\n return 'img';\n }\n\n return role as Role | AccessibilityRole;\n}\n\nexport function computeAriaModal(element: HostElement): boolean | undefined {\n return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal;\n}\n\nexport function computeAriaLabel(element: HostElement): string | undefined {\n const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;\n if (labelElementId) {\n const rootElement = getContainerElement(element);\n const labelElement = findAll(\n rootElement,\n (node) => isValidElement(node) && node.props.nativeID === labelElementId,\n {\n includeHiddenElements: true,\n },\n );\n if (labelElement.length > 0) {\n return getTextContent(labelElement[0]);\n }\n }\n\n const explicitLabel = element.props['aria-label'] ?? element.props.accessibilityLabel;\n if (explicitLabel) {\n return explicitLabel;\n }\n\n //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173\n if (isHostImage(element) && element.props.alt) {\n return element.props.alt;\n }\n\n return undefined;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state\nexport function computeAriaBusy({ props }: HostElement): boolean {\n return props['aria-busy'] ?? props.accessibilityState?.busy ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state\nexport function computeAriaChecked(element: HostElement): AccessibilityState['checked'] {\n const { props } = element;\n\n if (isHostSwitch(element)) {\n return props.value;\n }\n\n const role = getRole(element);\n if (!rolesSupportingCheckedState[role]) {\n return undefined;\n }\n\n return props['aria-checked'] ?? props.accessibilityState?.checked;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state\nexport function computeAriaDisabled(element: HostElement): boolean {\n if (isHostTextInput(element) && !isEditableTextInput(element)) {\n return true;\n }\n\n const { props } = element;\n return props['aria-disabled'] ?? props.accessibilityState?.disabled ?? false;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state\nexport function computeAriaExpanded({ props }: HostElement): boolean | undefined {\n return props['aria-expanded'] ?? props.accessibilityState?.expanded;\n}\n\n// See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state\nexport function computeAriaSelected({ props }: HostElement): boolean {\n return props['aria-selected'] ?? props.accessibilityState?.selected ?? false;\n}\n\nexport function computeAriaValue(element: HostElement): AccessibilityValue {\n const {\n accessibilityValue,\n 'aria-valuemax': ariaValueMax,\n 'aria-valuemin': ariaValueMin,\n 'aria-valuenow': ariaValueNow,\n 'aria-valuetext': ariaValueText,\n } = element.props;\n\n return {\n max: ariaValueMax ?? accessibilityValue?.max,\n min: ariaValueMin ?? accessibilityValue?.min,\n now: ariaValueNow ?? accessibilityValue?.now,\n text: ariaValueText ?? accessibilityValue?.text,\n };\n}\n\nexport function computeAccessibleName(element: HostElement): string | undefined {\n return computeAriaLabel(element) ?? getTextContent(element);\n}\n\ntype RoleSupportMap = Partial<Record<Role | AccessibilityRole, true>>;\n\nexport const rolesSupportingCheckedState: RoleSupportMap = {\n checkbox: true,\n radio: true,\n switch: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAMO,MAAMM,sBAAoD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAClE,UAAU,EACV,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,CACX;AAEM,MAAME,sBAAoD,GAAAD,OAAA,CAAAC,sBAAA,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AAE1F,SAASC,yBAAyBA,CACvCC,OAA2B,EAC3B;EAAEC;AAA6B,CAAC,GAAG,CAAC,CAAC,EAC5B;EACT,IAAID,OAAO,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACb;EAEA,IAAIE,OAA2B,GAAGF,OAAO;EACzC,OAAOE,OAAO,EAAE;IACd,IAAIC,4BAA4B,GAAGF,KAAK,EAAEG,GAAG,CAACF,OAAO,CAAC;IAEtD,IAAIC,4BAA4B,KAAKE,SAAS,EAAE;MAC9CF,4BAA4B,GAAGG,qBAAqB,CAACJ,OAAO,CAAC;MAC7DD,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AA2C,GAAA3D,OAAA,CAAA2D,2BAAA,GAAG;EACzDoB,QAAQ,EAAE,IAAI;EACdC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE;AACV,CAAC","ignoreList":[]}
|
|
@@ -1,43 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* ReactTestInstance referring to host element.
|
|
4
|
-
*/
|
|
5
|
-
export type HostTestInstance = ReactTestInstance & {
|
|
6
|
-
type: string;
|
|
7
|
-
};
|
|
1
|
+
import type { HostElement } from 'universal-test-renderer';
|
|
8
2
|
/**
|
|
9
3
|
* Checks if the given element is a host element.
|
|
10
4
|
* @param element The element to check.
|
|
11
5
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function isElementMounted(element:
|
|
14
|
-
/**
|
|
15
|
-
* Returns first host ancestor for given element.
|
|
16
|
-
* @param element The element start traversing from.
|
|
17
|
-
*/
|
|
18
|
-
export declare function getHostParent(element: ReactTestInstance | null): HostTestInstance | null;
|
|
19
|
-
/**
|
|
20
|
-
* Returns host children for given element.
|
|
21
|
-
* @param element The element start traversing from.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getHostChildren(element: ReactTestInstance | null): HostTestInstance[];
|
|
6
|
+
export declare function isValidElement(element?: HostElement | null): element is HostElement;
|
|
7
|
+
export declare function isElementMounted(element: HostElement): boolean;
|
|
24
8
|
/**
|
|
25
|
-
*
|
|
9
|
+
* Returns the unsafe root element of the tree (probably composite).
|
|
26
10
|
*
|
|
27
11
|
* @param element The element start traversing from.
|
|
28
|
-
* @returns
|
|
29
|
-
* if the passed element is a composite element, it will return an array containing its host children (zero, one or many).
|
|
12
|
+
* @returns The root element of the tree (host or composite).
|
|
30
13
|
*/
|
|
31
|
-
export declare function
|
|
14
|
+
export declare function getContainerElement(element: HostElement): HostElement;
|
|
32
15
|
/**
|
|
33
16
|
* Returns host siblings for given element.
|
|
34
17
|
* @param element The element start traversing from.
|
|
35
18
|
*/
|
|
36
|
-
export declare function getHostSiblings(element:
|
|
37
|
-
/**
|
|
38
|
-
* Returns the unsafe root element of the tree (probably composite).
|
|
39
|
-
*
|
|
40
|
-
* @param element The element start traversing from.
|
|
41
|
-
* @returns The root element of the tree (host or composite).
|
|
42
|
-
*/
|
|
43
|
-
export declare function getUnsafeRootElement(element: ReactTestInstance): ReactTestInstance;
|
|
19
|
+
export declare function getHostSiblings(element: HostElement | null): HostElement[];
|
|
@@ -3,78 +3,35 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.getHostParent = getHostParent;
|
|
8
|
-
exports.getHostSelves = getHostSelves;
|
|
6
|
+
exports.getContainerElement = getContainerElement;
|
|
9
7
|
exports.getHostSiblings = getHostSiblings;
|
|
10
|
-
exports.getUnsafeRootElement = getUnsafeRootElement;
|
|
11
8
|
exports.isElementMounted = isElementMounted;
|
|
12
|
-
exports.
|
|
9
|
+
exports.isValidElement = isValidElement;
|
|
10
|
+
var _universalTestRenderer = require("universal-test-renderer");
|
|
13
11
|
var _screen = require("../screen");
|
|
14
|
-
/**
|
|
15
|
-
* ReactTestInstance referring to host element.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* Checks if the given element is a host element.
|
|
20
14
|
* @param element The element to check.
|
|
21
15
|
*/
|
|
22
|
-
function
|
|
23
|
-
return typeof element?.type === 'string';
|
|
16
|
+
function isValidElement(element) {
|
|
17
|
+
return typeof element?.type === 'string' && element.type !== _universalTestRenderer.CONTAINER_TYPE;
|
|
24
18
|
}
|
|
25
19
|
function isElementMounted(element) {
|
|
26
|
-
return
|
|
20
|
+
return getContainerElement(element) === _screen.screen.container;
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
|
-
* Returns
|
|
24
|
+
* Returns the unsafe root element of the tree (probably composite).
|
|
25
|
+
*
|
|
31
26
|
* @param element The element start traversing from.
|
|
27
|
+
* @returns The root element of the tree (host or composite).
|
|
32
28
|
*/
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
let current = element.parent;
|
|
38
|
-
while (current) {
|
|
39
|
-
if (isHostElement(current)) {
|
|
40
|
-
return current;
|
|
41
|
-
}
|
|
29
|
+
function getContainerElement(element) {
|
|
30
|
+
let current = element;
|
|
31
|
+
while (current?.parent) {
|
|
42
32
|
current = current.parent;
|
|
43
33
|
}
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Returns host children for given element.
|
|
49
|
-
* @param element The element start traversing from.
|
|
50
|
-
*/
|
|
51
|
-
function getHostChildren(element) {
|
|
52
|
-
if (element == null) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
const hostChildren = [];
|
|
56
|
-
element.children.forEach(child => {
|
|
57
|
-
if (typeof child !== 'object') {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (isHostElement(child)) {
|
|
61
|
-
hostChildren.push(child);
|
|
62
|
-
} else {
|
|
63
|
-
hostChildren.push(...getHostChildren(child));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return hostChildren;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Return the array of host elements that represent the passed element.
|
|
71
|
-
*
|
|
72
|
-
* @param element The element start traversing from.
|
|
73
|
-
* @returns If the passed element is a host element, it will return an array containing only that element,
|
|
74
|
-
* if the passed element is a composite element, it will return an array containing its host children (zero, one or many).
|
|
75
|
-
*/
|
|
76
|
-
function getHostSelves(element) {
|
|
77
|
-
return isHostElement(element) ? [element] : getHostChildren(element);
|
|
34
|
+
return current;
|
|
78
35
|
}
|
|
79
36
|
|
|
80
37
|
/**
|
|
@@ -82,22 +39,7 @@ function getHostSelves(element) {
|
|
|
82
39
|
* @param element The element start traversing from.
|
|
83
40
|
*/
|
|
84
41
|
function getHostSiblings(element) {
|
|
85
|
-
const hostParent =
|
|
86
|
-
|
|
87
|
-
return getHostChildren(hostParent).filter(sibling => !hostSelves.includes(sibling));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns the unsafe root element of the tree (probably composite).
|
|
92
|
-
*
|
|
93
|
-
* @param element The element start traversing from.
|
|
94
|
-
* @returns The root element of the tree (host or composite).
|
|
95
|
-
*/
|
|
96
|
-
function getUnsafeRootElement(element) {
|
|
97
|
-
let current = element;
|
|
98
|
-
while (current.parent) {
|
|
99
|
-
current = current.parent;
|
|
100
|
-
}
|
|
101
|
-
return current;
|
|
42
|
+
const hostParent = element?.parent ?? null;
|
|
43
|
+
return hostParent?.children.filter(sibling => typeof sibling === 'object' && sibling !== element) ?? [];
|
|
102
44
|
}
|
|
103
45
|
//# sourceMappingURL=component-tree.js.map
|