@@ -17,4 +17,38 @@ describe('Image', () => {
1717 expect ( tag . type ( ) ) . to . equal ( "img" ) ;
1818 expect ( tag . state ( "url" ) ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/c_scale,w_300/sample" ) ;
1919 } ) ;
20+ it ( "should set event handlers" , function ( ) {
21+ let width = 300 ;
22+ let tag = shallow ( < Image publicId = "sample" cloudName = "demo" width = { width } crop = "scale" onLoad = { ( ) => "foo" } /> ) ;
23+ expect ( tag . type ( ) ) . to . equal ( "img" ) ;
24+ expect ( tag . state ( "url" ) ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/c_scale,w_300/sample" ) ;
25+ expect ( tag . props ( ) . onLoad ( ) ) . to . equal ( "foo" )
26+
27+ } ) ;
28+ it ( "should not pass-through Cloudinary attributes" , function ( ) {
29+ let width = 300 ;
30+
31+ let tag2 = mount ( < div width = "300" > < Image publicId = "sample" cloudName = "demo" width = "auto" crop = "scale" privateCdn = "private" defaultImage = "foobar" responsive responsiveUseBreakpoints /> </ div > ) ;
32+ let tag = shallow ( < Image publicId = "sample" cloudName = "demo" width = "auto" crop = "scale" privateCdn = "private" defaultImage = "foobar" responsive responsiveUseBreakpoints /> ) ;
33+ expect ( tag . type ( ) ) . to . equal ( "img" ) ;
34+ expect ( tag . state ( "url" ) ) . to . equal ( "" ) ;
35+ expect ( tag . props ( ) ) . to . have . property ( 'src' ) ;
36+
37+ // We are checking for both snake_case and camelCase keys
38+ expect ( tag . props ( ) ) . not . to . have . property ( 'privateCdn' ) ;
39+ expect ( tag . props ( ) ) . not . to . have . property ( 'private_cdn' ) ;
40+ expect ( tag . props ( ) ) . not . to . have . property ( 'defaultImage' ) ;
41+ expect ( tag . props ( ) ) . not . to . have . property ( 'default_image' ) ;
42+ expect ( tag . props ( ) ) . not . to . have . property ( 'responsiveUseBreakpoints' ) ;
43+ expect ( tag . props ( ) ) . not . to . have . property ( 'responsive_use_breakpoints' ) ;
44+ tag = shallow ( < Image publicId = "sample" cloudName = "demo" width = { width } crop = "scale" private_cdn = "private" default_image = "foobar" /> ) ;
45+ expect ( tag . type ( ) ) . to . equal ( "img" ) ;
46+ expect ( tag . state ( "url" ) ) . to . equal ( "http://demo-res.cloudinary.com/image/upload/c_scale,d_foobar,w_300/sample" ) ;
47+ expect ( tag . props ( ) ) . to . have . property ( 'src' ) ;
48+ expect ( tag . props ( ) ) . not . to . have . property ( 'privateCdn' ) ;
49+ expect ( tag . props ( ) ) . not . to . have . property ( 'private_cdn' ) ;
50+ expect ( tag . props ( ) ) . not . to . have . property ( 'defaultImage' ) ;
51+ expect ( tag . props ( ) ) . not . to . have . property ( 'default_image' ) ;
52+
53+ } ) ;
2054} ) ;
0 commit comments