Skip to content

Commit 841866c

Browse files
rshestfacebook-github-bot
authored andcommitted
Add accessibility props test to the <Text/> component (#53218)
Summary: Pull Request resolved: #53218 # Changelog: [Internal] - Uses the existing generalized accessibility props test suite, recently created by andrewdacenko, to test the corresponding props in the <Text/> component. Reviewed By: andrewdacenko Differential Revision: D80000693 fbshipit-source-id: ebbceef8db7b56dc5e4ba1ac7c027a5952b680a7
1 parent 677ee67 commit 841866c

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1313

1414
import type {Role} from '../../Components/View/ViewAccessibility';
15-
import type {HostInstance} from 'react-native';
15+
import type {AccessibilityProps, HostInstance} from 'react-native';
1616

1717
import ensureInstance from '../../../src/private/__tests__/utilities/ensureInstance';
1818
import * as Fantom from '@react-native/fantom';
1919
import * as React from 'react';
2020
import {createRef} from 'react';
2121
import {Text} from 'react-native';
22+
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
2223
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
2324
import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText';
2425

@@ -423,38 +424,38 @@ describe('<Text>', () => {
423424

424425
Fantom.runTask(() => {
425426
root.render(
426-
<Text style={{writingDirection: 'rtl'}}>dummy text</Text>,
427+
<Text style={{writingDirection: 'rtl'}}>{TEST_TEXT}</Text>,
427428
);
428429
});
429430

430431
expect(
431432
root.getRenderedOutput({props: ['writingDirection']}).toJSX(),
432433
).toEqual(
433-
<rn-paragraph writingDirection="rtl">dummy text</rn-paragraph>,
434+
<rn-paragraph writingDirection="rtl">{TEST_TEXT}</rn-paragraph>,
434435
);
435436

436437
Fantom.runTask(() => {
437438
root.render(
438-
<Text style={{writingDirection: 'ltr'}}>dummy text</Text>,
439+
<Text style={{writingDirection: 'ltr'}}>{TEST_TEXT}</Text>,
439440
);
440441
});
441442

442443
expect(
443444
root.getRenderedOutput({props: ['writingDirection']}).toJSX(),
444445
).toEqual(
445-
<rn-paragraph writingDirection="ltr">dummy text</rn-paragraph>,
446+
<rn-paragraph writingDirection="ltr">{TEST_TEXT}</rn-paragraph>,
446447
);
447448

448449
Fantom.runTask(() => {
449450
root.render(
450-
<Text style={{writingDirection: 'auto'}}>dummy text</Text>,
451+
<Text style={{writingDirection: 'auto'}}>{TEST_TEXT}</Text>,
451452
);
452453
});
453454

454455
expect(
455456
root.getRenderedOutput({props: ['writingDirection']}).toJSX(),
456457
).toEqual(
457-
<rn-paragraph writingDirection="auto">dummy text</rn-paragraph>,
458+
<rn-paragraph writingDirection="auto">{TEST_TEXT}</rn-paragraph>,
458459
);
459460
});
460461
});
@@ -468,7 +469,7 @@ describe('<Text>', () => {
468469
const root = Fantom.createRoot();
469470

470471
Fantom.runTask(() => {
471-
root.render(<Text ref={elementRef}>Some text</Text>);
472+
root.render(<Text ref={elementRef}>{TEST_TEXT}</Text>);
472473
});
473474

474475
const element = ensureInstance(elementRef.current, ReactNativeElement);
@@ -481,14 +482,14 @@ describe('<Text>', () => {
481482
const root = Fantom.createRoot();
482483

483484
Fantom.runTask(() => {
484-
root.render(<Text ref={elementRef}>Some text</Text>);
485+
root.render(<Text ref={elementRef}>{TEST_TEXT}</Text>);
485486
});
486487

487488
const element = ensureInstance(elementRef.current, ReactNativeElement);
488489
expect(element.childNodes.length).toBe(1);
489490

490491
const textChild = ensureInstance(element.childNodes[0], ReadOnlyText);
491-
expect(textChild.textContent).toBe('Some text');
492+
expect(textChild.textContent).toBe(TEST_TEXT);
492493
});
493494

494495
it('has text and element child nodes when nested', () => {
@@ -524,4 +525,9 @@ describe('<Text>', () => {
524525
expect(secondChildText.textContent).toBe('also in bold');
525526
});
526527
});
528+
529+
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
530+
return <Text {...props}>{TEST_TEXT}</Text>;
531+
}
532+
accessibilityPropsSuite(ComponentWithAccessibilityProps, false);
527533
});

0 commit comments

Comments
 (0)