Skip to content

Commit 5f8807a

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add public API test (#53096)
Summary: Pull Request resolved: #53096 Changelog: [Internal] As title Reviewed By: rshest Differential Revision: D79726634 fbshipit-source-id: 1474cbfb635250e06f4f898338ef0874bc488ed1
1 parent 026e22b commit 5f8807a

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 type {HostInstance} from 'react-native';
14+
15+
import * as Fantom from '@react-native/fantom';
16+
import * as React from 'react';
17+
import {createRef} from 'react';
18+
import {ImageBackground} from 'react-native';
19+
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
20+
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
21+
22+
describe('<ImageBackground>', () => {
23+
describe('props', () => {
24+
describe('ImageProps', () => {
25+
it('can have local source', () => {
26+
const root = Fantom.createRoot();
27+
28+
Fantom.runTask(() => {
29+
root.render(<ImageBackground source={require('./img/img1.png')} />);
30+
});
31+
32+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
33+
<rn-image
34+
source-scale="1"
35+
source-size="{1, 1}"
36+
source-type="local"
37+
source-uri="file://drawable-mdpi/packages_reactnative_libraries_image___tests___img_img1.png"
38+
/>,
39+
);
40+
});
41+
42+
it('can have remote source', () => {
43+
const root = Fantom.createRoot();
44+
45+
Fantom.runTask(() => {
46+
root.render(
47+
<ImageBackground
48+
source={{
49+
uri: 'https://reactnative.dev/img/tiny_logo.png',
50+
width: 100,
51+
height: 100,
52+
scale: 2,
53+
cache: 'only-if-cached',
54+
method: 'POST',
55+
body: 'name=React+Native',
56+
headers: {
57+
Authorization: 'Basic RandomString',
58+
},
59+
}}
60+
/>,
61+
);
62+
});
63+
64+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
65+
<rn-image
66+
source-body="name=React+Native"
67+
source-cache="only-if-cached"
68+
source-header-Authorization="Basic RandomString"
69+
source-method="POST"
70+
source-scale="2"
71+
source-size="{100, 100}"
72+
source-type="remote"
73+
source-uri="https://reactnative.dev/img/tiny_logo.png"
74+
/>,
75+
);
76+
});
77+
78+
it('can have srcSet', () => {
79+
const root = Fantom.createRoot();
80+
81+
Fantom.runTask(() => {
82+
root.render(
83+
<ImageBackground srcSet="https://reactnative.dev/img/tiny_logo.png 1x, https://reactnative.dev/img/header_logo.svg 2x" />,
84+
);
85+
});
86+
87+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
88+
<rn-image
89+
source-1x-scale="1"
90+
source-1x-type="remote"
91+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
92+
source-2x-scale="2"
93+
source-2x-type="remote"
94+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
95+
/>,
96+
);
97+
});
98+
});
99+
100+
describe('style', () => {
101+
it('can be set', () => {
102+
const root = Fantom.createRoot();
103+
104+
Fantom.runTask(() => {
105+
root.render(<ImageBackground style={{width: 100, height: 100}} />);
106+
});
107+
108+
expect(
109+
root.getRenderedOutput({props: ['width|height']}).toJSX(),
110+
).toEqual(<rn-image width="100.000000" height="100.000000" />);
111+
});
112+
});
113+
});
114+
115+
describe('ref', () => {
116+
it('Allows to set a reference to the inner `Image` component', () => {
117+
const elementRef = createRef<HostInstance>();
118+
const root = Fantom.createRoot();
119+
120+
Fantom.runTask(() => {
121+
root.render(<ImageBackground imageRef={elementRef} />);
122+
});
123+
124+
const image = ensureInstance(elementRef.current, ReactNativeElement);
125+
expect(image.tagName).toBe('RN:Image');
126+
});
127+
});
128+
});

0 commit comments

Comments
 (0)