Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Oct 25, 2024
1 parent 37be232 commit 853d3e9
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/helpers/__tests__/accessiblity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { View, Text, TextInput, Pressable, Switch, TouchableOpacity } from 'react-native';
import { render, isHiddenFromAccessibility, isInaccessible, screen } from '../..';
import { isAccessibilityElement } from '../accessibility';
import { computeAriaLabel, isAccessibilityElement } from '../accessibility';

describe('isHiddenFromAccessibility', () => {
test('returns false for accessible elements', () => {
Expand Down Expand Up @@ -371,3 +371,39 @@ describe('isAccessibilityElement', () => {
expect(isAccessibilityElement(null)).toEqual(false);
});
});

describe('computeAriaLabel', () => {
test('supports basic usage', () => {
render(
<View>
<View testID="label" aria-label="Internal Label" />
<View testID="label-by-id" aria-labelledby="external-label" />
<View nativeID="external-label">
<Text>External Text</Text>
</View>
<View testID="no-label" />
<View testID="text-content">
<Text>Text Content</Text>
</View>
</View>,
);

expect(computeAriaLabel(screen.getByTestId('label'))).toEqual('Internal Label');
expect(computeAriaLabel(screen.getByTestId('label-by-id'))).toEqual('External Text');
expect(computeAriaLabel(screen.getByTestId('no-label'))).toBeUndefined();
expect(computeAriaLabel(screen.getByTestId('text-content'))).toBeUndefined();
});

test('label priority', () => {
render(
<View>
<View testID="subject" aria-label="Internal Label" aria-labelledby="external-content" />
<View nativeID="external-content">
<Text>External Label</Text>
</View>
</View>,
);

expect(computeAriaLabel(screen.getByTestId('subject'))).toEqual('External Label');
});
});

0 comments on commit 853d3e9

Please sign in to comment.