Skip to content

Commit 62c8d51

Browse files
committed
Adding duration data to the store
1 parent 723c13a commit 62c8d51

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

app/store/mapStoreToPlayer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { hasStopped } from '../actions/hasStopped';
44
import { setProgress } from '../actions/setProgress';
5+
import { setDuration } from '../actions/setDuration';
56

67
function setupPlayer(player) {
78
return {
@@ -22,6 +23,8 @@ function setupPlayer(player) {
2223
}
2324

2425
function setupDispatch(store, player) {
26+
store.dispatch(setDuration(player.duration));
27+
2528
player.addEventListener('ended', () => store.dispatch(hasStopped(true)));
2629
player.addEventListener('timeupdate', () => store.dispatch(setProgress(player.currentTime)));
2730
}

test/store/mapStoreToPlayer.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import _ from 'lodash';
66

77
import configureStore from '../../app/store/configurePlayerStore';
88
import mapStoreToPlayer from '../../app/store/mapStoreToPlayer';
9+
import { HAS_STOPPED } from '../../app/actions/hasStopped';
10+
import { SET_PROGRESS } from '../../app/actions/setProgress';
11+
import { SET_DURATION } from '../../app/actions/setDuration';
912

1013
const store = configureStore();
1114
const sandbox = sinon.sandbox.create();
@@ -127,7 +130,7 @@ describe('mapStoreToPlayer', () => {
127130
const player = setupPlayer();
128131
const unsubscribe = mapStoreToPlayer(store, player);
129132
const expectedCallArgs = {
130-
type: 'HAS_STOPPED',
133+
type: HAS_STOPPED,
131134
hasStopped: true
132135
};
133136

@@ -143,7 +146,7 @@ describe('mapStoreToPlayer', () => {
143146
});
144147
const unsubscribe = mapStoreToPlayer(store, player);
145148
const expectedCallArgs = {
146-
type: 'SET_PROGRESS',
149+
type: SET_PROGRESS,
147150
progress: 75
148151
};
149152

@@ -152,5 +155,20 @@ describe('mapStoreToPlayer', () => {
152155

153156
unsubscribe();
154157
});
158+
159+
it('dispatched SET_DURATION: {NUMBER} when the player is loaded', () => {
160+
const player = setupPlayer({
161+
duration: 75
162+
});
163+
const unsubscribe = mapStoreToPlayer(store, player);
164+
const expectedCallArgs = {
165+
type: SET_DURATION,
166+
duration: 75
167+
};
168+
169+
assert(store.dispatch.calledWith(expectedCallArgs));
170+
171+
unsubscribe();
172+
});
155173
});
156174
});

0 commit comments

Comments
 (0)