Skip to content

Commit 136ed2a

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add Fantom integration test for TouchableNativeFeedback
Summary: Converts the Jest snapshot tests for TouchableNativeFeedback to Fantom integration tests, covering rendering, disabled prop, and accessibilityState merging behavior. Changelog: [Internal] Differential Revision: D94887406
1 parent 1ea6572 commit 136ed2a

2 files changed

Lines changed: 162 additions & 114 deletions

File tree

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
13+
14+
import * as Fantom from '@react-native/fantom';
15+
import * as React from 'react';
16+
import {Text, TouchableNativeFeedback, View} from 'react-native';
17+
18+
describe('<TouchableNativeFeedback>', () => {
19+
describe('displayName', () => {
20+
it('has displayName set to TouchableNativeFeedback', () => {
21+
expect(TouchableNativeFeedback.displayName).toEqual(
22+
'TouchableNativeFeedback',
23+
);
24+
});
25+
});
26+
27+
describe('rendering', () => {
28+
it('renders as a view with accessible="true"', () => {
29+
const root = Fantom.createRoot();
30+
31+
Fantom.runTask(() => {
32+
root.render(
33+
<TouchableNativeFeedback>
34+
<View />
35+
</TouchableNativeFeedback>,
36+
);
37+
});
38+
39+
expect(root.getRenderedOutput({props: ['accessible']}).toJSX()).toEqual(
40+
<rn-view accessible="true" />,
41+
);
42+
});
43+
44+
it('renders with children', () => {
45+
const root = Fantom.createRoot();
46+
47+
Fantom.runTask(() => {
48+
root.render(
49+
<TouchableNativeFeedback>
50+
<View>
51+
<Text>Touchable</Text>
52+
</View>
53+
</TouchableNativeFeedback>,
54+
);
55+
});
56+
57+
expect(root.getRenderedOutput({props: ['accessible']}).toJSX()).toEqual(
58+
<rn-view accessible="true">
59+
<rn-paragraph>Touchable</rn-paragraph>
60+
</rn-view>,
61+
);
62+
});
63+
});
64+
65+
describe('disabled prop', () => {
66+
it('sets accessibilityState disabled to true when disabled={true}', () => {
67+
const root = Fantom.createRoot();
68+
69+
Fantom.runTask(() => {
70+
root.render(
71+
<TouchableNativeFeedback disabled={true}>
72+
<View />
73+
</TouchableNativeFeedback>,
74+
);
75+
});
76+
77+
expect(
78+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
79+
).toEqual(
80+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
81+
);
82+
});
83+
84+
it('sets accessibilityState disabled to true even when accessibilityState is empty', () => {
85+
const root = Fantom.createRoot();
86+
87+
Fantom.runTask(() => {
88+
root.render(
89+
<TouchableNativeFeedback disabled={true} accessibilityState={{}}>
90+
<View />
91+
</TouchableNativeFeedback>,
92+
);
93+
});
94+
95+
expect(
96+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
97+
).toEqual(
98+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
99+
);
100+
});
101+
102+
it('keeps other accessibilityState values when disabled={true}', () => {
103+
const root = Fantom.createRoot();
104+
105+
Fantom.runTask(() => {
106+
root.render(
107+
<TouchableNativeFeedback
108+
disabled={true}
109+
accessibilityState={{checked: true}}>
110+
<View />
111+
</TouchableNativeFeedback>,
112+
);
113+
});
114+
115+
expect(
116+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
117+
).toEqual(
118+
<rn-view accessibilityState="{disabled:true,selected:false,checked:Checked,busy:false,expanded:null}" />,
119+
);
120+
});
121+
122+
it('overwrites accessibilityState disabled=false when disabled={true}', () => {
123+
const root = Fantom.createRoot();
124+
125+
Fantom.runTask(() => {
126+
root.render(
127+
<TouchableNativeFeedback
128+
disabled={true}
129+
accessibilityState={{disabled: false}}>
130+
<View />
131+
</TouchableNativeFeedback>,
132+
);
133+
});
134+
135+
expect(
136+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
137+
).toEqual(
138+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
139+
);
140+
});
141+
142+
it('overwrites accessibilityState disabled=true when disabled={false}', () => {
143+
const root = Fantom.createRoot();
144+
145+
Fantom.runTask(() => {
146+
root.render(
147+
<TouchableNativeFeedback
148+
disabled={false}
149+
accessibilityState={{disabled: true}}>
150+
<View />
151+
</TouchableNativeFeedback>,
152+
);
153+
});
154+
155+
expect(
156+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
157+
).toEqual(
158+
<rn-view accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:null}" />,
159+
);
160+
});
161+
});
162+
});

packages/react-native/Libraries/Components/Touchable/__tests__/TouchableNativeFeedback-test.js

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

0 commit comments

Comments
 (0)