8000 feat: testID property for use with e2e testing without interfering wi… · NativeScript/NativeScript@803553a · GitHub
[go: up one dir, main page]

Skip to content

Commit 803553a

Browse files
NathanWalkerrigor789
authored andcommitted
feat: testID property for use with e2e testing without interfering with a11y
1 parent b02eabf commit 803553a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/core/ui/core/view/index.android.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Point, CustomLayoutView as CustomLayoutViewDefinition } from '.';
33
import type { GestureTypes, GestureEventData } from '../../gestures';
44

55
// Types.
6-
import { ViewCommon, isEnabledProperty, originXProperty, originYProperty, isUserInteractionEnabledProperty } from './view-common';
6+
import { ViewCommon, isEnabledProperty, originXProperty, originYProperty, isUserInteractionEnabledProperty, testIDProperty } from './view-common';
77
import { paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length } from '../../styling/style-properties';
88
import { layout } from '../../../utils';
99
import { Trace } from '../../../trace';
@@ -796,6 +796,10 @@ export class View extends ViewCommon {
796796
this.nativeViewProtected.setAlpha(float(value));
797797
}
798798

799+
[testIDProperty.setNative](value: string) {
800+
this.nativeViewProtected.setContentDescription(value);
801+
}
802+
799803
[accessibilityEnabledProperty.setNative](value: boolean): void {
800804
this.nativeViewProtected.setFocusable(!!value);
801805

packages/core/ui/core/view/index.ios.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Point, View as ViewDefinition } from '.';
33

44
// Requires
5-
import { ViewCommon, isEnabledProperty, originXProperty, originYProperty, isUserInteractionEnabledProperty } from './view-common';
5+
import { ViewCommon, isEnabledProperty, originXProperty, originYProperty, isUserInteractionEnabledProperty, testIDProperty } from './view-common';
66
import { ShowModalOptions, hiddenProperty } from '../view-base';
77
import { Trace } from '../../../trace';
88
import { layout, iOSNativeHelper } from '../../../utils';
@@ -572,6 +572,10 @@ export class View extends ViewCommon implements ViewDefinition {
572572
this.updateOriginPoint(this.originX, value);
573573
}
574574

575+
[testIDProperty.setNative](value: string) {
576+
this.nativeViewProtected.accessibilityIdentifier = value;
577+
}
578+
575579
[accessibilityEnabledProperty.setNative](value: boolean): void {
576580
this.nativeViewProtected.isAccessibilityElement = !!value;
577581

packages/core/ui/core/view/view-common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
8282
public accessibilityValue: string;
8383
public accessibilityHint: string;
8484

85+
public testID: string;
86+
8587
public touchAnimation: boolean | TouchAnimationOptions;
8688
public ignoreTouchAnimation: boolean;
8789

@@ -1196,6 +1198,11 @@ const ignoreTouchAnimationProperty = new Property<ViewCommon, boolean>({
11961198
});
11971199
ignoreTouchAnimationProperty.register(ViewCommon);
11981200

1201+
export const testIDProperty = new Property<ViewCommon, string>({
1202+
name: 'testID',
1203+
});
1204+
testIDProperty.register(ViewCommon);
1205+
11991206
accessibilityIdentifierProperty.register(ViewCommon);
12001207
accessibilityLabelProperty.register(ViewCommon);
12011208
accessibilityValueProperty.register(ViewCommon);

0 commit comments

Comments
 (0)
0