|
|
@@ -5,9 +5,11 @@ import {
|
|
|
masterSet,
|
|
|
playPaused,
|
|
|
seeked,
|
|
|
+ songInfoFetched,
|
|
|
stateSet,
|
|
|
} from '../actions';
|
|
|
import { GlobalState, initialState } from '../reducer';
|
|
|
+import { Song } from '../types';
|
|
|
import { MusicPlayer } from '../types/state';
|
|
|
import { globalEffects } from './effects';
|
|
|
|
|
|
@@ -167,4 +169,60 @@ describe(globalEffects.name, () => {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe(ActionTypeLocal.SongInfoFetched, () => {
|
|
|
+ const statePriorMaster: GlobalState = {
|
|
|
+ ...initialState,
|
|
|
+ player: {
|
|
|
+ songId: 123,
|
|
|
+ playing: true,
|
|
|
+ currentTime: 83,
|
|
|
+ seekTime: 5,
|
|
|
+ master: 'some-master-client',
|
|
|
+ },
|
|
|
+ myClientName: 'some-master-client',
|
|
|
+ };
|
|
|
+
|
|
|
+ const action = songInfoFetched({ id: 185 } as Song, true);
|
|
|
+
|
|
|
+ describe('when the client is master', () => {
|
|
|
+ it('should return null', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ expect(globalEffects(statePriorMaster, playPaused())).toBeNull();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when the client is a slave', () => {
|
|
|
+ const stateSlave: GlobalState = {
|
|
|
+ ...statePriorMaster,
|
|
|
+ myClientName: 'some-slave-client',
|
|
|
+ };
|
|
|
+
|
|
|
+ it('should return a StateSet action informing other clients of the changed song', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(stateSlave, action);
|
|
|
+
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
+ payload: {
|
|
|
+ songId: 185,
|
|
|
+ playing: true,
|
|
|
+ currentTime: 0,
|
|
|
+ seekTime: 0,
|
|
|
+ master: 'some-master-client',
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when the action is not set to replace the current song', () => {
|
|
|
+ const actionNoReplace = songInfoFetched({ id: 185 } as Song, false);
|
|
|
+
|
|
|
+ it('should return null', () => {
|
|
|
+ expect.assertions(1);
|
|
|
+ const result = globalEffects(stateSlave, actionNoReplace);
|
|
|
+ expect(result).toBeNull();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|