Skip to content

Commit 12c3163

Browse files
authored
fixes #35 from github - video component ignores transformations (#38)
* fixes #35 from github - video component ignores transformations * add test for video component with transformation
1 parent ff7bfe2 commit 12c3163

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"browserify": "^13.1.0",
3434
"browserify-shim": "^3.8.12",
3535
"chai": "^3.5.0",
36+
"chai-string": "^1.4.0",
3637
"enzyme": "^2.4.1",
3738
"jsdom": "^9.8.3",
3839
"mocha": "^3.0.2",

src/components/Video/Video.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ class Video extends CloudinaryComponent {
1818
}
1919

2020
render() {
21-
let {publicId, poster, sourceTypes, fallback, sourceTransformation, ...options} = Object.assign({},
21+
let {publicId, poster, sourceTypes, fallback, sourceTransformation: sourceTransformations, ...options} = Object.assign({},
2222
this.context,
2323
this.props);
24-
sourceTransformation = sourceTransformation || {};
24+
sourceTransformations = sourceTransformations || {};
2525
sourceTypes = sourceTypes || Cloudinary.DEFAULT_VIDEO_PARAMS.source_types;
2626
options = CloudinaryComponent.normalizeOptions(options, {});
2727
let cld = Cloudinary.new(Util.withSnakeCaseKeys(options));
2828
let sources = [];
2929
let tagAttributes = Transformation.new(options).toHtmlAttributes();
30+
let childTransformations = this.getTransformation(options);
3031
if (Util.isPlainObject(poster)) {
3132
let defaults = poster.publicId !== undefined && poster.publicId !== null ? Cloudinary.DEFAULT_IMAGE_PARAMS : DEFAULT_POSTER_OPTIONS;
3233
poster = cld.url(poster.publicId || publicId, Util.defaults({}, Util.withSnakeCaseKeys(poster), defaults));
@@ -40,15 +41,17 @@ class Video extends CloudinaryComponent {
4041

4142
if (Util.isArray(sourceTypes)) {
4243
sources = sourceTypes.map(srcType => {
43-
let transformation = sourceTransformation[srcType] || {};
44-
let src = cld.url(publicId, Util.defaults({}, transformation, {resource_type: 'video', format: srcType}));
44+
let sourceTransformation = sourceTransformations[srcType] || {};
45+
let src = cld.url(publicId, Util.defaults({}, sourceTransformation, childTransformations, {resource_type: 'video', format: srcType}));
4546
let mimeType = 'video/' + (srcType === 'ogv' ? 'ogg' : srcType);
46-
return <source key={mimeType} src={ src} type={ mimeType}/>;
47+
return <source key={mimeType} src={src} type={mimeType}/>;
4748
}
4849
);
4950
} else {
50-
tagAttributes["src"] = cld.url(publicId, {resource_type: 'video', format: sourceTypes});
51+
let sourceTransformation = sourceTransformations[sourceTypes] || {};
52+
tagAttributes.src = cld.url(publicId, Util.defaults({}, sourceTransformation, childTransformations, {resource_type: 'video', format: sourceTypes}));
5153
}
54+
5255
return (
5356
<video {...tagAttributes}>
5457
{sources}

test/VideoTest.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import chai, { expect } from 'chai';
3+
import {shallow} from 'enzyme';
4+
import Video from '../src/components/Video';
5+
import Transformation from '../src/components/Transformation';
6+
7+
chai.use(require('chai-string'));
8+
9+
describe('Video', () => {
10+
it("should include child transformation for a single source type", function () {
11+
let tag = shallow(
12+
<Video cloudName='demo'
13+
sourceTypes={'webm'}
14+
publicId='dog'
15+
sourceTransformation={{
16+
webm: {overlay: 'text:verdana_30:webm!'}
17+
}}>
18+
<Transformation quality='70'/>
19+
</Video>);
20+
expect(tag.props().src).to.endWith('/q_70/l_text:verdana_30:webm!/dog.webm');
21+
});
22+
23+
it("should include child transformation for multiple source types", function () {
24+
let tag = shallow(
25+
<Video cloudName='demo'
26+
sourceTypes={['webm', 'mp4']}
27+
publicId='dog'
28+
sourceTransformation={{
29+
webm: {overlay: 'text:verdana_30:webm!'},
30+
mp4: {overlay: 'text:verdana_30:mp4!'}
31+
}}>
32+
<Transformation quality='70'/>
33+
</Video>);
34+
expect(tag.find('[type="video/webm"]').props().src).to.endWith('/q_70/l_text:verdana_30:webm!/dog.webm');
35+
expect(tag.find('[type="video/mp4"]').props().src).to.endWith('/q_70/l_text:verdana_30:mp4!/dog.mp4');
36+
});
37+
});

0 commit comments

Comments
 (0)