mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Factor out "common props" testing and add testID test for Text (#53292)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53292 # Changelog: [Internal] - Adds a `testID` test for the Text component, by means of extracting and reusing already existing one for Image. Reviewed By: andrewdacenko Differential Revision: D80332473 fbshipit-source-id: 8e8bc2eae12f5f340817f3788f320aad3a6fff45
This commit is contained in:
committed by
Facebook GitHub Bot
parent
63335e5913
commit
c23e84ae9f
@@ -19,6 +19,7 @@ import * as React from 'react';
|
||||
import {createRef} from 'react';
|
||||
import {Image} from 'react-native';
|
||||
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
|
||||
import {testIDPropSuite} from 'react-native/src/private/__tests__/utilities/commonPropsSuite';
|
||||
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
|
||||
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';
|
||||
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
|
||||
@@ -582,20 +583,6 @@ describe('<Image>', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('testID', () => {
|
||||
it('can be set', () => {
|
||||
const root = Fantom.createRoot();
|
||||
|
||||
Fantom.runTask(() => {
|
||||
root.render(<Image testID="test" source={LOGO_SOURCE} />);
|
||||
});
|
||||
|
||||
expect(root.getRenderedOutput({props: ['testID']}).toJSX()).toEqual(
|
||||
<rn-image testID="test" />,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tintColor', () => {
|
||||
it('can be set', () => {
|
||||
const root = Fantom.createRoot();
|
||||
@@ -610,11 +597,12 @@ describe('<Image>', () => {
|
||||
});
|
||||
});
|
||||
|
||||
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
|
||||
return <Image {...props} source={LOGO_SOURCE} />;
|
||||
component TestComponent(testID?: ?string, ...props: AccessibilityProps) {
|
||||
return <Image {...props} testID={testID} source={LOGO_SOURCE} />;
|
||||
}
|
||||
|
||||
accessibilityPropsSuite(ComponentWithAccessibilityProps, false);
|
||||
accessibilityPropsSuite(TestComponent, false);
|
||||
testIDPropSuite(TestComponent);
|
||||
});
|
||||
|
||||
describe('ref', () => {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {Text} from 'react-native';
|
||||
import accessibilityPropsSuite, {
|
||||
rolePropSuite,
|
||||
} from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
|
||||
import {testIDPropSuite} from 'react-native/src/private/__tests__/utilities/commonPropsSuite';
|
||||
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
|
||||
import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText';
|
||||
|
||||
@@ -418,9 +419,15 @@ describe('<Text>', () => {
|
||||
});
|
||||
});
|
||||
|
||||
component ComponentWithAccessibilityProps(...props: AccessibilityProps) {
|
||||
return <Text {...props}>{TEST_TEXT}</Text>;
|
||||
component TestComponent(testID?: ?string, ...props: AccessibilityProps) {
|
||||
return (
|
||||
<Text testID={testID} {...props}>
|
||||
{TEST_TEXT}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
accessibilityPropsSuite(ComponentWithAccessibilityProps, false);
|
||||
rolePropSuite(ComponentWithAccessibilityProps);
|
||||
accessibilityPropsSuite(TestComponent, false);
|
||||
rolePropSuite(TestComponent);
|
||||
|
||||
testIDPropSuite(TestComponent);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {Root} from '@react-native/fantom';
|
||||
|
||||
import * as Fantom from '@react-native/fantom';
|
||||
import * as React from 'react';
|
||||
|
||||
export function testIDPropSuite(
|
||||
Component: component(...{testID?: ?string}),
|
||||
): void {
|
||||
let root: Root;
|
||||
|
||||
beforeEach(() => {
|
||||
root = Fantom.createRoot();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
root.destroy();
|
||||
});
|
||||
|
||||
describe('testID', () => {
|
||||
it('can be set', () => {
|
||||
Fantom.runTask(() => {
|
||||
root.render(<Component testID="test" />);
|
||||
});
|
||||
|
||||
expect(
|
||||
root.getRenderedOutput({props: ['testID']}).toJSONObject().props.testID,
|
||||
).toEqual('test');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user