Skip to content

Commit 63335e5

Browse files
rshestfacebook-github-bot
authored andcommitted
Refactor accessibility tests and add proper Role types (#53222)
Summary: Pull Request resolved: #53222 # Changelog: [Internal] - This factors out bits of the previously existing "Text.role" prop testing into the general accessibility props tests, so those can be reused, also making sure that we use correct types for both `.role` prop (`Role` type) and `.accessibilityRole prop (`AccessibilityRole`, correspondingly). Note that the test suite for the `role` prop is a separate one, as `role` is only defined on the native side for certain component types (including `Text`), but not all. Also, in the existing suite we weren't really testing `role`, but instead running the same test twice for `accessibilityRole`, that is corrected as well. Reviewed By: andrewdacenko Differential Revision: D80084731 fbshipit-source-id: 545f01c00e9ea5ca53f664888b9bb7b24ded315e
1 parent 0ac41fa commit 63335e5

2 files changed

Lines changed: 177 additions & 187 deletions

File tree

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

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111

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

14-
import type {Role} from '../../Components/View/ViewAccessibility';
1514
import type {AccessibilityProps, HostInstance} from 'react-native';
1615

1716
import ensureInstance from '../../../src/private/__tests__/utilities/ensureInstance';
1817
import * as Fantom from '@react-native/fantom';
1918
import * as React from 'react';
2019
import {createRef} from 'react';
2120
import {Text} from 'react-native';
22-
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
21+
import accessibilityPropsSuite, {
22+
rolePropSuite,
23+
} from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
2324
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
2425
import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText';
2526

@@ -274,115 +275,6 @@ describe('<Text>', () => {
274275
});
275276
});
276277

277-
describe('role', () => {
278-
it(`has none by default`, () => {
279-
const root = Fantom.createRoot();
280-
281-
Fantom.runTask(() => {
282-
root.render(<Text>{TEST_TEXT}</Text>);
283-
});
284-
285-
expect(root.getRenderedOutput({props: ['role']}).toJSX()).toEqual(
286-
<rn-paragraph>{TEST_TEXT}</rn-paragraph>,
287-
);
288-
});
289-
290-
it(`maps invalid values to 'none'`, () => {
291-
const root = Fantom.createRoot();
292-
293-
Fantom.runTask(() => {
294-
// $FlowExpectedError[incompatible-type]
295-
root.render(<Text role="__some_invalid_value">{TEST_TEXT}</Text>);
296-
});
297-
298-
expect(root.getRenderedOutput({props: ['role']}).toJSX()).toEqual(
299-
<rn-paragraph role="none">{TEST_TEXT}</rn-paragraph>,
300-
);
301-
});
302-
303-
it(`propagates correctly all possible values`, () => {
304-
const root = Fantom.createRoot();
305-
(
306-
[
307-
'alert',
308-
'alertdialog',
309-
'application',
310-
'article',
311-
'banner',
312-
'button',
313-
'cell',
314-
'checkbox',
315-
'columnheader',
316-
'combobox',
317-
'complementary',
318-
'contentinfo',
319-
'definition',
320-
'dialog',
321-
'directory',
322-
'document',
323-
'feed',
324-
'figure',
325-
'form',
326-
'grid',
327-
'group',
328-
'heading',
329-
'img',
330-
'link',
331-
'list',
332-
'listitem',
333-
'log',
334-
'main',
335-
'marquee',
336-
'math',
337-
'menu',
338-
'menubar',
339-
'menuitem',
340-
'meter',
341-
'navigation',
342-
'none',
343-
'note',
344-
'option',
345-
'presentation',
346-
'progressbar',
347-
'radio',
348-
'radiogroup',
349-
'region',
350-
'row',
351-
'rowgroup',
352-
'rowheader',
353-
'scrollbar',
354-
'searchbox',
355-
'separator',
356-
'slider',
357-
'spinbutton',
358-
'status',
359-
'summary',
360-
'switch',
361-
'tab',
362-
'table',
363-
'tablist',
364-
'tabpanel',
365-
'term',
366-
'timer',
367-
'toolbar',
368-
'tooltip',
369-
'tree',
370-
'treegrid',
371-
'treeitem',
372-
'treeitem',
373-
] as Array<Role>
374-
).forEach(propVal => {
375-
Fantom.runTask(() => {
376-
root.render(<Text role={propVal}>{TEST_TEXT}</Text>);
377-
});
378-
379-
expect(root.getRenderedOutput({props: ['role']}).toJSX()).toEqual(
380-
<rn-paragraph role={propVal}>{TEST_TEXT}</rn-paragraph>,
381-
);
382-
});
383-
});
384-
});
385-
386278
describe('selectable', () => {
387279
it(`can be set to "true"`, () => {
388280
const root = Fantom.createRoot();
@@ -530,4 +422,5 @@ describe('<Text>', () => {
530422
return <Text {...props}>{TEST_TEXT}</Text>;
531423
}
532424
accessibilityPropsSuite(ComponentWithAccessibilityProps, false);
425+
rolePropSuite(ComponentWithAccessibilityProps);
533426
});

0 commit comments

Comments
 (0)