|
|
@@ -4,11 +4,16 @@ import {
|
|
|
ActionTypeRemote,
|
|
|
masterSet,
|
|
|
playPaused,
|
|
|
+ queueOrdered,
|
|
|
+ queuePushed,
|
|
|
+ queueRemoved,
|
|
|
+ queueShifted,
|
|
|
+ RemoteAction,
|
|
|
seeked,
|
|
|
songInfoFetched,
|
|
|
stateSet,
|
|
|
} from '../actions';
|
|
|
-import { GlobalState, initialState } from '../reducer';
|
|
|
+import { globalReducer, GlobalState, initialState } from '../reducer';
|
|
|
import { Song } from '../types';
|
|
|
import { MusicPlayer } from '../types/state';
|
|
|
import { globalEffects } from './effects';
|
|
|
@@ -24,6 +29,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 87,
|
|
|
master: 'my-client',
|
|
|
+ queue: [],
|
|
|
};
|
|
|
|
|
|
const prevState: GlobalState = {
|
|
|
@@ -31,7 +37,10 @@ describe(globalEffects.name, () => {
|
|
|
myClientName: 'my-client-name',
|
|
|
};
|
|
|
|
|
|
- const result = globalEffects(prevState, stateSet(localPlayer));
|
|
|
+ const action = stateSet(localPlayer);
|
|
|
+ const nextState = globalReducer(prevState, action);
|
|
|
+
|
|
|
+ const result = globalEffects(prevState, action, nextState);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -49,6 +58,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 87,
|
|
|
master: 'my-client-name',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
myClientName: 'my-client-name',
|
|
|
};
|
|
|
@@ -59,6 +69,8 @@ describe(globalEffects.name, () => {
|
|
|
myClientName: 'some-slave-client',
|
|
|
};
|
|
|
|
|
|
+ const action = seeked(776);
|
|
|
+
|
|
|
describe.each`
|
|
|
clientType | state
|
|
|
${'master'} | ${stateMaster}
|
|
|
@@ -67,7 +79,7 @@ describe(globalEffects.name, () => {
|
|
|
it('should create a remote state set action', () => {
|
|
|
expect.assertions(1);
|
|
|
|
|
|
- const result = globalEffects(state, seeked(776));
|
|
|
+ const result = globalEffects(state, action, globalReducer(state, action));
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -87,13 +99,20 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 5,
|
|
|
master: 'some-master-went-away',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
myClientName: 'my-client-name',
|
|
|
};
|
|
|
|
|
|
+ const action = masterSet();
|
|
|
+
|
|
|
it('should return a StateSet action informing other clients that we are the new master', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(stateMasterWentAway, masterSet());
|
|
|
+ const result = globalEffects(
|
|
|
+ stateMasterWentAway,
|
|
|
+ action,
|
|
|
+ globalReducer(stateMasterWentAway, action),
|
|
|
+ );
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -103,6 +122,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: -1,
|
|
|
master: 'my-client-name',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -110,7 +130,11 @@ describe(globalEffects.name, () => {
|
|
|
describe('when the action specified a particular client', () => {
|
|
|
it('should return a StateSet action informing the new client to resume playback', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(stateMasterWentAway, masterSet('other-client'));
|
|
|
+ const result = globalEffects(
|
|
|
+ stateMasterWentAway,
|
|
|
+ masterSet('other-client'),
|
|
|
+ globalReducer(stateMasterWentAway, masterSet('other-client')),
|
|
|
+ );
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -120,6 +144,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 83,
|
|
|
master: 'other-client',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -135,14 +160,19 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 5,
|
|
|
master: 'some-master-client',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
myClientName: 'some-master-client',
|
|
|
};
|
|
|
|
|
|
+ const action = playPaused();
|
|
|
+
|
|
|
describe('when the client is master', () => {
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- expect(globalEffects(statePriorMaster, playPaused())).toBeNull();
|
|
|
+ expect(
|
|
|
+ globalEffects(statePriorMaster, action, globalReducer(statePriorMaster, action)),
|
|
|
+ ).toBeNull();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -154,7 +184,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
it('should return a StateSet action informing other clients of the updated playing state', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(stateSlave, playPaused());
|
|
|
+ const result = globalEffects(stateSlave, action, globalReducer(stateSlave, action));
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -164,6 +194,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 5,
|
|
|
master: 'some-master-client',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -179,6 +210,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 83,
|
|
|
seekTime: 5,
|
|
|
master: 'some-master-client',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
myClientName: 'some-master-client',
|
|
|
};
|
|
|
@@ -188,7 +220,9 @@ describe(globalEffects.name, () => {
|
|
|
describe('when the client is master', () => {
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- expect(globalEffects(statePriorMaster, playPaused())).toBeNull();
|
|
|
+ expect(
|
|
|
+ globalEffects(statePriorMaster, action, globalReducer(statePriorMaster, action)),
|
|
|
+ ).toBeNull();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -200,7 +234,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
it('should return a StateSet action informing other clients of the changed song', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(stateSlave, action);
|
|
|
+ const result = globalEffects(stateSlave, action, globalReducer(stateSlave, action));
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -210,6 +244,7 @@ describe(globalEffects.name, () => {
|
|
|
currentTime: 0,
|
|
|
seekTime: 0,
|
|
|
master: 'some-master-client',
|
|
|
+ queue: [],
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -219,10 +254,49 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(stateSlave, actionNoReplace);
|
|
|
+ const result = globalEffects(
|
|
|
+ stateSlave,
|
|
|
+ actionNoReplace,
|
|
|
+ globalReducer(stateSlave, actionNoReplace),
|
|
|
+ );
|
|
|
expect(result).toBeNull();
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe.each`
|
|
|
+ description | action
|
|
|
+ ${ActionTypeLocal.QueuePushed} | ${queuePushed(123)}
|
|
|
+ ${ActionTypeLocal.QueueShifted} | ${queueShifted()}
|
|
|
+ ${ActionTypeLocal.QueueRemoved} | ${queueRemoved(84)}
|
|
|
+ ${ActionTypeLocal.QueueOrdered} | ${queueOrdered(17, -1)}
|
|
|
+ `('$description', ({ action }) => {
|
|
|
+ const statePrior: GlobalState = {
|
|
|
+ ...initialState,
|
|
|
+ player: {
|
|
|
+ songId: 123,
|
|
|
+ playing: true,
|
|
|
+ currentTime: 83,
|
|
|
+ seekTime: 5,
|
|
|
+ master: 'some-master-client',
|
|
|
+ queue: [13, 84, 17],
|
|
|
+ },
|
|
|
+ myClientName: 'some-other-client',
|
|
|
+ };
|
|
|
+
|
|
|
+ const nextState = globalReducer(statePrior, action);
|
|
|
+
|
|
|
+ it('should issue a state set action to update the queue', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(statePrior, action, nextState);
|
|
|
+ expect(result).toStrictEqual<RemoteAction>({
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
+ payload: {
|
|
|
+ ...statePrior.player,
|
|
|
+ queue: nextState.player.queue,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|