@@ -2,7 +2,12 @@ import React from 'react';
22import { Pressable , Switch , Text , TextInput , TouchableOpacity , View } from 'react-native' ;
33
44import { isHiddenFromAccessibility , isInaccessible , render , screen } from '../..' ;
5- import { computeAriaDisabled , computeAriaLabel , isAccessibilityElement } from '../accessibility' ;
5+ import {
6+ computeAccessibleName ,
7+ computeAriaDisabled ,
8+ computeAriaLabel ,
9+ isAccessibilityElement ,
10+ } from '../accessibility' ;
611
712describe ( 'isHiddenFromAccessibility' , ( ) => {
813 test ( 'returns false for accessible elements' , async ( ) => {
@@ -476,3 +481,45 @@ describe('computeAriaDisabled', () => {
476481 expect ( computeAriaDisabled ( screen . getByText ( 'ARIA Disabled Text' ) ) ) . toBe ( true ) ;
477482 } ) ;
478483} ) ;
484+
485+ describe ( 'computeAccessibleName' , ( ) => {
486+ test ( 'basic cases' , async ( ) => {
487+ await render (
488+ < >
489+ < View testID = "aria-label" aria-label = "ARIA Label" />
490+ < View testID = "accessibility-label" accessibilityLabel = "Accessibility Label" />
491+ < View testID = "text-content" >
492+ < Text > Text Content</ Text >
493+ </ View >
494+ < TextInput testID = "text-input" placeholder = "Text Input" />
495+ </ > ,
496+ ) ;
497+ expect ( computeAccessibleName ( screen . getByTestId ( 'aria-label' ) ) ) . toBe ( 'ARIA Label' ) ;
498+ expect ( computeAccessibleName ( screen . getByTestId ( 'accessibility-label' ) ) ) . toBe (
499+ 'Accessibility Label' ,
500+ ) ;
501+ expect ( computeAccessibleName ( screen . getByTestId ( 'text-content' ) ) ) . toBe ( 'Text Content' ) ;
502+ expect ( computeAccessibleName ( screen . getByTestId ( 'text-input' ) ) ) . toBe ( 'Text Input' ) ;
503+ } ) ;
504+
505+ test ( 'basic precedence' , async ( ) => {
506+ await render (
507+ < >
508+ < View testID = "aria-label" aria-label = "ARIA Label" accessibilityLabel = "Accessibility Label" >
509+ < Text > Text Content</ Text >
510+ </ View >
511+ < View testID = "accessibility-label" accessibilityLabel = "Accessibility Label" >
512+ < Text > Text Content</ Text >
513+ </ View >
514+ < View testID = "text-content" >
515+ < Text > Text Content</ Text >
516+ </ View >
517+ </ > ,
518+ ) ;
519+ expect ( computeAccessibleName ( screen . getByTestId ( 'aria-label' ) ) ) . toBe ( 'ARIA Label' ) ;
520+ expect ( computeAccessibleName ( screen . getByTestId ( 'accessibility-label' ) ) ) . toBe (
521+ 'Accessibility Label' ,
522+ ) ;
523+ expect ( computeAccessibleName ( screen . getByTestId ( 'text-content' ) ) ) . toBe ( 'Text Content' ) ;
524+ } ) ;
525+ } ) ;
0 commit comments