|
|
@@ -8,12 +8,11 @@ import {
|
|
|
queuePushed,
|
|
|
queueRemoved,
|
|
|
queueShifted,
|
|
|
- RemoteAction,
|
|
|
seeked,
|
|
|
songInfoFetched,
|
|
|
stateSet,
|
|
|
} from '../actions';
|
|
|
-import { globalReducer, GlobalState, initialState } from '../reducer';
|
|
|
+import { GlobalState, initialState } from '../reducer';
|
|
|
import { Song } from '../types';
|
|
|
import { MusicPlayer } from '../types/state';
|
|
|
import { globalEffects } from './effects';
|
|
|
@@ -38,9 +37,8 @@ describe(globalEffects.name, () => {
|
|
|
};
|
|
|
|
|
|
const action = stateSet(localPlayer);
|
|
|
- const nextState = globalReducer(prevState, action);
|
|
|
|
|
|
- const result = globalEffects(prevState, action, nextState);
|
|
|
+ const result = globalEffects(prevState, action);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -79,7 +77,7 @@ describe(globalEffects.name, () => {
|
|
|
it('should create a remote state set action', () => {
|
|
|
expect.assertions(1);
|
|
|
|
|
|
- const result = globalEffects(state, action, globalReducer(state, action));
|
|
|
+ const result = globalEffects(state, action);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -108,11 +106,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
it('should return a StateSet action informing other clients that we are the new master', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(
|
|
|
- stateMasterWentAway,
|
|
|
- action,
|
|
|
- globalReducer(stateMasterWentAway, action),
|
|
|
- );
|
|
|
+ const result = globalEffects(stateMasterWentAway, action);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -130,11 +124,7 @@ 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'),
|
|
|
- globalReducer(stateMasterWentAway, masterSet('other-client')),
|
|
|
- );
|
|
|
+ const result = globalEffects(stateMasterWentAway, masterSet('other-client'));
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -170,9 +160,7 @@ describe(globalEffects.name, () => {
|
|
|
describe('when the client is master', () => {
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- expect(
|
|
|
- globalEffects(statePriorMaster, action, globalReducer(statePriorMaster, action)),
|
|
|
- ).toBeNull();
|
|
|
+ expect(globalEffects(statePriorMaster, action)).toBeNull();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -184,7 +172,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, action, globalReducer(stateSlave, action));
|
|
|
+ const result = globalEffects(stateSlave, action);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -220,9 +208,7 @@ describe(globalEffects.name, () => {
|
|
|
describe('when the client is master', () => {
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- expect(
|
|
|
- globalEffects(statePriorMaster, action, globalReducer(statePriorMaster, action)),
|
|
|
- ).toBeNull();
|
|
|
+ expect(globalEffects(statePriorMaster, action)).toBeNull();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -234,7 +220,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, globalReducer(stateSlave, action));
|
|
|
+ const result = globalEffects(stateSlave, action);
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
@@ -254,47 +240,118 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
it('should return null', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(
|
|
|
- stateSlave,
|
|
|
- actionNoReplace,
|
|
|
- globalReducer(stateSlave, actionNoReplace),
|
|
|
- );
|
|
|
+ const result = globalEffects(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 = {
|
|
|
+ describe(ActionTypeLocal.QueuePushed, () => {
|
|
|
+ const action = queuePushed(184);
|
|
|
+
|
|
|
+ it('should add to the end of the queue', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(
|
|
|
+ {
|
|
|
+ ...initialState,
|
|
|
+ player: { ...initialState.player, queue: [23] },
|
|
|
+ },
|
|
|
+ action,
|
|
|
+ );
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
+ payload: {
|
|
|
+ ...initialState.player,
|
|
|
+ queue: [23, 184],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when the song is already in the queue', () => {
|
|
|
+ it('should not modify the queue', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(
|
|
|
+ {
|
|
|
+ ...initialState,
|
|
|
+ player: { ...initialState.player, queue: [184, 23] },
|
|
|
+ },
|
|
|
+ action,
|
|
|
+ );
|
|
|
+ expect(result).toBeNull();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe(ActionTypeLocal.QueueShifted, () => {
|
|
|
+ const action = queueShifted();
|
|
|
+ const stateWithQueue: GlobalState = {
|
|
|
...initialState,
|
|
|
- player: {
|
|
|
- songId: 123,
|
|
|
- playing: true,
|
|
|
- currentTime: 83,
|
|
|
- seekTime: 5,
|
|
|
- master: 'some-master-client',
|
|
|
- queue: [13, 84, 17],
|
|
|
- },
|
|
|
- myClientName: 'some-other-client',
|
|
|
+ player: { ...initialState.player, queue: [8843, 23] },
|
|
|
};
|
|
|
|
|
|
- const nextState = globalReducer(statePrior, action);
|
|
|
+ it('should play the first song on the queue and remove it from the queue', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(stateWithQueue, action);
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
+ payload: {
|
|
|
+ ...initialState.player,
|
|
|
+ playing: true,
|
|
|
+ songId: 8843,
|
|
|
+ currentTime: 0,
|
|
|
+ seekTime: 0,
|
|
|
+ queue: [23],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe(ActionTypeLocal.QueueRemoved, () => {
|
|
|
+ const action = queueRemoved(84);
|
|
|
|
|
|
- it('should issue a state set action to update the queue', () => {
|
|
|
+ it('should remove the given song ID from the queue', () => {
|
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(statePrior, action, nextState);
|
|
|
- expect(result).toStrictEqual<RemoteAction>({
|
|
|
+ const result = globalEffects(
|
|
|
+ {
|
|
|
+ ...initialState,
|
|
|
+ player: { ...initialState.player, queue: [17, 84, 23] },
|
|
|
+ },
|
|
|
+ action,
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
+ payload: {
|
|
|
+ ...initialState.player,
|
|
|
+ queue: [17, 23],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe(ActionTypeLocal.QueueOrdered, () => {
|
|
|
+ it.each`
|
|
|
+ direction | delta | expectedResult
|
|
|
+ ${'forwards'} | ${1} | ${[17, 23, 84]}
|
|
|
+ ${'backwards'} | ${-1} | ${[84, 17, 23]}
|
|
|
+ `('should reorder ($direction) the given song ID', ({ delta, expectedResult }) => {
|
|
|
+ const action = queueOrdered(84, delta);
|
|
|
+
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(
|
|
|
+ {
|
|
|
+ ...initialState,
|
|
|
+ player: { ...initialState.player, queue: [17, 84, 23] },
|
|
|
+ },
|
|
|
+ action,
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
|
payload: {
|
|
|
- ...statePrior.player,
|
|
|
- queue: nextState.player.queue,
|
|
|
+ ...initialState.player,
|
|
|
+ queue: expectedResult,
|
|
|
},
|
|
|
});
|
|
|
});
|