File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
22import { Image , ImageProps , View } from 'react-native' ;
33import type { CloudinaryImage } from '@cloudinary/url-gen' ;
44import 'react-native-url-polyfill/auto' ;
5+ import { SDKAnalyticsConstants } from './internal/SDKAnalyticsConstants' ;
56
67interface AdvancedImageProps extends Omit < ImageProps , 'source' > { cldImg : CloudinaryImage ; }
78const AdvancedImage : React . FC < AdvancedImageProps > = ( props ) => {
@@ -11,7 +12,7 @@ const AdvancedImage: React.FC<AdvancedImageProps> = (props) => {
1112 } = props ;
1213 return (
1314 < View >
14- < Image { ...rest } source = { { uri : cldImg . toURL ( ) } } />
15+ < Image { ...rest } source = { { uri : cldImg . toURL ( { trackedAnalytics : SDKAnalyticsConstants } ) } } />
1516 </ View >
1617 ) ;
1718}
Original file line number Diff line number Diff line change 1+ import { SDKAnalyticsConstants } from '../internal/SDKAnalyticsConstants' ;
2+ import { Platform , Image } from 'react-native' ;
3+ import AdvancedImage from '../AdvancedImage' ;
4+ import { CloudinaryImage } from '@cloudinary/url-gen/assets/CloudinaryImage' ;
5+ import { render } from '@testing-library/react-native' ;
6+ import React from 'react' ;
7+
8+ const cloudinaryImage = new CloudinaryImage ( 'sample' , { cloudName : 'demo' } ) ;
9+
10+ describe ( 'analytics' , ( ) => {
11+ beforeEach ( ( ) => {
12+ SDKAnalyticsConstants . sdkSemver = '1.0.0' ;
13+ SDKAnalyticsConstants . techVersion = '10.2.5' ;
14+ } ) ;
15+ it ( 'creates a url with analytics' , ( ) => {
16+ const element = render ( < AdvancedImage cldImg = { cloudinaryImage } > </ AdvancedImage > ) ;
17+ const imageComponent = element . root . findByType ( Image ) ;
18+ expect ( imageComponent . props . source . uri ) . toBe ( cloudinaryImage . toURL ( { trackedAnalytics : SDKAnalyticsConstants } ) ) ;
19+ } ) ;
20+ } ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ import { render } from '@testing-library/react-native';
66import TestRenderer from 'react-test-renderer' ;
77describe ( 'AdvancedImage' , ( ) => {
88 it ( 'should render an Image with the correct URI' , ( ) => {
9- const cldImg = new CloudinaryImage ( 'sample' , { cloudName : 'demo' } ) ;
9+ const cldImg = new CloudinaryImage ( 'sample' , { cloudName : 'demo' } , { analytics : false } ) ;
1010 const component = TestRenderer . create ( < AdvancedImage cldImg = { cldImg } /> ) ;
1111 const imageComponent = component . root . findByType ( Image ) ;
1212 expect ( imageComponent . props . source . uri ) . toBe ( cldImg . toURL ( ) ) ;
1313 } ) ;
1414
1515 it ( 'should forward any other props to the Image' , ( ) => {
16- const cldImg = new CloudinaryImage ( 'sample' , { cloudName : 'demo' } ) ;
16+ const cldImg = new CloudinaryImage ( 'sample' , { cloudName : 'demo' } , { analytics : false } ) ;
1717 const { getByTestId } = render ( < AdvancedImage cldImg = { cldImg } testID = "my-image" /> ) ;
1818 const image = getByTestId ( 'my-image' ) ;
1919 expect ( image ) . toBeTruthy ( ) ;
Original file line number Diff line number Diff line change 1+ import { Platform } from 'react-native' ;
2+
3+ const getReactNativeVersion = ( ) => {
4+ try {
5+ const version = Platform . Version ;
6+ return version . toString ( ) ;
7+ } catch {
8+ return "0.0.0"
9+ }
10+ }
11+
12+ const getSDKVersion = ( ) => {
13+ try {
14+ const SDKVersionPackageJson = require ( 'cloudinary-react-native/package.json' )
15+ if ( SDKVersionPackageJson && SDKVersionPackageJson . version ) {
16+ //return SDKVersionPackageJson.version
17+ return
18+ }
19+ } catch {
20+ return "0.0.0" ;
21+ }
22+ return "0.0.0" ;
23+ }
24+
25+ export const SDKAnalyticsConstants = {
26+ sdkSemver : getSDKVersion ( ) ,
27+ techVersion : getReactNativeVersion ( ) ,
28+ sdkCode : 'P'
29+ } ;
You can’t perform that action at this time.
0 commit comments