Skip to content

Commit 997e665

Browse files
author
Amir Tocker
committed
Refactor. Add tests. Add index.js.
1 parent 119e68e commit 997e665

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import CloudinaryContext from './src/components/CloudinaryContext';
3+
import Image from './src/components/Image';
4+
import Transformation from './src/components/Transformation';
5+
import Video from './src/components/Video';
6+
7+
export { CloudinaryContext, Image, Transformation, Video};

src/Util/Util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import debounce from './debounce';
22
import firstDefined from './firstDefined';
33
import closestAbove from './closestAbove';
44

5-
module.exports = {
5+
let Util = {
66
debounce, firstDefined, closestAbove
77
};
8+
9+
export default Util;

src/components/CloudinaryContext/CloudinaryContext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default class CloudinaryContext extends CloudinaryComponent {
5656
);
5757
}
5858
}
59+
5960
CloudinaryContext.propTypes = CloudinaryComponent.propTypes;
6061
CloudinaryContext.defaultProps = {};
6162
CloudinaryContext.childContextTypes = CloudinaryComponent.contextTypes;

src/components/Image/Image.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import cloudinary, {Util} from 'cloudinary-core';
33
import CloudinaryComponent from '../CloudinaryComponent';
44
import {debounce, firstDefined, closestAbove} from '../../Util';
55

6+
67
export default class Image extends CloudinaryComponent {
78
constructor(props, context) {
9+
function defaultBreakpoints(width, steps = 100) {
10+
return steps * Math.ceil(width / steps);
11+
}
12+
813
super(props, context);
914
let options = CloudinaryComponent.normalizeOptions(context, props);
1015
this.handleResize = this.handleResize.bind(this);
@@ -211,7 +216,3 @@ Image.defaultProps = {};
211216
Image.contextTypes = CloudinaryComponent.contextTypes;
212217
Image.propTypes = CloudinaryComponent.propTypes;
213218

214-
function defaultBreakpoints(width, steps = 100) {
215-
return steps * Math.ceil(width / steps);
216-
}
217-

test/ContextTest.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import { expect } from 'chai';
3+
import { shallow, mount, render } from 'enzyme';
4+
import Image from '../src/components/Image';
5+
import Transformation from '../src/components/Transformation';
6+
import CloudinaryContext from '../src/components/CloudinaryContext';
7+
8+
9+
describe('CloudinaryContext', () => {
10+
beforeEach(() => {
11+
});
12+
it("should pass properties to children", function() {
13+
let tag = mount(
14+
<CloudinaryContext cloudName="demo">
15+
<Image publicId="sample" />
16+
</CloudinaryContext>
17+
);
18+
19+
expect(tag.html().startsWith("<div")).to.equal(true);
20+
let img = tag.childAt(0);
21+
expect(img.node.state["url"]).to.equal("http://res.cloudinary.com/demo/image/upload/sample");
22+
});
23+
24+
it("should allow chained Contexts", function() {
25+
let tag = mount(
26+
<CloudinaryContext cloudName="demo">
27+
<CloudinaryContext width="100" crop="scale">
28+
<Image publicId="sample"/>
29+
</CloudinaryContext>
30+
</CloudinaryContext>
31+
);
32+
expect(tag.containsMatchingElement(
33+
<img src="http://res.cloudinary.com/demo/image/upload/c_scale,w_100/sample"/>
34+
)).to.equal(true);
35+
});
36+
});

test/TransformationTest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ describe('Transformation', () => {
2121
let tag = shallow(
2222
<Image publicId="sample" cloudName="demo" >
2323
<Transformation width="100" crop="scale"/>
24-
<Transformation width="200" crop="crop"/>
24+
<Transformation width="200" crop="pad">
25+
<Transformation angle="30"/>
26+
</Transformation>
2527
</Image>
2628
);
2729
expect(tag.type()).to.equal("img");
28-
expect(tag.state("url")).to.equal("http://res.cloudinary.com/demo/image/upload/c_scale,w_100/c_crop,w_200/sample");
30+
expect(tag.state("url")).to.equal("http://res.cloudinary.com/demo/image/upload/c_scale,w_100/a_30/c_pad,w_200/sample");
2931
});
3032
});

0 commit comments

Comments
 (0)