Skip to content

Commit 6c340ba

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add source tests (facebook#53074)
Summary: Pull Request resolved: facebook#53074 Changelog: [Internal] Add tests for source prop of Image. Reviewed By: rshest Differential Revision: D79605165
1 parent 33d35dd commit 6c340ba

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
@@ -328,6 +328,107 @@ describe('<Image>', () => {
328328
},
329329
);
330330
});
331+
332+
describe('source', () => {
333+
it('can be set to a local image', () => {
334+
const root = Fantom.createRoot();
335+
336+
Fantom.runTask(() => {
337+
root.render(<Image source={require('./img/img1.png')} />);
338+
});
339+
340+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
341+
<rn-image
342+
source-scale="1"
343+
source-size="{1, 1}"
344+
source-type="local"
345+
source-uri="file://drawable-mdpi/packages_reactnative_libraries_image___tests___img_img1.png"
346+
/>,
347+
);
348+
});
349+
350+
it('can be set to a remote image', () => {
351+
const root = Fantom.createRoot();
352+
353+
Fantom.runTask(() => {
354+
root.render(
355+
<Image
356+
source={{
357+
uri: 'https://reactnative.dev/img/tiny_logo.png',
358+
width: 100,
359+
height: 100,
360+
scale: 2,
361+
cache: 'only-if-cached',
362+
method: 'POST',
363+
body: 'name=React+Native',
364+
headers: {
365+
Authorization: 'Basic RandomString',
366+
},
367+
}}
368+
/>,
369+
);
370+
});
371+
372+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
373+
<rn-image
374+
source-body="name=React+Native"
375+
source-cache="only-if-cached"
376+
source-header-Authorization="Basic RandomString"
377+
source-method="POST"
378+
source-scale="2"
379+
source-size="{100, 100}"
380+
source-type="remote"
381+
source-uri="https://reactnative.dev/img/tiny_logo.png"
382+
/>,
383+
);
384+
});
385+
386+
it('can be set to a list of remote images', () => {
387+
const root = Fantom.createRoot();
388+
389+
Fantom.runTask(() => {
390+
root.render(
391+
<Image
392+
source={[
393+
{
394+
uri: 'https://reactnative.dev/img/tiny_logo.png',
395+
scale: 1,
396+
headers: {
397+
Authorization: 'Basic RandomString',
398+
},
399+
},
400+
{
401+
uri: 'https://reactnative.dev/img/medium_logo.png',
402+
scale: 2,
403+
cache: 'only-if-cached',
404+
},
405+
{
406+
uri: 'https://reactnative.dev/img/large_logo.png',
407+
scale: 3,
408+
method: 'POST',
409+
},
410+
]}
411+
/>,
412+
);
413+
});
414+
415+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
416+
<rn-image
417+
source-1x-header-Authorization="Basic RandomString"
418+
source-1x-scale="1"
419+
source-1x-type="remote"
420+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
421+
source-2x-cache="only-if-cached"
422+
source-2x-scale="2"
423+
source-2x-type="remote"
424+
source-2x-uri="https://reactnative.dev/img/medium_logo.png"
425+
source-3x-method="POST"
426+
source-3x-type="remote"
427+
source-3x-uri="https://reactnative.dev/img/large_logo.png"
428+
/>,
429+
);
430+
});
431+
});
331432
});
332433

333434
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)