Skip to content

Commit d6042d2

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Add Fantom integration tests for ActivityIndicator (#55767)
Summary: Pull Request resolved: #55767 Add new Fantom integration tests for ActivityIndicator, achieving 100% line coverage for ActivityIndicator.js (from 0%). Changelog: [Internal] Reviewed By: CalixTang Differential Revision: D94360957 fbshipit-source-id: 1312e45bdf0ed9cf6c337b101b83c7b9e456c4d1
1 parent 4d96fb5 commit d6042d2

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
*/
10+
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
13+
import ensureInstance from '../../../../src/private/__tests__/utilities/ensureInstance';
14+
import * as Fantom from '@react-native/fantom';
15+
import * as React from 'react';
16+
import {createRef} from 'react';
17+
import {ActivityIndicator} from 'react-native';
18+
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
19+
20+
describe('<ActivityIndicator>', () => {
21+
describe('props', () => {
22+
describe('size', () => {
23+
it('defaults to "small" (20x20)', () => {
24+
const root = Fantom.createRoot();
25+
26+
Fantom.runTask(() => {
27+
root.render(<ActivityIndicator />);
28+
});
29+
30+
expect(root.getRenderedOutput().toJSX()).toEqual(
31+
<rn-androidProgressBar height="20.000000" width="20.000000" />,
32+
);
33+
});
34+
35+
it('renders with size "small"', () => {
36+
const root = Fantom.createRoot();
37+
38+
Fantom.runTask(() => {
39+
root.render(<ActivityIndicator size="small" />);
40+
});
41+
42+
expect(root.getRenderedOutput().toJSX()).toEqual(
43+
<rn-androidProgressBar height="20.000000" width="20.000000" />,
44+
);
45+
});
46+
47+
it('renders with size "large" (36x36)', () => {
48+
const root = Fantom.createRoot();
49+
50+
Fantom.runTask(() => {
51+
root.render(<ActivityIndicator size="large" />);
52+
});
53+
54+
expect(root.getRenderedOutput().toJSX()).toEqual(
55+
<rn-androidProgressBar height="36.000000" width="36.000000" />,
56+
);
57+
});
58+
59+
it('renders with numeric size on Android', () => {
60+
const root = Fantom.createRoot();
61+
62+
Fantom.runTask(() => {
63+
root.render(<ActivityIndicator size={48} />);
64+
});
65+
66+
expect(root.getRenderedOutput().toJSX()).toEqual(
67+
<rn-androidProgressBar height="48.000000" width="48.000000" />,
68+
);
69+
});
70+
});
71+
72+
describe('color', () => {
73+
it('renders an AndroidProgressBar when color is set', () => {
74+
const root = Fantom.createRoot();
75+
76+
Fantom.runTask(() => {
77+
root.render(<ActivityIndicator color="red" />);
78+
});
79+
80+
// Color is a native prop not serialized as a view attribute,
81+
// but the component still renders correctly
82+
expect(root.getRenderedOutput().toJSX()).toEqual(
83+
<rn-androidProgressBar height="20.000000" width="20.000000" />,
84+
);
85+
});
86+
});
87+
88+
describe('animating', () => {
89+
it('defaults to true', () => {
90+
const root = Fantom.createRoot();
91+
92+
Fantom.runTask(() => {
93+
root.render(<ActivityIndicator />);
94+
});
95+
96+
// Component renders normally when animating (default)
97+
expect(root.getRenderedOutput().toJSX()).toEqual(
98+
<rn-androidProgressBar height="20.000000" width="20.000000" />,
99+
);
100+
});
101+
102+
it('renders when animating is false', () => {
103+
const root = Fantom.createRoot();
104+
105+
Fantom.runTask(() => {
106+
root.render(<ActivityIndicator animating={false} />);
107+
});
108+
109+
// Component still renders when not animating
110+
expect(root.getRenderedOutput().toJSX()).toEqual(
111+
<rn-androidProgressBar height="20.000000" width="20.000000" />,
112+
);
113+
});
114+
});
115+
116+
describe('style', () => {
117+
it('applies wrapper View style', () => {
118+
const root = Fantom.createRoot();
119+
120+
Fantom.runTask(() => {
121+
root.render(<ActivityIndicator style={{opacity: 0.5}} />);
122+
});
123+
124+
expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual(
125+
<rn-view opacity="0.5">
126+
<rn-androidProgressBar />
127+
</rn-view>,
128+
);
129+
});
130+
});
131+
132+
describe('accessibilityLabel', () => {
133+
it('is propagated to the native component', () => {
134+
const root = Fantom.createRoot();
135+
136+
Fantom.runTask(() => {
137+
root.render(
138+
<ActivityIndicator accessibilityLabel="Loading content" />,
139+
);
140+
});
141+
142+
expect(
143+
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
144+
).toEqual(
145+
<rn-androidProgressBar accessibilityLabel="Loading content" />,
146+
);
147+
});
148+
});
149+
150+
describe('testID', () => {
151+
it('is propagated to the native component', () => {
152+
const root = Fantom.createRoot();
153+
154+
Fantom.runTask(() => {
155+
root.render(<ActivityIndicator testID="loading-spinner" />);
156+
});
157+
158+
expect(root.getRenderedOutput({props: ['testID']}).toJSX()).toEqual(
159+
<rn-androidProgressBar testID="loading-spinner" />,
160+
);
161+
});
162+
});
163+
});
164+
165+
describe('ref', () => {
166+
it('provides a valid ReactNativeElement instance', () => {
167+
const elementRef =
168+
createRef<React.ElementRef<typeof ActivityIndicator>>();
169+
const root = Fantom.createRoot();
170+
171+
Fantom.runTask(() => {
172+
root.render(<ActivityIndicator ref={elementRef} />);
173+
});
174+
175+
expect(elementRef.current).toBeInstanceOf(ReactNativeElement);
176+
});
177+
178+
it('has the correct tag name', () => {
179+
const elementRef =
180+
createRef<React.ElementRef<typeof ActivityIndicator>>();
181+
const root = Fantom.createRoot();
182+
183+
Fantom.runTask(() => {
184+
root.render(<ActivityIndicator ref={elementRef} />);
185+
});
186+
187+
const element = ensureInstance(elementRef.current, ReactNativeElement);
188+
expect(element.tagName).toBe('RN:AndroidProgressBar');
189+
});
190+
});
191+
});

0 commit comments

Comments
 (0)