|
@@ -38,16 +38,28 @@ describe(globalEffects.name, () => {
|
|
|
shuffleMode: false,
|
|
shuffleMode: false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const action = stateSet(localPlayer, 3);
|
|
|
|
|
|
|
+ const action = stateSet(localPlayer);
|
|
|
|
|
|
|
|
const result = globalEffects(state, action);
|
|
const result = globalEffects(state, action);
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 3,
|
|
|
|
|
payload: { ...state.player, ...localPlayer },
|
|
payload: { ...state.player, ...localPlayer },
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ describe('when the payload is a partial', () => {
|
|
|
|
|
+ const actionPartial = stateSet({ master: 'my-client-name', currentTime: 143 });
|
|
|
|
|
+
|
|
|
|
|
+ it('should create a partial remote state set action', () => {
|
|
|
|
|
+ expect.assertions(1);
|
|
|
|
|
+ const result = globalEffects(state, actionPartial);
|
|
|
|
|
+ expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
|
|
+ type: ActionTypeRemote.StateSet,
|
|
|
|
|
+ payload: { master: 'my-client-name', currentTime: 143 },
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe(ActionTypeLocal.Seeked, () => {
|
|
describe(ActionTypeLocal.Seeked, () => {
|
|
@@ -86,8 +98,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
- payload: { ...state.player, seekTime: 776 },
|
|
|
|
|
|
|
+ payload: { seekTime: 776 },
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -112,13 +123,12 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
const action = masterSet();
|
|
const action = masterSet();
|
|
|
|
|
|
|
|
- it('should return a StateSet action informing other clients that we are the new master', () => {
|
|
|
|
|
|
|
+ it('should return a full StateSet action informing other clients that we are the new master', () => {
|
|
|
expect.assertions(1);
|
|
expect.assertions(1);
|
|
|
const result = globalEffects(stateMasterWentAway, action);
|
|
const result = globalEffects(stateMasterWentAway, action);
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
songId: 123,
|
|
songId: 123,
|
|
|
playing: false,
|
|
playing: false,
|
|
@@ -133,13 +143,12 @@ describe(globalEffects.name, () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('when the action specified a particular client', () => {
|
|
describe('when the action specified a particular client', () => {
|
|
|
- it('should return a StateSet action informing the new client to resume playback', () => {
|
|
|
|
|
|
|
+ it('should return a full StateSet action informing the new client to take over master status', () => {
|
|
|
expect.assertions(1);
|
|
expect.assertions(1);
|
|
|
const result = globalEffects(stateMasterWentAway, masterSet('other-client'));
|
|
const result = globalEffects(stateMasterWentAway, masterSet('other-client'));
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
songId: 123,
|
|
songId: 123,
|
|
|
playing: true,
|
|
playing: true,
|
|
@@ -173,10 +182,9 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
- payload: expect.objectContaining({
|
|
|
|
|
|
|
+ payload: {
|
|
|
activeClients: ['other-client'],
|
|
activeClients: ['other-client'],
|
|
|
- }),
|
|
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -196,10 +204,9 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
- payload: expect.objectContaining({
|
|
|
|
|
|
|
+ payload: {
|
|
|
activeClients: expect.arrayContaining(['some-client', 'other-client']),
|
|
activeClients: expect.arrayContaining(['some-client', 'other-client']),
|
|
|
- }),
|
|
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -234,16 +241,8 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
- songId: 123,
|
|
|
|
|
playing: false,
|
|
playing: false,
|
|
|
- currentTime: 83,
|
|
|
|
|
- seekTime: 5,
|
|
|
|
|
- master: 'some-master-client',
|
|
|
|
|
- activeClients: [],
|
|
|
|
|
- queue: [],
|
|
|
|
|
- shuffleMode: false,
|
|
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -287,16 +286,11 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
songId: 185,
|
|
songId: 185,
|
|
|
playing: true,
|
|
playing: true,
|
|
|
currentTime: 0,
|
|
currentTime: 0,
|
|
|
seekTime: 0,
|
|
seekTime: 0,
|
|
|
- master: 'some-master-client',
|
|
|
|
|
- activeClients: [],
|
|
|
|
|
- queue: [],
|
|
|
|
|
- shuffleMode: false,
|
|
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -316,21 +310,17 @@ describe(globalEffects.name, () => {
|
|
|
describe(ActionTypeLocal.QueuePushed, () => {
|
|
describe(ActionTypeLocal.QueuePushed, () => {
|
|
|
const action = queuePushed([184, 79]);
|
|
const action = queuePushed([184, 79]);
|
|
|
|
|
|
|
|
|
|
+ const stateWithQueue: GlobalState = {
|
|
|
|
|
+ ...initialState,
|
|
|
|
|
+ player: { ...initialState.player, master: 'some-master', queue: [23] },
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
it('should add to the end of the queue', () => {
|
|
it('should add to the end of the queue', () => {
|
|
|
expect.assertions(1);
|
|
expect.assertions(1);
|
|
|
- const result = globalEffects(
|
|
|
|
|
- {
|
|
|
|
|
- ...initialState,
|
|
|
|
|
- player: { ...initialState.player, master: 'some-master', queue: [23] },
|
|
|
|
|
- },
|
|
|
|
|
- action,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const result = globalEffects(stateWithQueue, action);
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
- ...initialState.player,
|
|
|
|
|
- master: 'some-master',
|
|
|
|
|
queue: [23, 184, 79],
|
|
queue: [23, 184, 79],
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
@@ -363,10 +353,7 @@ describe(globalEffects.name, () => {
|
|
|
const result = globalEffects(stateWithQueue, action);
|
|
const result = globalEffects(stateWithQueue, action);
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
- ...initialState.player,
|
|
|
|
|
- master: 'some-master',
|
|
|
|
|
playing: true,
|
|
playing: true,
|
|
|
songId: 8843,
|
|
songId: 8843,
|
|
|
currentTime: 0,
|
|
currentTime: 0,
|
|
@@ -392,10 +379,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
- ...initialState.player,
|
|
|
|
|
- master: 'some-master',
|
|
|
|
|
queue: [17, 23],
|
|
queue: [17, 23],
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
@@ -421,10 +405,7 @@ describe(globalEffects.name, () => {
|
|
|
|
|
|
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
expect(result).toStrictEqual<ActionStateSetRemote>({
|
|
|
type: ActionTypeRemote.StateSet,
|
|
type: ActionTypeRemote.StateSet,
|
|
|
- priority: 0,
|
|
|
|
|
payload: {
|
|
payload: {
|
|
|
- ...initialState.player,
|
|
|
|
|
- master: 'some-master',
|
|
|
|
|
queue: expectedResult,
|
|
queue: expectedResult,
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|