1- const CLOUD_NAME = "demo " ;
1+ const CLOUD_NAME = "sdk-test " ;
22
33describe ( "cloudinary" , function ( ) {
44
55 var $compile ,
66 $rootScope ,
7- $provider ;
7+ $window ;
88 beforeEach ( function ( ) {
99 module ( 'cloudinary' ) ;
1010 angular . module ( 'cloudinary' ) . config ( [ 'cloudinaryProvider' , function ( cloudinaryProvider ) {
@@ -18,6 +18,8 @@ describe("cloudinary", function () {
1818 // The injector unwraps the underscores (_) from around the parameter names when matching
1919 $compile = _$compile_ ;
2020 $rootScope = _$rootScope_ ;
21+ $window = window ;
22+ $rootScope . testPublicId = "sample" ;
2123 } ) ) ;
2224 describe ( "clImage" , function ( ) {
2325 it ( 'Adds an inner <img> tag' , function ( ) {
@@ -56,7 +58,9 @@ describe("cloudinary", function () {
5658 describe ( "html-width" , function ( ) {
5759 var element ;
5860 beforeEach ( function ( ) {
61+ $rootScope . testPublicId = "sample" ;
5962 element = $compile ( "<div><cl-image public_id='{{testPublicId}}'/></div>" ) ( $rootScope ) ;
63+ $rootScope . $digest ( ) ;
6064 } ) ;
6165 it ( 'adds a width attribute to the tag if it has a value' , function ( ) {
6266 var element = $compile ( "<div><cl-image public_id='foobar'/></div>" ) ( $rootScope ) ;
@@ -67,19 +71,52 @@ describe("cloudinary", function () {
6771 expect ( element . html ( ) ) . toMatch ( "src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/foobar\"" ) ;
6872 } ) ;
6973 it ( 'modify the src attribute when the public ID attribute changes' , function ( ) {
70- // Compile a piece of HTML containing the directive
7174 $rootScope . testPublicId = 'foobar' ;
72- var element = $compile ( "<div><cl-image public_id='{{testPublicId}}'/></div>" ) ( $rootScope ) ;
73- // fire all the watches, so the scope expression {{1 + 1}} will be evaluated
7475 $rootScope . $digest ( ) ;
75- // Check that the compiled element contains the templated content
7676 expect ( element . html ( ) ) . toMatch ( "src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/foobar\"" ) ;
7777 $rootScope . testPublicId = 'barfoo' ;
7878 $rootScope . $digest ( ) ;
7979 expect ( element . html ( ) ) . toMatch ( "src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/barfoo\"" ) ;
8080
8181 } ) ;
8282
83+ } ) ;
84+ describe ( "responsive" , function ( ) {
85+ var testWindow , tabImage2 , image1 ;
86+ beforeAll ( function ( done ) {
87+ testWindow = window . open ( "/base/spec/responsive-core-test.html" , "Cloudinary test #{(new Date()).toLocaleString()}" , "width=200, height=500" ) ;
88+
89+ testWindow . addEventListener ( 'load' , function ( ) {
90+ image1 = testWindow . document . getElementById ( "image1" ) ;
91+ tabImage2 = testWindow . document . getElementById ( "tabImage2" ) ;
92+ expect ( tabImage2 ) . toBeDefined ( ) ;
93+ done ( ) ;
94+ } ) ;
95+
96+ } ) ;
97+ afterAll ( function ( ) {
98+ testWindow && testWindow . close ( ) ;
99+ } ) ;
100+ it ( 'should enable responsive functionality' , function ( ) {
101+ expect ( tabImage2 . getAttribute ( "src" ) ) . toMatch ( "https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/c_scale,w_200/sample.jpg" ) ;
102+ } ) ;
103+ it ( "should react to a change in the parent's width" , function ( done ) {
104+
105+ var listener = function ( ) {
106+ expect ( tabImage2 . outerHTML ) . toMatch ( "src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/c_scale,w_400/sample.jpg\"" ) ;
107+ done ( ) ;
108+ } ;
109+ // testWindow.addEventListener('resize', listener);
110+ setTimeout ( listener , 2000 ) ;
111+ testWindow . resizeTo ( 350 , 800 ) ;
112+ } ) ;
113+ it ( 'should apply responsive if "width" is not defined' , function ( ) {
114+ element = $compile ( "<div><cl-image public_id='{{testPublicId}}' responsive/></div>" ) ( $rootScope ) ;
115+ $rootScope . $digest ( ) ;
116+ expect ( cloudinary . Util . getData ( element [ 0 ] , "width" ) ) . toBeDefined ( ) ;
117+ expect ( cloudinary . Util . hasClass ( element [ 0 ] , "cld-responsive" ) ) . toBeDefined ( ) ;
118+
119+ } )
83120 } )
84121 } ) ;
85122 describe ( "clSrc" , function ( ) {
0 commit comments