Skip to content

Commit 8e5aa53

Browse files
committed
add conditional transformations
1 parent d7bc03a commit 8e5aa53

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

spec/cloudinary_spec.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe("cloudinary", function () {
5252
$rootScope.testPublicId = 'barfoo';
5353
$rootScope.$digest();
5454
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/barfoo\"");
55-
5655
});
5756
});
5857
describe("html-width", function(){
@@ -79,8 +78,65 @@ describe("cloudinary", function () {
7978
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/barfoo\"");
8079

8180
});
81+
});
82+
83+
describe ('conditional transformation', function(){
84+
it ('should add if (condition) to the result URL', function() {
85+
// Compile a piece of HTML containing the directive
86+
var element = $compile("<div><cl-image public_id='foobar' if='w_gt_200' width='100' crop='scale'/></div>")($rootScope);
87+
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
88+
$rootScope.$digest();
89+
90+
// Check that the compiled element contains the templated content
91+
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/if_w_gt_200,c_scale,w_100/foobar\"");
92+
});
93+
94+
it ('should add if (condition) to the result URL', function() {
95+
// Compile a piece of HTML containing the directive
96+
var element = $compile("<div><cl-image public_id='foobar'><cl-transformation if='w_gt_200' width='100' crop='scale'/></cl-image></div>")($rootScope);
97+
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
98+
$rootScope.$digest();
99+
100+
// Check that the compiled element contains the templated content
101+
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/if_w_gt_200,c_scale,w_100/foobar\"");
102+
});
103+
104+
it ('should add if (condition) to the result URL', function() {
105+
// Compile a piece of HTML containing the directive
106+
var element = $compile("<div>" +
107+
"<cl-image public_id='foobar'>" +
108+
"<cl-transformation if='w_gt_200'/>"+
109+
"<cl-transformation width='100' crop='scale'/>" +
110+
"<cl-transformation height='100' crop='fill'/>"+
111+
"<cl-transformation if='end'/>" +
112+
"</cl-image></div>")($rootScope);
113+
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
114+
$rootScope.$digest();
115+
116+
// Check that the compiled element contains the templated content
117+
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/if_w_gt_200/c_scale,w_100/c_fill,h_100/if_end/foobar\"");
118+
});
119+
120+
it ('should add if (condition) to the result URL', function() {
121+
// Compile a piece of HTML containing the directive
122+
var element = $compile("<div>" +
123+
"<cl-image public_id='foobar'>" +
124+
"<cl-transformation if='w_gt_200'/>"+
125+
"<cl-transformation width='100' crop='scale'/>" +
126+
"<cl-transformation height='100' crop='fill'/>"+
127+
"<cl-transformation if='else'/>" +
128+
"<cl-transformation width='200' crop='fill'/>" +
129+
"<cl-transformation height='200' crop='fit'/>"+
130+
"<cl-transformation if='end'/>" +
131+
"</cl-image></div>")($rootScope);
132+
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
133+
$rootScope.$digest();
82134

135+
// Check that the compiled element contains the templated content
136+
expect(element.html()).toMatch("src=\"https?://res\.cloudinary\.com/" + CLOUD_NAME + "/image/upload/if_w_gt_200/c_scale,w_100/c_fill,h_100/if_else/c_fill,w_200/c_fit,h_200/if_end/foobar\"");
137+
});
83138
});
139+
84140
describe("responsive", function () {
85141
var testWindow, tabImage2, image1;
86142
beforeAll(function (done) {

0 commit comments

Comments
 (0)