11import React from 'react' ;
2- import chai , { expect } from 'chai' ;
2+ import chai , { expect } from 'chai' ;
33import { shallow , mount } from 'enzyme' ;
44import Video from '../src/components/Video' ;
55import Transformation from '../src/components/Transformation' ;
66
77chai . use ( require ( 'chai-string' ) ) ;
88
99describe ( '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 support fps parameter" , function ( ) {
24- let tag = shallow (
25- < Video cloudName = 'demo'
26- sourceTypes = { 'webm' }
27- publicId = 'dog' >
28- < Transformation fps = '24' />
29- </ Video > ) ;
30- expect ( tag . props ( ) . src ) . to . endWith ( '/fps_24/dog.webm' ) ;
31- tag = shallow (
32- < Video cloudName = 'demo'
33- sourceTypes = { 'webm' }
34- publicId = 'dog' >
35- < Transformation fps = '24-29.97' />
36- </ Video > ) ;
37- expect ( tag . props ( ) . src ) . to . endWith ( '/fps_24-29.97/dog.webm' ) ;
38- tag = shallow (
39- < Video cloudName = 'demo'
40- sourceTypes = { 'webm' }
41- publicId = 'dog' >
42- < Transformation fps = '25-' />
43- </ Video > ) ;
44- expect ( tag . props ( ) . src ) . to . endWith ( '/fps_25-/dog.webm' ) ;
45- } ) ;
46-
47- it ( 'should support startOffset parameter' , function ( ) {
48- let tag = shallow (
49- < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
50- < Transformation startOffset = "auto" />
51- </ Video > ) ;
52- expect ( tag . props ( ) . src ) . to . endWith ( '/so_auto/dog.webm' ) ;
53- tag = shallow (
54- < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
55- < Transformation startOffset = "2" />
56- </ Video > ) ;
57- expect ( tag . props ( ) . src ) . to . endWith ( '/so_2/dog.webm' ) ;
58- tag = shallow (
59- < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
60- < Transformation startOffset = "2.34" />
61- </ Video > ) ;
62- expect ( tag . props ( ) . src ) . to . endWith ( '/so_2.34/dog.webm' ) ;
63- } ) ;
64-
65- it ( "should include child transformation for multiple source types" , function ( ) {
66- let tag = shallow (
67- < Video cloudName = 'demo'
68- sourceTypes = { [ 'webm' , 'mp4' ] }
69- publicId = 'dog'
70- sourceTransformation = { {
71- webm : { overlay : 'text:verdana_30:webm!' } ,
72- mp4 : { overlay : 'text:verdana_30:mp4!' }
73- } } >
74- < Transformation quality = '70' />
75- </ Video > ) ;
76- expect ( tag . find ( '[type="video/webm"]' ) . props ( ) . src ) . to . endWith ( '/q_70/l_text:verdana_30:webm!/dog.webm' ) ;
77- expect ( tag . find ( '[type="video/mp4"]' ) . props ( ) . src ) . to . endWith ( '/q_70/l_text:verdana_30:mp4!/dog.mp4' ) ;
78- } ) ;
79-
80- it ( 'should support inner text' , function ( ) {
81- let tag = shallow (
82- < Video cloudName = 'demo' publicId = 'dog' >
83- Your browser does not support the video tag.
84- </ Video >
85- ) ;
86- expect ( tag . type ( ) ) . to . equal ( "video" ) ;
87- } ) ;
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 support fps parameter" , function ( ) {
24+ let tag = shallow (
25+ < Video cloudName = 'demo'
26+ sourceTypes = { 'webm' }
27+ publicId = 'dog' >
28+ < Transformation fps = '24' />
29+ </ Video > ) ;
30+ expect ( tag . props ( ) . src ) . to . endWith ( '/fps_24/dog.webm' ) ;
31+ tag = shallow (
32+ < Video cloudName = 'demo'
33+ sourceTypes = { 'webm' }
34+ publicId = 'dog' >
35+ < Transformation fps = '24-29.97' />
36+ </ Video > ) ;
37+ expect ( tag . props ( ) . src ) . to . endWith ( '/fps_24-29.97/dog.webm' ) ;
38+ tag = shallow (
39+ < Video cloudName = 'demo'
40+ sourceTypes = { 'webm' }
41+ publicId = 'dog' >
42+ < Transformation fps = '25-' />
43+ </ Video > ) ;
44+ expect ( tag . props ( ) . src ) . to . endWith ( '/fps_25-/dog.webm' ) ;
45+ } ) ;
46+
47+ it ( 'should support startOffset parameter' , function ( ) {
48+ let tag = shallow (
49+ < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
50+ < Transformation startOffset = "auto" />
51+ </ Video > ) ;
52+ expect ( tag . props ( ) . src ) . to . endWith ( '/so_auto/dog.webm' ) ;
53+ tag = shallow (
54+ < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
55+ < Transformation startOffset = "2" />
56+ </ Video > ) ;
57+ expect ( tag . props ( ) . src ) . to . endWith ( '/so_2/dog.webm' ) ;
58+ tag = shallow (
59+ < Video cloudName = "demo" sourceTypes = { 'webm' } publicId = "dog" >
60+ < Transformation startOffset = "2.34" />
61+ </ Video > ) ;
62+ expect ( tag . props ( ) . src ) . to . endWith ( '/so_2.34/dog.webm' ) ;
63+ } ) ;
64+
65+ it ( "should include child transformation for multiple source types" , function ( ) {
66+ let tag = shallow (
67+ < Video cloudName = 'demo'
68+ sourceTypes = { [ 'webm' , 'mp4' ] }
69+ publicId = 'dog'
70+ sourceTransformation = { {
71+ webm : { overlay : 'text:verdana_30:webm!' } ,
72+ mp4 : { overlay : 'text:verdana_30:mp4!' }
73+ } } >
74+ < Transformation quality = '70' />
75+ </ Video > ) ;
76+ expect ( tag . find ( '[type="video/webm"]' ) . props ( ) . src ) . to . endWith ( '/q_70/l_text:verdana_30:webm!/dog.webm' ) ;
77+ expect ( tag . find ( '[type="video/mp4"]' ) . props ( ) . src ) . to . endWith ( '/q_70/l_text:verdana_30:mp4!/dog.mp4' ) ;
78+ } ) ;
79+
80+ it ( 'should support inner text' , function ( ) {
81+ let tag = shallow (
82+ < Video cloudName = 'demo' publicId = 'dog' >
83+ Your browser does not support the video tag.
84+ </ Video >
85+ ) ;
86+ expect ( tag . type ( ) ) . to . equal ( "video" ) ;
87+ } ) ;
8888
8989 it ( 'Should support forwarding innerRef to underlying video element' , function ( ) {
9090 let myRef = React . createRef ( ) ;
@@ -105,6 +105,65 @@ describe('Video', () => {
105105
106106 expect ( tag . find ( 'video' ) . prop ( 'src' ) ) . to . endWith ( '/l_text:verdana_30:webm!/dog.webm' ) ;
107107 expect ( video . src ) . to . endWith ( '/l_text:verdana_30:webm!/dog.webm' ) ;
108- [ 'play' , 'pause' , 'canPlayType' , 'addTextTrack' ] . forEach ( func => expect ( video [ func ] ) . to . be . a ( 'function' ) ) ;
108+ [ 'play' , 'pause' , 'canPlayType' , 'addTextTrack' ] . forEach ( func => expect ( video [ func ] ) . to . be . a ( 'function' ) ) ;
109+ } ) ;
110+
111+ it ( 'Should set default video poster' , function ( ) {
112+ let tag = shallow (
113+ < Video cloudName = 'demo' publicId = 'dog' />
114+ ) ;
115+
116+ expect ( tag . props ( ) . poster ) . to . equal ( 'http://res.cloudinary.com/demo/video/upload/dog.jpg' ) ;
117+ } ) ;
118+
119+ it ( 'Should set secure video poster' , function ( ) {
120+ let tag = shallow (
121+ < Video cloudName = 'demo' publicId = 'dog' poster = { { secure : true } } />
122+ ) ;
123+
124+ expect ( tag . props ( ) . poster ) . to . equal ( 'https://res.cloudinary.com/demo/video/upload/dog.jpg' ) ;
125+ } ) ;
126+
127+ it ( 'Should set video poster url' , function ( ) {
128+ let tag = shallow (
129+ < Video cloudName = 'demo' publicId = 'dog'
130+ poster = { 'https://res.cloudinary.com/demo/video/upload/w_200,dpr_2.0/dog.jpg' } />
131+ ) ;
132+
133+ expect ( tag . props ( ) . poster ) . to . equal ( 'https://res.cloudinary.com/demo/video/upload/w_200,dpr_2.0/dog.jpg' ) ;
134+ } ) ;
135+
136+ it ( 'Should set video poster public_id and transformation' , function ( ) {
137+ const poster = {
138+ public_id : 'elephants' ,
139+ transformation : [
140+ { width : 100 , crop : "scale" } ,
141+ { dpr : "2.0" }
142+ ]
143+ } ;
144+
145+ let tag = shallow (
146+ < Video cloudName = 'demo' publicId = 'dog' poster = { poster } />
147+ ) ;
148+
149+ expect ( tag . props ( ) . poster ) . to . equal ( 'http://res.cloudinary.com/demo/image/upload/c_scale,w_100/dpr_2.0/elephants' ) ;
150+ } ) ;
151+
152+ it ( 'Should set video poster public_id, resource_type and transformation' , function ( ) {
153+ const poster = {
154+ public_id : 'elephants' ,
155+ resource_type : 'video' ,
156+ format : 'jpg' ,
157+ transformation : [
158+ { width : 100 , crop : "scale" } ,
159+ { dpr : "2.0" }
160+ ]
161+ } ;
162+
163+ let tag = shallow (
164+ < Video cloudName = 'demo' publicId = 'dog' poster = { poster } />
165+ ) ;
166+
167+ expect ( tag . props ( ) . poster ) . to . equal ( 'http://res.cloudinary.com/demo/video/upload/c_scale,w_100/dpr_2.0/elephants.jpg' ) ;
109168 } ) ;
110169} ) ;
0 commit comments