Skip to content

Commit 6738dbc

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Generalize accessibility testing (#53182)
Summary: Pull Request resolved: #53182 Changelog: [Internal] Move accessibility tests into reusable test suite. Reviewed By: rshest Differential Revision: D79897200 fbshipit-source-id: d98ebc7d16e7fd5c3c81086df4eec07dfdcb2fb0
1 parent 1feb364 commit 6738dbc

5 files changed

Lines changed: 269 additions & 90 deletions

File tree

packages/react-native/Libraries/Components/Pressable/__tests__/Pressable-itest.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1313

14-
import type {HostInstance} from 'react-native';
14+
import type {AccessibilityProps, HostInstance} from 'react-native';
1515

1616
import * as Fantom from '@react-native/fantom';
1717
import * as React from 'react';
1818
import {createRef} from 'react';
1919
import {Pressable} from 'react-native';
2020
import {Text} from 'react-native';
21+
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
2122
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
2223
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
2324

@@ -156,6 +157,11 @@ describe('<Pressable>', () => {
156157
);
157158
});
158159
});
160+
161+
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
162+
return <Pressable {...props} />;
163+
}
164+
accessibilityPropsSuite(ComponentWithAccessibilityProps);
159165
});
160166

161167
describe('ref', () => {

packages/react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-itest.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

13+
import type {AccessibilityProps} from 'react-native';
14+
1315
import * as Fantom from '@react-native/fantom';
1416
import * as React from 'react';
1517
import {Text, TouchableWithoutFeedback, View} from 'react-native';
18+
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
1619
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
1720
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
1821

@@ -36,23 +39,15 @@ describe('<TouchableWithoutFeedback>', () => {
3639
});
3740
});
3841

39-
describe('accessibility', () => {
40-
it('is accessible by default', () => {
41-
const root = Fantom.createRoot();
42-
43-
Fantom.runTask(() => {
44-
root.render(
45-
<TouchableWithoutFeedback>
46-
<Text>Touchable</Text>
47-
</TouchableWithoutFeedback>,
48-
);
49-
});
42+
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
43+
return (
44+
<TouchableWithoutFeedback {...props}>
45+
<Text>Touchable</Text>
46+
</TouchableWithoutFeedback>
47+
);
48+
}
5049

51-
expect(root.getRenderedOutput({props: ['accessible']}).toJSX()).toEqual(
52-
<rn-paragraph accessible="true">Touchable</rn-paragraph>,
53-
);
54-
});
55-
});
50+
accessibilityPropsSuite(ComponentWithAccessibilityProps);
5651
});
5752

5853
describe('ref', () => {

packages/react-native/Libraries/Image/__tests__/Image-itest.js

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

13-
import type {HostInstance} from 'react-native';
13+
import type {AccessibilityProps, HostInstance} from 'react-native';
1414

1515
import * as Fantom from '@react-native/fantom';
1616
import * as React from 'react';
1717
import {createRef} from 'react';
1818
import {Image} from 'react-native';
19+
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
1920
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
2021
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';
2122
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
@@ -59,78 +60,6 @@ describe('<Image>', () => {
5960
});
6061
});
6162

62-
describe('accessibility', () => {
63-
describe('accessible', () => {
64-
it('indicates that image is an accessibility element', () => {
65-
const root = Fantom.createRoot();
66-
67-
Fantom.runTask(() => {
68-
root.render(<Image accessible={true} />);
69-
});
70-
71-
expect(
72-
root.getRenderedOutput({props: ['accessible']}).toJSX(),
73-
).toEqual(<rn-image accessible="true" />);
74-
});
75-
});
76-
77-
describe('accessibilityLabel', () => {
78-
it('provides information for screen reader', () => {
79-
const root = Fantom.createRoot();
80-
81-
Fantom.runTask(() => {
82-
root.render(<Image accessibilityLabel="React Native Logo" />);
83-
});
84-
85-
expect(
86-
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
87-
).toEqual(<rn-image accessibilityLabel="React Native Logo" />);
88-
});
89-
});
90-
91-
describe('alt', () => {
92-
it('provides information for screen reader', () => {
93-
const root = Fantom.createRoot();
94-
95-
Fantom.runTask(() => {
96-
root.render(<Image alt="React Native Logo" />);
97-
});
98-
99-
expect(
100-
root
101-
.getRenderedOutput({props: ['accessible', 'accessibilityLabel']})
102-
.toJSX(),
103-
).toEqual(
104-
<rn-image
105-
accessible="true"
106-
accessibilityLabel="React Native Logo"
107-
/>,
108-
);
109-
});
110-
111-
it('can be set alongside accessibilityLabel, but accessibilityLabel has higher priority', () => {
112-
const root = Fantom.createRoot();
113-
114-
Fantom.runTask(() => {
115-
root.render(
116-
<Image
117-
alt="React Native Logo"
118-
accessibilityLabel="React Native"
119-
/>,
120-
);
121-
});
122-
123-
expect(
124-
root
125-
.getRenderedOutput({props: ['accessible', 'accessibilityLabel']})
126-
.toJSX(),
127-
).toEqual(
128-
<rn-image accessible="true" accessibilityLabel="React Native" />,
129-
);
130-
});
131-
});
132-
});
133-
13463
describe('blurRadius', () => {
13564
it('provides blur radius for image', () => {
13665
const root = Fantom.createRoot();
@@ -656,6 +585,12 @@ describe('<Image>', () => {
656585
);
657586
});
658587
});
588+
589+
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
590+
return <Image {...props} source={LOGO_SOURCE} />;
591+
}
592+
593+
accessibilityPropsSuite(ComponentWithAccessibilityProps, false);
659594
});
660595

661596
describe('ref', () => {

0 commit comments

Comments
 (0)