Skip to content

Commit 502cf6d

Browse files
committed
chore: add tests
1 parent 9f81822 commit 502cf6d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/helpers/__tests__/accessiblity.test.tsx

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { View, Text, TextInput, Pressable, Switch, TouchableOpacity } from 'react-native';
33
import { render, isHiddenFromAccessibility, isInaccessible, screen } from '../..';
4-
import { isAccessibilityElement } from '../accessibility';
4+
import { computeAriaLabel, isAccessibilityElement } from '../accessibility';
55

66
describe('isHiddenFromAccessibility', () => {
77
test('returns false for accessible elements', () => {
@@ -371,3 +371,39 @@ describe('isAccessibilityElement', () => {
371371
expect(isAccessibilityElement(null)).toEqual(false);
372372
});
373373
});
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

Comments
 (0)