@@ -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,67 @@ 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 = "disabled" aria-disabled />
417
+ < View testID = "not-disabled" />
418
+ < View testID = "disabled-by-state" accessibilityState = { { disabled : true } } />
419
+ < View testID = "not-disabled-by-state" accessibilityState = { { disabled : false } } />
420
+ </ View > ,
421
+ ) ;
422
+
423
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
424
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'not-disabled' ) ) ) . toBe ( false ) ;
425
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled-by-state' ) ) ) . toBe ( true ) ;
426
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'not-disabled-by-state' ) ) ) . toBe ( false ) ;
427
+ } ) ;
428
+
429
+ test ( 'supports TextInput' , ( ) => {
430
+ render (
431
+ < View >
432
+ < TextInput testID = "disabled" editable = { false } />
433
+ < TextInput testID = "not-disabled" editable />
434
+ </ View > ,
435
+ ) ;
436
+
437
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
438
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'not-disabled' ) ) ) . toBe ( false ) ;
439
+ } ) ;
440
+
441
+ test ( 'supports Button' , ( ) => {
442
+ render (
443
+ < View >
444
+ < Pressable testID = "disabled" disabled >
445
+ < Text > Disabled Button</ Text >
446
+ </ Pressable >
447
+ < Pressable testID = "not-disabled" >
448
+ < Text > Enabled Button</ Text >
449
+ </ Pressable >
450
+ </ View > ,
451
+ ) ;
452
+
453
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
454
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'not-disabled' ) ) ) . toBe ( false ) ;
455
+ } ) ;
456
+
457
+ test ( 'supports Text' , ( ) => {
458
+ render (
459
+ < View >
460
+ < Text testID = "disabled" disabled >
461
+ Disabled Text
462
+ </ Text >
463
+ < Text testID = "aria-disabled" aria-disabled >
464
+ Disabled Text
465
+ </ Text >
466
+ < Text testID = "not-disabled" > Enabled Text</ Text >
467
+ </ View > ,
468
+ ) ;
469
+
470
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'disabled' ) ) ) . toBe ( true ) ;
471
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'aria-disabled' ) ) ) . toBe ( true ) ;
472
+ expect ( computeAriaDisabled ( screen . getByTestId ( 'not-disabled' ) ) ) . toBe ( false ) ;
473
+ } ) ;
474
+ } ) ;
0 commit comments