diff --git a/packages/core/accessibility/index.android.ts b/packages/core/accessibility/index.android.ts index 41bb528c7..cadd85e99 100644 --- a/packages/core/accessibility/index.android.ts +++ b/packages/core/accessibility/index.android.ts @@ -1,6 +1,7 @@ import { Application, ApplicationEventData } from '../application'; import { Trace } from '../trace'; import { SDK_VERSION } from '../utils/constants'; +import { resources } from '../utils/android'; import type { View } from '../ui/core/view'; import { GestureTypes } from '../ui/gestures'; import { notifyAccessibilityFocusState } from './accessibility-common'; @@ -166,6 +167,12 @@ function ensureNativeClasses() { return; } + // Set resource id that can be used with test frameworks without polluting the content description. + const id = host.getTag(resources.getId(`:id/nativescript_accessibility_id`)); + if (id != null) { + info.setViewIdResourceName(id); + } + const accessibilityRole = view.accessibilityRole; if (accessibilityRole) { const androidClassName = RoleTypeMap.get(accessibilityRole); @@ -661,11 +668,6 @@ function applyContentDescription(view: View, forceUpdate?: boolean) { const contentDescription = contentDescriptionBuilder.join('. ').trim().replace(/^\.$/, ''); - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && view.testID) { - // ignore when testID is enabled - return; - } - if (contentDescription) { if (Trace.isEnabled()) { Trace.write(`${cls} - set to "${contentDescription}"`, Trace.categories.Accessibility); diff --git a/packages/core/global-types.d.ts b/packages/core/global-types.d.ts index 7eb160698..472744e04 100644 --- a/packages/core/global-types.d.ts +++ b/packages/core/global-types.d.ts @@ -131,7 +131,6 @@ declare const __CSS_PARSER__: string; declare const __NS_WEBPACK__: boolean; declare const __UI_USE_EXTERNAL_RENDERER__: boolean; declare const __UI_USE_XML_PARSER__: boolean; -declare const __USE_TEST_ID__: boolean | undefined; declare const __ANDROID__: boolean; declare const __IOS__: boolean; declare const __VISIONOS__: boolean; diff --git a/packages/core/platforms/android/core.aar b/packages/core/platforms/android/core.aar index ea938e613..1986e7770 100644 Binary files a/packages/core/platforms/android/core.aar and b/packages/core/platforms/android/core.aar differ diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index 04fbf6938..f6e67654f 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -794,20 +794,19 @@ export class View extends ViewCommon { } [testIDProperty.setNative](value: string) { - this.setTestID(this.nativeViewProtected, value); + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } - setTestID(view, value) { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) { - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); + setAccessibilityIdentifier(view, value) { + const id = Utils.android.resources.getId(':id/nativescript_accessibility_id'); - if (id) { - view.setTag(id, value); - view.setTag(value); - } - - view.setContentDescription(value); + if (id) { + view.setTag(id, value); + view.setTag(value); } + + if (this.testID && this.testID !== value) this.testID = value; + if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value; } [accessibilityEnabledProperty.setNative](value: boolean): void { @@ -817,16 +816,7 @@ export class View extends ViewCommon { } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID; - } else { - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); - - if (id) { - this.nativeViewProtected.setTag(id, value); - this.nativeViewProtected.setTag(value); - } - } + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } [accessibilityRoleProperty.setNative](value: AccessibilityRole): void { diff --git a/packages/core/ui/core/view/index.ios.ts b/packages/core/ui/core/view/index.ios.ts index 9fa8b0442..3967b3b69 100644 --- a/packages/core/ui/core/view/index.ios.ts +++ b/packages/core/ui/core/view/index.ios.ts @@ -679,13 +679,14 @@ export class View extends ViewCommon implements ViewDefinition { } [testIDProperty.setNative](value: string) { - this.setTestID(this.nativeViewProtected, value); + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } - public setTestID(view: any, value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) { - view.accessibilityIdentifier = value; - } + public setAccessibilityIdentifier(view: any, value: string): void { + view.accessibilityIdentifier = value; + + if (this.testID && this.testID !== value) this.testID = value; + if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value; } [accessibilityEnabledProperty.setNative](value: boolean): void { @@ -695,15 +696,11 @@ export class View extends ViewCommon implements ViewDefinition { } [accessibilityIdentifierProperty.getDefault](): string { - return this.nativeViewProtected.accessibilityLabel; + return this.nativeViewProtected.accessibilityIdentifier; } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID - } else { - this.nativeViewProtected.accessibilityIdentifier = value; - } + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } [accessibilityRoleProperty.setNative](value: AccessibilityRole): void { diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index 58adce944..ad3e3cf26 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -1173,7 +1173,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { return; } - public setTestID(view: any, value: string) { + public setAccessibilityIdentifier(view: any, value: string) { return; } } diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 25ddad5cf..37be9f247 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -465,21 +465,11 @@ export class TextBase extends TextBaseCommon { } [testIDProperty.setNative](value: string): void { - this.setTestID(this.nativeTextViewProtected, value); + this.setAccessibilityIdentifier(this.nativeTextViewProtected, value); } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID; - } else { - // we override the default setter to apply it on nativeTextViewProtected - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); - - if (id) { - this.nativeTextViewProtected.setTag(id, value); - this.nativeTextViewProtected.setTag(value); - } - } + this.setAccessibilityIdentifier(this.nativeTextViewProtected, value); } [maxLinesProperty.setNative](value: number) { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 209c654fe..0ce7972bc 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -367,8 +367,7 @@ exports[`angular configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -800,8 +799,7 @@ exports[`angular configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index bdb96879f..9b3fd6325 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -269,8 +269,7 @@ exports[`base configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -597,8 +596,7 @@ exports[`base configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap index 5341c1e17..9ee90ab55 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -269,8 +269,7 @@ exports[`javascript configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -596,8 +595,7 @@ exports[`javascript configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 1fdd9b35b..abe3c8c59 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -292,7 +292,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR 'global.isIOS': false, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -631,7 +630,6 @@ exports[`react configuration > android > base config 1`] = ` 'global.isIOS': false, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -977,7 +975,6 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena 'global.isIOS': true, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -1317,7 +1314,6 @@ exports[`react configuration > ios > base config 1`] = ` 'global.isIOS': true, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index 1fd6be11a..98a774cff 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -296,8 +296,7 @@ exports[`svelte configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -645,8 +644,7 @@ exports[`svelte configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index 46b6beeef..811bfe377 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -269,8 +269,7 @@ exports[`typescript configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -596,8 +595,7 @@ exports[`typescript configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap index 9d756f755..3d708a2ae 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -309,8 +309,7 @@ exports[`vue configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -671,8 +670,7 @@ exports[`vue configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 16472530f..00291c9de 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -449,9 +449,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { /* for compat only */ 'global.isVisionOS': platform === 'visionos', process: 'global.process', - // enable testID when using --env.e2e - __USE_TEST_ID__: !!env.e2e, - // todo: ?!?! // profile: '() => {}', }, diff --git a/packages/webpack5/src/index.ts b/packages/webpack5/src/index.ts index 058c74b68..f9ac6f073 100644 --- a/packages/webpack5/src/index.ts +++ b/packages/webpack5/src/index.ts @@ -52,7 +52,6 @@ export interface IWebpackEnv { // misc replace?: string[] | string; watchNodeModules?: boolean; - e2e?: boolean; } interface IChainEntry {