@@ -2,7 +2,7 @@ import React from 'react';
2
2
import { Pressable , Switch , Text , TextInput , TouchableOpacity , View } from 'react-native' ;
3
3
4
4
import { isHiddenFromAccessibility , isInaccessible , render , screen } from '../..' ;
5
- import { computeAriaLabel , isAccessibilityElement } from '../accessibility' ;
5
+ import { computeAriaDisabled , computeAriaLabel , isAccessibilityElement } from '../accessibility' ;
6
6
7
7
describe ( 'isHiddenFromAccessibility' , ( ) => {
8
8
test ( 'returns false for accessible elements' , ( ) => {
@@ -278,11 +278,11 @@ describe('isHiddenFromAccessibility', () => {
278
278
test ( 'has isInaccessible alias' , ( ) => {
279
279
expect ( isInaccessible ) . toBe ( isHiddenFromAccessibility ) ;
280
280
} ) ;
281
- } ) ;
282
281
283
- test ( 'is not triggered for element with "aria-modal" prop' , ( ) => {
284
- render ( < View aria-modal testID = "subject" /> ) ;
285
- expect ( isHiddenFromAccessibility ( screen . getByTestId ( 'subject' ) ) ) . toBe ( false ) ;
282
+ test ( 'is not triggered for element with "aria-modal" prop' , ( ) => {
283
+ render ( < View aria-modal testID = "subject" /> ) ;
284
+ expect ( isHiddenFromAccessibility ( screen . getByTestId ( 'subject' ) ) ) . toBe ( false ) ;
285
+ } ) ;
286
286
} ) ;
287
287
288
288
describe ( 'isAccessibilityElement' , ( ) => {
@@ -408,3 +408,71 @@ describe('computeAriaLabel', () => {
408
408
expect ( computeAriaLabel ( screen . getByTestId ( 'subject' ) ) ) . toEqual ( 'External Label' ) ;
409
409
} ) ;
410
410
} ) ;
411
+
412
+ describe ( 'computeAriaDisabled' , ( ) => {
413
+ test ( 'supports basic usage' , ( ) => {
414
+ render (
415
+ < View >
416
+ < View testID = "default" />
417
+ < View testID = "disabled" aria-disabled />
418
+ < View testID = "disabled-false" aria-disabled = { false } />
419
+ < View testID = "disabled-by-state" accessibilityState = { { disabled : true } } />
420
+ < View testID = "disabled-false-by-state" accessibilityState = { { disabled : false } } />
421
+ </ View > ,
422
+ ) ;
423
+
424
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'default' ) ) ) . toBe ( false ) ;
425
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
426
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled-false' ) ) ) . toBe ( false ) ;
427
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled-by-state' ) ) ) . toBe ( true ) ;
428
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled-false-by-state' ) ) ) . toBe ( false ) ;
429
+ } ) ;
430
+
431
+ test ( 'supports TextInput' , ( ) => {
432
+ render (
433
+ < View >
434
+ < TextInput testID = "default" />
435
+ < TextInput testID = "editable" editable />
436
+ < TextInput testID = "editable-false" editable = { false } />
437
+ </ View > ,
438
+ ) ;
439
+
440
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'default' ) ) ) . toBe ( false ) ;
441
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'editable' ) ) ) . toBe ( false ) ;
442
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'editable-false' ) ) ) . toBe ( true ) ;
443
+ } ) ;
444
+
445
+ test ( 'supports Button' , ( ) => {
446
+ render (
447
+ < View >
448
+ < Pressable testID = "default" role = "button" >
449
+ < Text > Default Button</ Text >
450
+ </ Pressable >
451
+ < Pressable testID = "disabled" role = "button" disabled >
452
+ < Text > Disabled Button</ Text >
453
+ </ Pressable >
454
+ < Pressable testID = "disabled-false" role = "button" disabled = { false } >
455
+ < Text > Disabled False Button</ Text >
456
+ </ Pressable >
457
+ </ View > ,
458
+ ) ;
459
+
460
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'default' ) ) ) . toBe ( false ) ;
461
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
462
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled-false' ) ) ) . toBe ( false ) ;
463
+ } ) ;
464
+
465
+ test ( 'supports Text' , ( ) => {
466
+ render (
467
+ < View >
468
+ < Text > Default Text</ Text >
469
+ < Text disabled > Disabled Text</ Text >
470
+ < Text aria-disabled > ARIA Disabled Text</ Text >
471
+ </ View > ,
472
+ ) ;
473
+
474
+ expect ( computeAriaDisabled ( screen . getByText ( 'Default Text' ) ) ) . toBe ( false ) ;
475
+ expect ( computeAriaDisabled ( screen . getByText ( 'Disabled Text' ) ) ) . toBe ( true ) ;
476
+ expect ( computeAriaDisabled ( screen . getByText ( 'ARIA Disabled Text' ) ) ) . toBe ( true ) ;
477
+ } ) ;
478
+ } ) ;
0 commit comments