@@ -17,7 +17,10 @@ function setupPlayer() {
17
17
play : playSpy ,
18
18
pause : pauseSpy ,
19
19
playSpy : playSpy ,
20
- pauseSpy : pauseSpy
20
+ pauseSpy : pauseSpy ,
21
+ addEventListener : function addEventListener ( name , cb ) {
22
+ this [ name ] = cb ;
23
+ }
21
24
} ;
22
25
}
23
26
@@ -30,64 +33,100 @@ describe('mapStoreToPlayer', () => {
30
33
sandbox . restore ( ) ;
31
34
} ) ;
32
35
33
- it ( 'triggers the pause method when the dispatching isPlaying: false' , ( ) => {
34
- const player = setupPlayer ( ) ;
35
- store . getState . onCall ( 0 ) . returns ( {
36
- playback : {
37
- isPlaying : true
38
- }
36
+ describe ( 'store dispatches' , ( ) => {
37
+ it ( 'triggers the pause method when the dispatching IS_PLAYING: false' , ( ) => {
38
+ const player = setupPlayer ( ) ;
39
+ store . getState . onCall ( 0 ) . returns ( {
40
+ playback : {
41
+ isPlaying : true
42
+ }
43
+ } ) ;
44
+ store . getState . onCall ( 1 ) . returns ( {
45
+ playback : {
46
+ isPlaying : false
47
+ }
48
+ } ) ;
49
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
50
+
51
+ store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
52
+ assert ( player . pauseSpy . calledOnce ) ;
53
+
54
+ unsubscribe ( ) ;
39
55
} ) ;
40
- store . getState . onCall ( 1 ) . returns ( {
41
- playback : {
42
- isPlaying : false
43
- }
56
+
57
+ it ( 'triggers the play method when the dispatching IS_PLAYING: true' , ( ) => {
58
+ const player = setupPlayer ( ) ;
59
+ store . getState . onCall ( 0 ) . returns ( {
60
+ playback : {
61
+ isPlaying : false
62
+ }
63
+ } ) ;
64
+ store . getState . onCall ( 1 ) . returns ( {
65
+ playback : {
66
+ isPlaying : true
67
+ }
68
+ } ) ;
69
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
70
+
71
+ store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
72
+ assert ( player . playSpy . calledOnce ) ;
73
+
74
+ unsubscribe ( ) ;
44
75
} ) ;
45
- const unsubscribe = mapStoreToPlayer ( store , player ) ;
46
76
47
- store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
48
- assert ( player . pauseSpy . calledOnce ) ;
77
+ it ( 'triggers the pause method and resets the player when dispatching HAS_STOPPED: true' , ( ) => {
78
+ const player = setupPlayer ( ) ;
79
+ store . getState . onCall ( 0 ) . returns ( {
80
+ playback : {
81
+ hasStopped : false
82
+ }
83
+ } ) ;
84
+ store . getState . onCall ( 1 ) . returns ( {
85
+ playback : {
86
+ hasStopped : true
87
+ }
88
+ } ) ;
89
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
90
+
91
+ store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
92
+ assert ( player . pauseSpy . calledOnce ) ;
93
+ assert . equal ( player . currentTime , 0 ) ;
94
+
95
+ unsubscribe ( ) ;
96
+ } ) ;
49
97
50
- unsubscribe ( ) ;
98
+ it ( 'updates the volume of the player when dispatching SET_VOLUME' , ( ) => {
99
+ const player = setupPlayer ( ) ;
100
+ store . getState . onCall ( 0 ) . returns ( {
101
+ playback : {
102
+ volume : 50
103
+ }
104
+ } ) ;
105
+ store . getState . onCall ( 1 ) . returns ( {
106
+ playback : {
107
+ volume : 75
108
+ }
109
+ } ) ;
110
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
111
+
112
+ store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
113
+ assert . equal ( player . volume , 0.75 ) ;
114
+
115
+ unsubscribe ( ) ;
116
+ } ) ;
51
117
} ) ;
52
118
53
- it ( 'triggers the play method when the dispatching isPlaying: true' , ( ) => {
54
- const player = setupPlayer ( ) ;
55
- store . getState . onCall ( 0 ) . returns ( {
56
- playback : {
57
- isPlaying : false
58
- }
59
- } ) ;
60
- store . getState . onCall ( 1 ) . returns ( {
61
- playback : {
62
- isPlaying : true
63
- }
64
- } ) ;
65
- const unsubscribe = mapStoreToPlayer ( store , player ) ;
119
+ describe ( 'player events' , ( ) => {
120
+ beforeEach ( ( ) => sinon . stub ( store , 'dispatch' ) ) ;
66
121
67
- store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
68
- assert ( player . playSpy . calledOnce ) ;
122
+ it ( 'dispatches HAS_STOPPED: true when the player ends' , ( ) => {
123
+ const player = setupPlayer ( ) ;
124
+ const unsubscribe = mapStoreToPlayer ( store , player ) ;
69
125
70
- unsubscribe ( ) ;
71
- } ) ;
126
+ player . ended ( ) ;
127
+ assert ( store . dispatch . calledOnce ) ;
72
128
73
- it ( 'triggers the pause method and resets the player when dispatching hasStopped: true' , ( ) => {
74
- const player = setupPlayer ( ) ;
75
- store . getState . onCall ( 0 ) . returns ( {
76
- playback : {
77
- hasStopped : false
78
- }
79
- } ) ;
80
- store . getState . onCall ( 1 ) . returns ( {
81
- playback : {
82
- hasStopped : true
83
- }
129
+ unsubscribe ( ) ;
84
130
} ) ;
85
- const unsubscribe = mapStoreToPlayer ( store , player ) ;
86
-
87
- store . dispatch ( { type : 'FAKE_DISPATCH' } ) ;
88
- assert ( player . pauseSpy . calledOnce ) ;
89
- assert . equal ( player . currentTime , 0 ) ;
90
-
91
- unsubscribe ( ) ;
92
131
} ) ;
93
132
} ) ;
0 commit comments