Skip to content

Commit 1b392fe

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Migrate Components, FlatList, and Modal Jest tests to Fantom
Summary: Migrates component unit tests from regular Jest (`-test.js`) to Fantom (`-itest.js`) so they render through the real React Native runtime (Fabric/Yoga) instead of a mocked renderer. Folded missing cases into existing Fantom tests (`View`, `ScrollView`, `Pressable`, `ActivityIndicator`, `Button`, `TouchableOpacity`, `TouchableWithoutFeedback`, `Modal`, `FlatList`) and added new Fantom tests for `TouchableNativeFeedback` and `InputAccessoryView`. Obsolete file snapshots that captured the old mocked output were removed; assertions now compare against the real Fabric output. A few component tests remain on Jest for now because they depend on capabilities Fantom does not provide (module mocks of native modules / mock-based event simulation): `AccessibilityInfo`, `DrawerAndroid`, `Keyboard`, `StatusBar`, and `Pressability`. Changelog: [Internal] Differential Revision: D108759082
1 parent 9506a61 commit 1b392fe

31 files changed

Lines changed: 786 additions & 3747 deletions

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {ActivityIndicator} from 'react-native';
1818
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
1919

2020
describe('<ActivityIndicator>', () => {
21+
it('sets displayName', () => {
22+
expect(ActivityIndicator.displayName).toBe('ActivityIndicator');
23+
});
24+
2125
describe('props', () => {
2226
describe('size', () => {
2327
it('defaults to "small" (20x20)', () => {

packages/react-native/Libraries/Components/ActivityIndicator/__tests__/ActivityIndicator-test.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/react-native/Libraries/Components/ActivityIndicator/__tests__/__snapshots__/ActivityIndicator-test.js.snap

Lines changed: 0 additions & 32 deletions
This file was deleted.

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

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as Fantom from '@react-native/fantom';
1717
import * as React from 'react';
1818
import {createRef} from 'react';
1919
import {Pressable} from 'react-native';
20-
import {Text} from 'react-native';
20+
import {PlatformColor, Text} from 'react-native';
2121
import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
2222
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
2323
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
@@ -123,6 +123,132 @@ describe('<Pressable>', () => {
123123

124124
expect(onPressCallback).toHaveBeenCalledTimes(0);
125125
});
126+
127+
it('sets accessibilityState disabled to true', () => {
128+
const root = Fantom.createRoot();
129+
130+
Fantom.runTask(() => {
131+
root.render(<Pressable disabled={true} />);
132+
});
133+
134+
expect(
135+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
136+
).toEqual(
137+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
138+
);
139+
});
140+
141+
it('sets accessibilityState disabled to true when accessibilityState is empty', () => {
142+
const root = Fantom.createRoot();
143+
144+
Fantom.runTask(() => {
145+
root.render(<Pressable disabled={true} accessibilityState={{}} />);
146+
});
147+
148+
expect(
149+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
150+
).toEqual(
151+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
152+
);
153+
});
154+
155+
it('preserves other accessibilityState fields when disabled is true', () => {
156+
const root = Fantom.createRoot();
157+
158+
Fantom.runTask(() => {
159+
root.render(
160+
<Pressable disabled={true} accessibilityState={{checked: true}} />,
161+
);
162+
});
163+
164+
expect(
165+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
166+
).toEqual(
167+
<rn-view accessibilityState="{disabled:true,selected:false,checked:Checked,busy:false,expanded:null}" />,
168+
);
169+
});
170+
171+
it('overwrites accessibilityState.disabled with the disabled prop', () => {
172+
const root = Fantom.createRoot();
173+
174+
Fantom.runTask(() => {
175+
root.render(
176+
<Pressable
177+
disabled={true}
178+
accessibilityState={{disabled: false}}
179+
/>,
180+
);
181+
});
182+
183+
expect(
184+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
185+
).toEqual(
186+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
187+
);
188+
});
189+
});
190+
191+
describe('android_ripple', () => {
192+
it('renders with a numeric color and alpha', () => {
193+
const root = Fantom.createRoot();
194+
195+
Fantom.runTask(() => {
196+
root.render(
197+
<Pressable android_ripple={{color: '#FF0000', alpha: 0.5}} />,
198+
);
199+
});
200+
201+
expect(root.getRenderedOutput().toJSX()).toEqual(
202+
<rn-view
203+
accessible="true"
204+
accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:null}"
205+
/>,
206+
);
207+
});
208+
209+
it('renders with a PlatformColor and alpha', () => {
210+
const root = Fantom.createRoot();
211+
212+
Fantom.runTask(() => {
213+
root.render(
214+
<Pressable
215+
android_ripple={{
216+
color: PlatformColor('?attr/colorAccent'),
217+
alpha: 0.3,
218+
}}
219+
/>,
220+
);
221+
});
222+
223+
expect(root.getRenderedOutput().toJSX()).toEqual(
224+
<rn-view
225+
accessible="true"
226+
accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:null}"
227+
/>,
228+
);
229+
});
230+
231+
it('does not crash with an unresolvable PlatformColor', () => {
232+
const root = Fantom.createRoot();
233+
234+
Fantom.runTask(() => {
235+
root.render(
236+
<Pressable
237+
android_ripple={{
238+
color: PlatformColor('?attr/doesNotExist'),
239+
alpha: 0.5,
240+
}}
241+
/>,
242+
);
243+
});
244+
245+
expect(root.getRenderedOutput().toJSX()).toEqual(
246+
<rn-view
247+
accessible="true"
248+
accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:null}"
249+
/>,
250+
);
251+
});
126252
});
127253

128254
describe('children', () => {

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

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)