Skip to content

Commit 512cd7f

Browse files
committed
updated playback reducer with hasStopped property setter
1 parent e5fdadf commit 512cd7f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

app/reducers/playback.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import { IS_PLAYING } from '../actions/isPlaying';
44
import { IS_PAUSED } from '../actions/isPaused';
5+
import { HAS_STOPPED } from '../actions/hasStopped';
56

67
const initialState = {
78
isPlaying: false,
8-
isPaused: false
9+
isPaused: false,
10+
hasStopped: true
911
};
1012

1113
export function setPlaybackState(state = initialState, action) {
@@ -20,6 +22,10 @@ export function setPlaybackState(state = initialState, action) {
2022
isPlaying: !action.isPaused,
2123
isPaused: action.isPaused
2224
});
25+
case HAS_STOPPED :
26+
return Object.assign({}, state, {
27+
hasStopped: action.hasStopped
28+
});
2329
default:
2430
return state;
2531
}

test/reducers/playback.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import assert from 'assert';
44
import { IS_PLAYING } from '../../app/actions/isPlaying';
55
import { IS_PAUSED } from '../../app/actions/isPaused';
6+
import { HAS_STOPPED } from '../../app/actions/hasStopped';
67
import { setPlaybackState as playbackReducer } from '../../app/reducers/playback';
78

89
describe('playbackState', () => {
@@ -11,7 +12,7 @@ describe('playbackState', () => {
1112
assert.strictEqual(playbackReducer(undefined, '').isPlaying, false);
1213
});
1314

14-
it('{isPlaying: true, isPaused: false} when isPlaying is true', () => {
15+
it('{isPlaying: true, isPaused: false} when action.isPlaying is true', () => {
1516
const state = playbackReducer(undefined, {
1617
type: IS_PLAYING,
1718
isPlaying: true
@@ -20,7 +21,7 @@ describe('playbackState', () => {
2021
assert.strictEqual(state.isPaused, false);
2122
});
2223

23-
it('{isPlaying: false, isPaused: true} when isPlaying is false', () => {
24+
it('{isPlaying: false, isPaused: true} when action.isPlaying is false', () => {
2425
const state = playbackReducer(undefined, {
2526
type: IS_PLAYING,
2627
isPlaying: false
@@ -35,7 +36,7 @@ describe('playbackState', () => {
3536
assert.strictEqual(playbackReducer(undefined, '').isPaused, false);
3637
});
3738

38-
it('{isPlaying: false, isPaused: true} when isPaused is true', () => {
39+
it('{isPlaying: false, isPaused: true} when action.isPaused is true', () => {
3940
const state = playbackReducer(undefined, {
4041
type: IS_PAUSED,
4142
isPaused: true
@@ -44,7 +45,7 @@ describe('playbackState', () => {
4445
assert.strictEqual(state.isPlaying, false);
4546
});
4647

47-
it('{isPlaying: true, isPaused: false} when isPaused is false', () => {
48+
it('{isPlaying: true, isPaused: false} when action.isPaused is false', () => {
4849
const state = playbackReducer(undefined, {
4950
type: IS_PAUSED,
5051
isPaused: false
@@ -53,4 +54,26 @@ describe('playbackState', () => {
5354
assert.strictEqual(state.isPlaying, true);
5455
});
5556
});
57+
58+
describe('hasStopped property', () => {
59+
it('defaults to true', () => {
60+
assert.strictEqual(playbackReducer(undefined, '').hasStopped, true);
61+
});
62+
63+
it('{hasStopped: true} when action.hasStopped is true', () => {
64+
const state = playbackReducer(undefined, {
65+
type: HAS_STOPPED,
66+
hasStopped: true
67+
});
68+
assert.strictEqual(state.hasStopped, true);
69+
});
70+
71+
it('{hasStopped: false} when action.hasStopped is false', () => {
72+
const state = playbackReducer(undefined, {
73+
type: HAS_STOPPED,
74+
hasStopped: false
75+
});
76+
assert.strictEqual(state.hasStopped, false);
77+
});
78+
});
5679
});

0 commit comments

Comments
 (0)