11import React from 'react' ;
2- import { expect } from 'chai' ;
3- import { mount } from 'enzyme' ;
4- import setProps from './setProps' ;
2+ import { expect } from 'chai' ;
3+ import { mount } from 'enzyme' ;
54import cloudinary from './cloudinary-proxy' ;
6- const { Image, CloudinaryContext, Transformation} = cloudinary ;
5+
6+ const { Image, CloudinaryContext} = cloudinary ;
77
88describe ( 'CloudinaryContext' , ( ) => {
9- it ( "should pass properties to children" , function ( ) {
9+ it ( "should pass properties to children" , function ( ) {
1010 let tag = mount (
1111 < CloudinaryContext className = "root" cloudName = "demo" >
12- < Image publicId = "sample" />
12+ < Image publicId = "sample" />
1313 </ CloudinaryContext >
1414 ) ;
1515
@@ -20,48 +20,48 @@ describe('CloudinaryContext', () => {
2020 expect ( img . instance ( ) . state . url ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/sample" ) ;
2121 } ) ;
2222
23- it ( "should render without div" , function ( ) {
23+ it ( "should render without div" , function ( ) {
2424 let tag = mount (
2525 < CloudinaryContext className = "root" cloudName = "demo" includeOwnBody = { true } >
26- < Image publicId = "sample" />
26+ < Image publicId = "sample" />
2727 </ CloudinaryContext >
2828 ) ;
2929
3030 expect ( tag . html ( ) . startsWith ( "<div" ) ) . to . equal ( false ) ;
3131 } ) ;
32- it ( "should render with div" , function ( ) {
32+ it ( "should render with div" , function ( ) {
3333 let tag = mount (
3434 < CloudinaryContext className = "root" cloudName = "demo" includeOwnBody = { false } >
35- < Image publicId = "sample" />
35+ < Image publicId = "sample" />
3636 </ CloudinaryContext >
3737 ) ;
3838
3939 expect ( tag . html ( ) . startsWith ( "<div" ) ) . to . equal ( true ) ;
4040 } ) ;
4141
42- it ( "should pass properties to children with snake case" , function ( ) {
43- let tag = mount (
44- < CloudinaryContext className = "root" cloudName = "demo" fetch_format = "auto" >
45- < Image publicId = "sample" />
46- </ CloudinaryContext >
47- ) ;
42+ it ( "should pass properties to children with snake case" , function ( ) {
43+ let tag = mount (
44+ < CloudinaryContext className = "root" cloudName = "demo" fetch_format = "auto" >
45+ < Image publicId = "sample" />
46+ </ CloudinaryContext >
47+ ) ;
4848
49- let img = tag . find ( "div" ) . childAt ( 0 ) ;
50- expect ( img . instance ( ) . state . url ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/f_auto/sample" ) ;
49+ let img = tag . find ( "div" ) . childAt ( 0 ) ;
50+ expect ( img . instance ( ) . state . url ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/f_auto/sample" ) ;
5151 } ) ;
5252
53- it ( "should pass properties to children with kebab case" , function ( ) {
54- let tag = mount (
55- < CloudinaryContext className = "root" cloudName = "demo" fetch-format = "auto" >
56- < Image publicId = "sample" />
57- </ CloudinaryContext >
58- ) ;
53+ it ( "should pass properties to children with kebab case" , function ( ) {
54+ let tag = mount (
55+ < CloudinaryContext className = "root" cloudName = "demo" fetch-format = "auto" >
56+ < Image publicId = "sample" />
57+ </ CloudinaryContext >
58+ ) ;
5959
60- let img = tag . find ( "div" ) . childAt ( 0 ) ;
61- expect ( img . instance ( ) . state . url ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/f_auto/sample" ) ;
60+ let img = tag . find ( "div" ) . childAt ( 0 ) ;
61+ expect ( img . instance ( ) . state . url ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/f_auto/sample" ) ;
6262 } ) ;
6363
64- it ( "should remove Cloudinary custom properties from CloudinaryContext component" , function ( ) {
64+ it ( "should remove Cloudinary custom properties from CloudinaryContext component" , function ( ) {
6565 let html = mount (
6666 < CloudinaryContext
6767 className = "root"
@@ -71,7 +71,7 @@ describe('CloudinaryContext', () => {
7171 role = "tab"
7272 aria-live = "polite"
7373 >
74- < Image publicId = "sample" />
74+ < Image publicId = "sample" />
7575 </ CloudinaryContext >
7676 ) ;
7777
@@ -86,35 +86,28 @@ describe('CloudinaryContext', () => {
8686 expect ( contextDiv . find ( 'img' ) . prop ( "src" ) ) . to . equal ( "https://res.cloudinary.com/demo/image/upload/q_auto/sample" ) ;
8787 } ) ;
8888
89- it ( "should allow chained Contexts" , function ( ) {
89+ it ( "should allow chained Contexts" , function ( ) {
9090 let tag = mount (
9191 < CloudinaryContext cloudName = "demo" >
9292 < CloudinaryContext width = "100" crop = "scale" >
93- < Image publicId = "sample" />
93+ < Image publicId = "sample" />
9494 </ CloudinaryContext >
9595 </ CloudinaryContext >
9696 ) ;
9797 expect (
9898 tag . find ( 'img' ) . prop ( 'src' )
9999 ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/c_scale,w_100/sample" ) ;
100100 } ) ;
101- it ( "updates transformations dynamically on context change" , function ( ) {
102- const cloudName1 = "demo" ;
103- const cloudName2 = "demo2" ;
104101
105- let tag = mount (
106- < CloudinaryContext cloudName = { cloudName1 } >
107- < Image publicId = "sample" >
108- < Transformation width = "100" crop = "scale" />
109- </ Image >
102+ it ( "should update url on context change" , function ( ) {
103+ const tag = mount (
104+ < CloudinaryContext cloudName = "demo" >
105+ < Image publicId = "sample" />
110106 </ CloudinaryContext >
111107 ) ;
112108
113- expect ( tag . find ( 'img' ) . getElement ( ) . props . src ) . to . equal ( `http://res.cloudinary.com/${ cloudName1 } /image/upload/c_scale,w_100/sample` ) ;
114-
115- tag . setProps ( { cloudName : cloudName2 } ) ;
116- setProps ( tag , { cloudName : cloudName2 } ) . then ( tag => {
117- expect ( tag . find ( 'img' ) . getElement ( ) . props . src ) . to . equal ( `http://res.cloudinary.com/${ cloudName2 } /image/upload/c_scale,w_100/sample` ) ;
118- } ) ;
109+ expect ( tag . find ( 'img' ) . prop ( 'src' ) ) . to . equal ( "http://res.cloudinary.com/demo/image/upload/sample" ) ;
110+ tag . setProps ( { cloudName : "demo2" } ) . update ( ) ;
111+ expect ( tag . find ( 'img' ) . prop ( 'src' ) ) . to . equal ( "http://res.cloudinary.com/demo2/image/upload/sample" ) ;
119112 } ) ;
120113} ) ;
0 commit comments