Skip to content

Commit 1b95a04

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add source tests
Summary: Changelog: [Internal] Add tests for source prop of Image. Differential Revision: D79605165
1 parent f562412 commit 1b95a04

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

packages/react-native/Libraries/Image/__tests__/Image-itest.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,107 @@ describe('<Image>', () => {
282282
},
283283
);
284284
});
285+
286+
describe('source', () => {
287+
it('can be set to a local image', () => {
288+
const root = Fantom.createRoot();
289+
290+
Fantom.runTask(() => {
291+
root.render(<Image source={require('./img/img1.png')} />);
292+
});
293+
294+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
295+
<rn-image
296+
source-scale="1"
297+
source-size="{1, 1}"
298+
source-type="local"
299+
source-uri="file://drawable-mdpi/packages_reactnative_libraries_image___tests___img_img1.png"
300+
/>,
301+
);
302+
});
303+
304+
it('can be set to a remote image', () => {
305+
const root = Fantom.createRoot();
306+
307+
Fantom.runTask(() => {
308+
root.render(
309+
<Image
310+
source={{
311+
uri: 'https://reactnative.dev/img/tiny_logo.png',
312+
width: 100,
313+
height: 100,
314+
scale: 2,
315+
cache: 'only-if-cached',
316+
method: 'POST',
317+
body: 'name=React+Native',
318+
headers: {
319+
Authorization: 'Basic RandomString',
320+
},
321+
}}
322+
/>,
323+
);
324+
});
325+
326+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
327+
<rn-image
328+
source-body="name=React+Native"
329+
source-cache="only-if-cached"
330+
source-header-Authorization="Basic RandomString"
331+
source-method="POST"
332+
source-scale="2"
333+
source-size="{100, 100}"
334+
source-type="remote"
335+
source-uri="https://reactnative.dev/img/tiny_logo.png"
336+
/>,
337+
);
338+
});
339+
340+
it('can be set to a list of remote images', () => {
341+
const root = Fantom.createRoot();
342+
343+
Fantom.runTask(() => {
344+
root.render(
345+
<Image
346+
source={[
347+
{
348+
uri: 'https://reactnative.dev/img/tiny_logo.png',
349+
scale: 1,
350+
headers: {
351+
Authorization: 'Basic RandomString',
352+
},
353+
},
354+
{
355+
uri: 'https://reactnative.dev/img/medium_logo.png',
356+
scale: 2,
357+
cache: 'only-if-cached',
358+
},
359+
{
360+
uri: 'https://reactnative.dev/img/large_logo.png',
361+
scale: 3,
362+
method: 'POST',
363+
},
364+
]}
365+
/>,
366+
);
367+
});
368+
369+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
370+
<rn-image
371+
source-1x-header-Authorization="Basic RandomString"
372+
source-1x-scale="1"
373+
source-1x-type="remote"
374+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
375+
source-2x-cache="only-if-cached"
376+
source-2x-scale="2"
377+
source-2x-type="remote"
378+
source-2x-uri="https://reactnative.dev/img/medium_logo.png"
379+
source-3x-method="POST"
380+
source-3x-type="remote"
381+
source-3x-uri="https://reactnative.dev/img/large_logo.png"
382+
/>,
383+
);
384+
});
385+
});
285386
});
286387

287388
describe('ref', () => {

packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ SharedDebugStringConvertibleList ImageProps::getDebugProps() const {
292292
sourcesList = sources[0].getDebugProps("source");
293293
} else if (sources.size() > 1) {
294294
for (const auto& source : sources) {
295-
std::string sourceName = "source@" + react::toString(source.scale) + "x";
295+
std::string sourceName = "source-" + react::toString(source.scale) + "x";
296296
auto debugProps = source.getDebugProps(sourceName);
297297
sourcesList.insert(
298298
sourcesList.end(), debugProps.begin(), debugProps.end());

0 commit comments

Comments
 (0)