2
2
3
3
import assert from 'assert' ;
4
4
import sinon from 'sinon' ;
5
+ import _ from 'lodash' ;
5
6
6
7
import configureStore from '../../app/store/configurePlayerStore' ;
7
8
import mapStoreToPlayer from '../../app/store/mapStoreToPlayer' ;
8
9
9
10
const store = configureStore ( ) ;
10
11
const sandbox = sinon . sandbox . create ( ) ;
11
12
12
- function setupPlayer ( ) {
13
+ function setupPlayer ( params ) {
13
14
const playSpy = sinon . spy ( ) ;
14
15
const pauseSpy = sinon . spy ( ) ;
15
-
16
- return {
16
+ const player = {
17
17
play : playSpy ,
18
18
pause : pauseSpy ,
19
19
playSpy : playSpy ,
@@ -22,6 +22,8 @@ function setupPlayer() {
22
22
this [ name ] = cb ;
23
23
}
24
24
} ;
25
+
26
+ return _ . assign ( player , params ) ;
25
27
}
26
28
27
29
describe ( 'mapStoreToPlayer' , ( ) => {
@@ -117,14 +119,36 @@ describe('mapStoreToPlayer', () => {
117
119
} ) ;
118
120
119
121
describe ( 'player events' , ( ) => {
120
- beforeEach ( ( ) => sinon . stub ( store , 'dispatch' ) ) ;
122
+ beforeEach ( ( ) => {
123
+ sandbox . stub ( store , 'dispatch' ) ;
124
+ } ) ;
121
125
122
126
it ( 'dispatches HAS_STOPPED: true when the player ends' , ( ) => {
123
127
const player = setupPlayer ( ) ;
124
128
const unsubscribe = mapStoreToPlayer ( store , player ) ;
129
+ const expectedCallArgs = {
130
+ type : 'HAS_STOPPED' ,
131
+ hasStopped : true
132
+ } ;
125
133
126
134
player . ended ( ) ;
127
- assert ( store . dispatch . calledOnce ) ;
135
+ assert ( store . dispatch . calledWith ( expectedCallArgs ) ) ;
136
+
137
+ unsubscribe ( ) ;
138
+ } ) ;
139
+
140
+ it ( 'dispatched SET_PROGRESS: {NUMBER} when the timeupdate event is triggered' , ( ) => {
141
+ const player = setupPlayer ( {
142
+ currentTime : 75
143
+ } ) ;
144
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
145
+ const expectedCallArgs = {
146
+ type : 'SET_PROGRESS' ,
147
+ progress : 75
148
+ } ;
149
+
150
+ player . timeupdate ( ) ;
151
+ assert ( store . dispatch . calledWith ( expectedCallArgs ) ) ;
128
152
129
153
unsubscribe ( ) ;
130
154
} ) ;
0 commit comments