|
1 | 1 | import React from 'react';
|
2 | 2 | import { View, Text, TextInput, Pressable, Switch, TouchableOpacity } from 'react-native';
|
3 | 3 | import { render, isHiddenFromAccessibility, isInaccessible, screen } from '../..';
|
4 |
| -import { isAccessibilityElement } from '../accessibility'; |
| 4 | +import { computeAriaLabel, isAccessibilityElement } from '../accessibility'; |
5 | 5 |
|
6 | 6 | describe('isHiddenFromAccessibility', () => {
|
7 | 7 | test('returns false for accessible elements', () => {
|
@@ -371,3 +371,39 @@ describe('isAccessibilityElement', () => {
|
371 | 371 | expect(isAccessibilityElement(null)).toEqual(false);
|
372 | 372 | });
|
373 | 373 | });
|
| 374 | + |
| 375 | +describe('computeAriaLabel', () => { |
| 376 | + test('supports basic usage', () => { |
| 377 | + render( |
| 378 | + <View> |
| 379 | + <View testID="label" aria-label="Internal Label" /> |
| 380 | + <View testID="label-by-id" aria-labelledby="external-label" /> |
| 381 | + <View nativeID="external-label"> |
| 382 | + <Text>External Text</Text> |
| 383 | + </View> |
| 384 | + <View testID="no-label" /> |
| 385 | + <View testID="text-content"> |
| 386 | + <Text>Text Content</Text> |
| 387 | + </View> |
| 388 | + </View>, |
| 389 | + ); |
| 390 | + |
| 391 | + expect(computeAriaLabel(screen.getByTestId('label'))).toEqual('Internal Label'); |
| 392 | + expect(computeAriaLabel(screen.getByTestId('label-by-id'))).toEqual('External Text'); |
| 393 | + expect(computeAriaLabel(screen.getByTestId('no-label'))).toBeUndefined(); |
| 394 | + expect(computeAriaLabel(screen.getByTestId('text-content'))).toBeUndefined(); |
| 395 | + }); |
| 396 | + |
| 397 | + test('label priority', () => { |
| 398 | + render( |
| 399 | + <View> |
| 400 | + <View testID="subject" aria-label="Internal Label" aria-labelledby="external-content" /> |
| 401 | + <View nativeID="external-content"> |
| 402 | + <Text>External Label</Text> |
| 403 | + </View> |
| 404 | + </View>, |
| 405 | + ); |
| 406 | + |
| 407 | + expect(computeAriaLabel(screen.getByTestId('subject'))).toEqual('External Label'); |
| 408 | + }); |
| 409 | +}); |
0 commit comments