Skip to content

Commit 4ba8671

Browse files
Feature/add mandatory qualifiers to effect shear (#308)
* Add mandatory(constructor) qualifiers, x and y, to Reshape.shear
1 parent 3db4e3a commit 4ba8671

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

__TESTS__/unit/actions/Reshape.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe('Tests for Transformation Action -- Cutter', () => {
5757
expect(url).toBe('e_distort:arc:200');
5858
});
5959

60-
it('Shears an image', () => {
60+
it('Shears an image with constructor arguments', () => {
6161
const url = createNewImage()
62-
.reshape(Reshape.shear().skewX(100).skewY(200))
62+
.reshape(Reshape.shear(100, 200))
6363
.toString();
6464

6565
expect(url).toBe('e_shear:100:200');

__TESTS__/unit/urlConfig.test.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import IURLConfig from "../../src/config/interfaces/Config/IURLConfig";
33
import {CloudinaryImage} from "../../src/assets/CloudinaryImage";
44
import {Resize} from "../../src/actions/resize";
55
import {createNewImage} from "../TestUtils/createCloudinaryImage";
6+
import URLConfig from "../../src/config/URLConfig";
67

78

89
/**
@@ -17,20 +18,20 @@ function createURLFromConfig(urlConfig: IURLConfig) {
1718

1819

1920
describe('It tests a combination of Cloudinary URL and Configuration', () => {
20-
it ('Generates a URL', () => {
21+
it('Generates a URL', () => {
2122
const url = createNewImage('my_image')
2223
.toURL();
2324

2425
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/my_image');
2526
});
2627

27-
it ('Throw error when config is invalid', () => {
28+
it('Throw error when config is invalid', () => {
2829
expect(() => {
2930
new CloudinaryImage('my_image').toURL(); // missing cloudName should throw error
3031
}).toThrow();
3132
});
3233

33-
it ('Generates a URL with transforamtions', () => {
34+
it('Generates a URL with transforamtions', () => {
3435
const url = createNewImage()
3536
.resize(Resize.fill(100, 100))
3637
.setPublicID('sample')
@@ -39,13 +40,14 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
3940
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/c_fill,h_100,w_100/sample');
4041
});
4142

42-
it ('Shows a use-case for global configuration', () => {
43+
it('Shows a use-case for global configuration', () => {
4344
//
4445
/**
4546
* We can implement this "wrapper", or instruct our customers how to implement it.
4647
*/
4748
class MyGlobalCloudinary {
4849
public cloudinaryConfig: ICloudinaryConfigurations;
50+
4951
// Constructor accepts a cloudinary configuration
5052
constructor(cloudinaryConfig: ICloudinaryConfigurations) {
5153
this.cloudinaryConfig = cloudinaryConfig;
@@ -80,37 +82,36 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
8082
});
8183

8284

83-
8485
it('Secure by default', () => {
8586
const url = createURLFromConfig({});
8687
expect(url).toContain('https://res.cloudinary.com/demo');
8788
});
8889

8990
it('Supports secure:false', () => {
9091
const url = createURLFromConfig({
91-
secure:false
92+
secure: false
9293
});
9394
expect(url).toContain('http://res.cloudinary.com/demo');
9495
});
9596

9697
it('Support cname with secure false', () => {
9798
const url = createURLFromConfig({
98-
cname:'hello.com',
99+
cname: 'hello.com',
99100
secure: false
100101
});
101102
expect(url).toContain('http://hello.com/demo');
102103
});
103104

104105
it('Support secureDistribution with secure true', () => {
105106
const url = createURLFromConfig({
106-
secureDistribution:'foobar.com'
107+
secureDistribution: 'foobar.com'
107108
});
108109
expect(url).toContain('https://foobar.com/demo');
109110
});
110111

111112
it('Support private CDN with secure true', () => {
112113
const url = createURLFromConfig({
113-
privateCdn:true
114+
privateCdn: true
114115
});
115116
expect(url).toContain(`https://demo-res.cloudinary.com/image/upload`);
116117
});
@@ -125,20 +126,43 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
125126
});
126127

127128
it('Generates a URL with version in the public ID', () => {
128-
const img = createNewImage('v1234/foo/sample', {cloudName: 'demo'}, { forceVersion: true});
129+
const img = createNewImage('v1234/foo/sample', {cloudName: 'demo'}, {forceVersion: true});
129130

130131
expect(img.toURL()).toContain('https://res.cloudinary.com/demo/image/upload/v1234/foo/sample');
131132
});
132133

133134
it('Generates a URL with V1', () => {
134-
const img = createNewImage('foo/sample', {cloudName: 'demo'}, { forceVersion: true});
135+
const img = createNewImage('foo/sample', {cloudName: 'demo'}, {forceVersion: true});
135136

136137
expect(img.toURL()).toContain('https://res.cloudinary.com/demo/image/upload/v1/foo/sample');
137138
});
138139

139140
it('Generates a URL without V1', () => {
140-
const img = createNewImage('foo/sample', {cloudName: 'demo'}, { forceVersion: false});
141+
const img = createNewImage('foo/sample', {cloudName: 'demo'}, {forceVersion: false});
141142

142143
expect(img.toURL()).toContain('https://res.cloudinary.com/demo/image/upload/foo/sample');
143144
});
145+
146+
it('Sets attributes using setters', () => {
147+
const conf = new URLConfig({});
148+
149+
conf
150+
.setCname('foo')
151+
.setForceVersion(true)
152+
.setLongUrlSignature(true)
153+
.setPrivateCdn(true)
154+
.setSecure(true)
155+
.setShorten(true)
156+
.setSignUrl(true)
157+
.setUseRootPath(true);
158+
159+
expect(conf.cname).toBe('foo');
160+
expect(conf.forceVersion).toBe(true);
161+
expect(conf.longUrlSignature).toBe(true);
162+
expect(conf.privateCdn).toBe(true);
163+
expect(conf.secure).toBe(true);
164+
expect(conf.shorten).toBe(true);
165+
expect(conf.signUrl).toBe(true);
166+
expect(conf.useRootPath).toBe(true);
167+
});
144168
});

src/actions/reshape.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ function distort(coordinates: IDistortCoordinates): DistortAction {
5454

5555
/**
5656
* @description Skews the image according to the two specified values in degrees.
57+
* @param {number} x Skews the image according to the two specified values in degrees. (X and Y)
58+
* @param {number} y Skews the image according to the two specified values in degrees. (X and Y)
5759
* @memberOf Actions.Reshape
5860
*/
59-
function shear(): ShearAction {
60-
return new ShearAction();
61+
function shear(x: number, y: number): ShearAction {
62+
return new ShearAction(x, y);
6163
}
6264

6365
/**

src/actions/reshape/Shear.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class ShearAction extends Action {
99
private _x: number;
1010
private _y: number;
1111

12+
constructor(x: number, y:number) {
13+
super();
14+
this.skewX(x);
15+
this.skewY(y);
16+
}
1217
/**
1318
* @param {number} x Skews the image according to the two specified values in degrees. (X and Y)
1419
*/

0 commit comments

Comments
 (0)