Skip to content

Commit d0a0ecb

Browse files
committed
Adding progress action and reducer functionality
1 parent 4a34b6a commit d0a0ecb

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

app/actions/setProgress.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
export const SET_PROGRESS = 'SET_PROGRESS';
4+
5+
export function setProgress(progress) {
6+
return {
7+
type: SET_PROGRESS,
8+
progress: progress
9+
};
10+
}

app/reducers/playback.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import { IS_PLAYING } from '../actions/isPlaying';
44
import { HAS_STOPPED } from '../actions/hasStopped';
55
import { SET_VOLUME } from '../actions/setVolume';
6+
import { SET_PROGRESS } from '../actions/setProgress';
67

78
const initialState = {
89
isPlaying: false,
910
hasStopped: true,
10-
volume: 50
11+
volume: 50,
12+
progress: 0
1113
};
1214

1315
function setIsPlayingState(isPlaying) {
@@ -40,6 +42,12 @@ function setVolumeState(volume) {
4042
};
4143
}
4244

45+
function setProgressState(progress) {
46+
return {
47+
progress: progress
48+
};
49+
}
50+
4351
export function playbackReducer(state = initialState, action) {
4452
switch (action.type) {
4553
case IS_PLAYING :
@@ -48,6 +56,8 @@ export function playbackReducer(state = initialState, action) {
4856
return Object.assign({}, state, setHasStoppedState(action.hasStopped));
4957
case SET_VOLUME :
5058
return Object.assign({}, state, setVolumeState(action.volume));
59+
case SET_PROGRESS :
60+
return Object.assign({}, state, setProgressState(action.progress));
5161
default:
5262
return state;
5363
}

test/actions/setProgress.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
import assert from 'assert';
4+
import { SET_PROGRESS, setProgress } from '../../app/actions/setProgress';
5+
6+
describe('setProgress', () => {
7+
it('returns an object with the progress: {NUMBER}', () => {
8+
const action = setProgress(50);
9+
10+
assert.equal(action.type, SET_PROGRESS);
11+
assert.equal(action.progress, 50);
12+
});
13+
});

test/reducers/playback.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import assert from 'assert';
44
import { IS_PLAYING } from '../../app/actions/isPlaying';
55
import { HAS_STOPPED } from '../../app/actions/hasStopped';
66
import { SET_VOLUME } from '../../app/actions/setVolume';
7+
import { SET_PROGRESS } from '../../app/actions/setProgress';
78
import { playbackReducer } from '../../app/reducers/playback';
89

910
describe('playbackState', () => {
@@ -62,7 +63,7 @@ describe('playbackState', () => {
6263
assert.strictEqual(playbackReducer(undefined, '').volume, 50);
6364
});
6465

65-
it('{volume: 75} when action.volume is 75', () => {
66+
it('sets {volume: 75} when action.volume is 75', () => {
6667
const state = playbackReducer(undefined, {
6768
type: SET_VOLUME,
6869
volume: 75
@@ -71,4 +72,19 @@ describe('playbackState', () => {
7172
assert.strictEqual(state.volume, 75);
7273
});
7374
});
75+
76+
describe('progress property', () => {
77+
it('defaults to 0', () => {
78+
assert.strictEqual(playbackReducer(undefined, '').progress, 0);
79+
});
80+
81+
it('sets {progress: 75} when action.progress is 75', () => {
82+
const state = playbackReducer(undefined, {
83+
type: SET_PROGRESS,
84+
progress: 75
85+
});
86+
87+
assert.strictEqual(state.progress, 75);
88+
});
89+
});
7490
});

0 commit comments

Comments
 (0)