@@ -5,154 +5,167 @@ import React from 'react';
5
5
import { shallow , mount } from 'enzyme' ;
6
6
import chai , { expect } from 'chai' ;
7
7
import chaiEnzyme from 'chai-enzyme' ;
8
+ import sinonChai from 'sinon-chai' ;
9
+ import dirtyChai from 'dirty-chai' ;
10
+ chai . use ( sinonChai ) ;
11
+ chai . use ( dirtyChai ) ;
8
12
chai . use ( chaiEnzyme ( ) ) ;
9
13
import sinon from 'sinon' ;
10
14
11
- describe ( 'VideoCoverFallback' , function ( ) {
12
- it ( 'should update container ratio when mounted' , function ( ) {
15
+ describe ( 'VideoCoverFallback' , ( ) => {
16
+ it ( 'should update container ratio when mounted' , ( ) => {
13
17
const spy = sinon . spy ( ) ;
14
18
class WithSpy extends VideoCoverFallback {
15
19
updateContainerRatio = spy ;
16
20
}
17
- const wrapper = mount ( < WithSpy /> ) ;
18
- expect ( spy . calledOnce ) . to . be . true ;
21
+ mount ( < WithSpy /> ) ;
22
+ expect ( spy ) . to . have . been . calledOnce ( ) ;
19
23
} ) ;
20
24
21
- it ( 'should call getResizeNotifier prop when mounted' , function ( ) {
25
+ it ( 'should call onFallbackDidMount prop when mounted' , ( ) => {
22
26
const spy = sinon . spy ( ) ;
23
- const wrapper = mount ( < VideoCoverFallback getResizeNotifyer = { spy } /> )
24
- expect ( spy . calledOnce ) . to . be . true ;
27
+ mount ( < VideoCoverFallback onFallbackDidMount = { spy } /> ) ;
28
+ expect ( spy ) . to . have . been . calledOnce ( ) ;
25
29
} ) ;
26
30
27
- it ( 'should pass this.updateContainerRatio as parameter in getResizeNotifier ' , function ( ) {
31
+ it ( 'should pass this.updateContainerRatio as parameter in onFallbackWillUnmount ' , ( ) => {
28
32
let resizeNotifyer ;
29
- const wrapper = mount ( < VideoCoverFallback getResizeNotifyer = { result => {
30
- resizeNotifyer = result ;
31
- } } /> )
33
+ const wrapper = mount ( < VideoCoverFallback
34
+ onFallbackDidMount = { result => {
35
+ resizeNotifyer = result ;
36
+ } }
37
+ /> ) ;
32
38
expect ( resizeNotifyer ) . to . equal ( wrapper . instance ( ) . updateContainerRatio ) ;
33
39
} ) ;
34
40
35
- it ( 'should initialize window-resize eventlisteners if props.remeasureOnWindowResize is set' , function ( ) {
41
+ it ( 'should initialize window-resize eventlisteners if props.remeasureOnWindowResize is set' , ( ) => {
36
42
const spy = sinon . spy ( ) ;
37
43
class WithSpy extends VideoCoverFallback {
38
44
initEventListeners = spy ;
39
45
}
40
- const wrapper = mount ( < WithSpy remeasureOnWindowResize /> ) ;
41
- expect ( spy . calledOnce ) . to . be . true ;
46
+ mount ( < WithSpy remeasureOnWindowResize /> ) ;
47
+ expect ( spy ) . to . have . been . calledOnce ( ) ;
42
48
} ) ;
43
49
44
- it ( 'should NOT initialize window-resize eventlisteners if props.remeasureOnWindowResize is not set' , function ( ) {
50
+ it ( 'should NOT initialize window-resize eventlisteners if props.remeasureOnWindowResize is not set' , ( ) => {
45
51
const spy = sinon . spy ( ) ;
46
52
class WithSpy extends VideoCoverFallback {
47
53
initEventListeners = spy ;
48
54
}
49
- const wrapper = mount ( < WithSpy /> ) ;
50
- expect ( spy . calledOnce ) . to . be . false ;
55
+ mount ( < WithSpy /> ) ;
56
+ expect ( spy ) . not . to . have . been . called ( ) ;
51
57
} ) ;
52
58
53
- it ( 'should remove eventlisteners before unmount' , function ( ) {
59
+ it ( 'should remove eventlisteners before unmount' , ( ) => {
54
60
const spy = sinon . spy ( ) ;
55
61
class WithSpy extends VideoCoverFallback {
56
62
removeEventListeners = spy ;
57
63
}
58
64
const wrapper = mount ( < WithSpy /> ) ;
59
65
wrapper . unmount ( ) ;
60
- expect ( spy . calledOnce ) . to . be . true ;
66
+ expect ( spy ) . to . have . been . calledOnce ( ) ;
61
67
} ) ;
62
68
63
- it ( 'should add/remove eventlisteners if props.remeasureOnWindowResize changes' , function ( ) {
69
+ it ( 'should add/remove eventlisteners if props.remeasureOnWindowResize changes' , ( ) => {
64
70
const addSpy = sinon . spy ( ) ;
65
71
const removeSpy = sinon . spy ( ) ;
66
72
class WithSpy extends VideoCoverFallback {
67
73
initEventListeners = addSpy ;
68
74
removeEventListeners = removeSpy ;
69
75
}
70
76
const wrapper = mount ( < WithSpy /> ) ;
71
- expect ( addSpy . called ) . to . be . false ;
72
- expect ( removeSpy . called ) . to . be . false ;
73
- wrapper . setProps ( { remeasureOnWindowResize : true } ) ;
74
- expect ( addSpy . calledOnce ) . to . be . true ;
75
- expect ( removeSpy . called ) . to . be . false ;
76
- wrapper . setProps ( { remeasureOnWindowResize : false } ) ;
77
- expect ( addSpy . calledOnce ) . to . be . true ;
78
- expect ( removeSpy . calledOnce ) . to . be . true ;
79
- } )
80
-
81
- it ( 'should render a video tag inside a container-div' , function ( ) {
77
+ expect ( addSpy ) . not . to . have . been . called ( ) ;
78
+ expect ( removeSpy ) . not . to . have . been . called ( ) ;
79
+ wrapper . setProps ( { remeasureOnWindowResize : true } ) ;
80
+ expect ( addSpy ) . to . have . been . calledOnce ( ) ;
81
+ expect ( removeSpy ) . not . to . have . been . called ( ) ;
82
+ wrapper . setProps ( { remeasureOnWindowResize : false } ) ;
83
+ expect ( addSpy ) . to . have . been . calledOnce ( ) ;
84
+ expect ( removeSpy ) . to . have . been . calledOnce ( ) ;
85
+ } ) ;
86
+
87
+ it ( 'should render a video tag inside a container-div' , ( ) => {
82
88
const wrapper = shallow ( < VideoCoverFallback /> ) ;
83
89
expect ( wrapper ) . to . have . descendants ( 'div' ) ;
84
90
expect ( wrapper . find ( 'div' ) ) . to . have . descendants ( 'video' ) ;
85
91
} ) ;
86
92
87
- it ( 'should pass props.className to the container-div' , function ( ) {
88
- const wrapper = shallow ( < VideoCoverFallback className = ' some-classname' /> ) ;
93
+ it ( 'should pass props.className to the container-div' , ( ) => {
94
+ const wrapper = shallow ( < VideoCoverFallback className = " some-classname" /> ) ;
89
95
expect ( wrapper ) . to . have . className ( 'some-classname' ) ;
90
- } )
96
+ } ) ;
91
97
92
- it ( 'should invoke updateVideoRatio on loadedData media event' , function ( ) {
98
+ it ( 'should invoke updateVideoRatio on loadedData media event' , ( ) => {
93
99
const spy = sinon . spy ( ) ;
94
100
class WithSpy extends VideoCoverFallback {
95
101
updateVideoRatio = spy ;
96
102
}
97
103
const wrapper = shallow ( < WithSpy /> ) ;
98
104
const video = wrapper . find ( 'video' ) ;
99
- video . simulate ( 'loadedData' , { target : {
100
- videoWidth : 50 ,
101
- videoHeight : 50 ,
102
- } } ) ;
103
- expect ( spy . calledOnce ) . to . be . true ;
104
- expect ( spy . calledWith ( 50 , 50 ) ) . to . be . true ;
105
+ video . simulate ( 'loadedData' , {
106
+ target : {
107
+ videoWidth : 50 ,
108
+ videoHeight : 50 ,
109
+ } ,
110
+ } ) ;
111
+ expect ( spy ) . to . have . been . calledOnce ( ) ;
112
+ expect ( spy . calledWith ( 50 , 50 ) ) . to . be . true ( ) ;
105
113
} ) ;
106
114
107
- it ( 'should apply all props.videoOptions to the video tag' , function ( ) {
108
- const wrapper = shallow ( < VideoCoverFallback videoOptions = { {
109
- src : 'http://some-video-url.mp4' ,
110
- } } /> ) ;
115
+ it ( 'should apply all props.videoOptions to the video tag' , ( ) => {
116
+ const wrapper = shallow ( < VideoCoverFallback
117
+ videoOptions = { {
118
+ src : 'http://some-video-url.mp4' ,
119
+ } }
120
+ /> ) ;
111
121
expect ( wrapper . find ( 'video' ) ) . to . have . prop ( 'src' , 'http://some-video-url.mp4' ) ;
112
122
} ) ;
113
123
114
- describe ( 'container-styles' , function ( ) {
115
-
116
- it ( 'should apply props.style to the container-div' , function ( ) {
117
- const wrapper = shallow ( < VideoCoverFallback style = { {
118
- backgroundColor : 'teal' ,
119
- lineHeight : '100px' ,
120
- } } /> ) ;
124
+ describe ( 'container-styles' , ( ) => {
125
+ it ( 'should apply props.style to the container-div' , ( ) => {
126
+ const wrapper = shallow ( < VideoCoverFallback
127
+ style = { {
128
+ backgroundColor : 'teal' ,
129
+ lineHeight : '100px' ,
130
+ } }
131
+ /> ) ;
121
132
expect ( wrapper ) . to . have . style ( 'background-color' , 'teal' ) ;
122
133
expect ( wrapper ) . to . have . style ( 'line-height' , '100px' ) ;
123
134
} ) ;
124
-
125
- it ( 'should set width and height to 100% by default' , function ( ) {
135
+
136
+ it ( 'should set width and height to 100% by default' , ( ) => {
126
137
const wrapper = shallow ( < VideoCoverFallback /> ) ;
127
138
expect ( wrapper ) . to . have . style ( 'height' , '100%' ) ;
128
139
expect ( wrapper ) . to . have . style ( 'width' , '100%' ) ;
129
140
} ) ;
130
141
131
- it ( 'should be possible to override width and height via props.style' , function ( ) {
142
+ it ( 'should be possible to override width and height via props.style' , ( ) => {
132
143
const wrapper = shallow ( < VideoCoverFallback style = { { width : '50%' , height : '50%' } } /> ) ;
133
144
expect ( wrapper ) . to . have . style ( 'height' , '50%' ) ;
134
145
expect ( wrapper ) . to . have . style ( 'width' , '50%' ) ;
135
146
} ) ;
136
147
137
- it ( 'should set position relative and overflow: hidden' , function ( ) {
148
+ it ( 'should set position relative and overflow: hidden' , ( ) => {
138
149
const wrapper = shallow ( < VideoCoverFallback /> ) ;
139
150
expect ( wrapper ) . to . have . style ( 'position' , 'relative' ) ;
140
151
expect ( wrapper ) . to . have . style ( 'overflow' , 'hidden' ) ;
141
152
} ) ;
142
153
143
- it ( 'should not be possible to override position and overflow' , function ( ) {
144
- const wrapper = shallow ( < VideoCoverFallback style = { {
145
- position : 'fixed' ,
146
- overflow : 'scroll' ,
147
- } } /> ) ;
154
+ it ( 'should not be possible to override position and overflow' , ( ) => {
155
+ const wrapper = shallow ( < VideoCoverFallback
156
+ style = { {
157
+ position : 'fixed' ,
158
+ overflow : 'scroll' ,
159
+ } }
160
+ /> ) ;
148
161
expect ( wrapper ) . to . have . style ( 'position' , 'relative' ) ;
149
162
expect ( wrapper ) . to . have . style ( 'overflow' , 'hidden' ) ;
150
163
} ) ;
151
164
} ) ;
152
165
153
166
// todo: maybe use generated test-data for this?
154
- describe ( 'video-styles' , function ( ) {
155
- it ( 'should have width auto, height 100% if innerRatio > outerRatio' , function ( ) {
167
+ describe ( 'video-styles' , ( ) => {
168
+ it ( 'should have width auto, height 100% if innerRatio > outerRatio' , ( ) => {
156
169
const wrapper = shallow ( < VideoCoverFallback /> ) ;
157
170
wrapper . setState ( {
158
171
innerRatio : 5 ,
@@ -161,7 +174,7 @@ describe('VideoCoverFallback', function () {
161
174
expect ( wrapper . find ( 'video' ) ) . to . have . style ( 'width' , 'auto' ) ;
162
175
expect ( wrapper . find ( 'video' ) ) . to . have . style ( 'height' , '100%' ) ;
163
176
} ) ;
164
- it ( 'should have width 100%, height auto if innerRatio <= outerRatio' , function ( ) {
177
+ it ( 'should have width 100%, height auto if innerRatio <= outerRatio' , ( ) => {
165
178
const wrapper = shallow ( < VideoCoverFallback /> ) ;
166
179
wrapper . setState ( {
167
180
innerRatio : 3 ,
@@ -172,28 +185,29 @@ describe('VideoCoverFallback', function () {
172
185
} ) ;
173
186
} ) ;
174
187
175
- describe ( 'updateContainerRatio()' , function ( ) {
176
- it ( 'should set state.outerRatio to ratio of container width/height' , function ( ) {
188
+ describe ( 'updateContainerRatio()' , ( ) => {
189
+ it ( 'should set state.outerRatio to ratio of container width/height' , ( ) => {
177
190
const wrapper = shallow ( < VideoCoverFallback /> ) ;
178
- const mockRef = {
191
+ const mockRef = {
179
192
getBoundingClientRect : ( ) => {
180
- return {
193
+ const result = {
181
194
width : 4 ,
182
- height : 5
183
- }
184
- }
195
+ height : 5 ,
196
+ } ;
197
+ return result ;
198
+ } ,
185
199
} ;
186
200
wrapper . instance ( ) . updateContainerRatio ( mockRef ) ;
187
- expect ( wrapper ) . to . have . state ( 'outerRatio' , 4 / 5 ) ;
201
+ expect ( wrapper ) . to . have . state ( 'outerRatio' , 4 / 5 ) ;
188
202
} ) ;
189
203
} ) ;
190
204
191
- describe ( 'updateVideoRatio()' , function ( ) {
192
- it ( 'should set state.innerRatio to ratio of video width/height' , function ( ) {
205
+ describe ( 'updateVideoRatio()' , ( ) => {
206
+ it ( 'should set state.innerRatio to ratio of video width/height' , ( ) => {
193
207
const wrapper = shallow ( < VideoCoverFallback /> ) ;
194
208
expect ( wrapper ) . not . to . have . state ( 'innerRatio' ) ;
195
209
wrapper . instance ( ) . updateVideoRatio ( 4 , 5 ) ;
196
- expect ( wrapper ) . to . have . state ( 'innerRatio' , 4 / 5 ) ;
210
+ expect ( wrapper ) . to . have . state ( 'innerRatio' , 4 / 5 ) ;
197
211
} ) ;
198
212
} ) ;
199
- } ) ;
213
+ } ) ;
0 commit comments