| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- import { ActionTypeRemote, stateSet } from './actions';
- import { GlobalState, initialState } from './reducer';
- import { isActiveClient, isFromOurselves, isMaster, willBeMaster } from './selectors';
- describe('isMaster', () => {
- describe('when the master player is the current client', () => {
- it('should return true', () => {
- expect.assertions(1);
- expect(
- isMaster({
- player: { ...initialState.player, master: 'my-client-name' },
- myClientName: 'my-client-name',
- }),
- ).toBe(true);
- });
- });
- describe('when the master player is not the current client', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(
- isMaster({
- player: { ...initialState.player, master: 'other-client-name' },
- myClientName: 'my-client-name',
- }),
- ).toBe(false);
- });
- });
- describe('when there is no master player', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(
- isMaster({
- player: { ...initialState.player, master: '' },
- myClientName: 'my-client-name',
- }),
- ).toBe(false);
- });
- });
- });
- describe('isActiveClient', () => {
- describe('when the client is master', () => {
- it('should return true', () => {
- expect.assertions(1);
- expect(
- isActiveClient({
- player: { ...initialState.player, master: 'my-client-name', activeClients: [] },
- myClientName: 'my-client-name',
- }),
- ).toBe(true);
- });
- });
- describe('when the client is a slave', () => {
- describe('when the client is in the active clients list', () => {
- it('should return true', () => {
- expect.assertions(1);
- expect(
- isActiveClient({
- player: {
- ...initialState.player,
- master: 'some-other-client',
- activeClients: ['my-client-name'],
- },
- myClientName: 'my-client-name',
- }),
- ).toBe(true);
- });
- });
- describe('when the client is not in the active clients list', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(
- isActiveClient({
- player: {
- ...initialState.player,
- master: 'some-other-client',
- activeClients: ['different-client-name'],
- },
- myClientName: 'my-client-name',
- }),
- ).toBe(false);
- });
- });
- });
- });
- describe('isFromOurselves', () => {
- describe('when an action was dispatched from the current client', () => {
- it('should return true', () => {
- expect.assertions(1);
- expect(
- isFromOurselves(
- { myClientName: 'my-client-name' },
- {
- type: ActionTypeRemote.StateSet,
- fromClient: 'my-client-name',
- payload: {} as GlobalState,
- },
- ),
- ).toBe(true);
- });
- });
- describe('when an action was dispatched from a different client', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(
- isFromOurselves(
- { myClientName: 'my-client-name' },
- {
- type: ActionTypeRemote.StateSet,
- fromClient: 'some-other-client-name',
- payload: {} as GlobalState,
- },
- ),
- ).toBe(false);
- });
- });
- describe('when an action was not dispatched from a client', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(
- isFromOurselves(
- { myClientName: 'my-client-name' },
- {
- type: ActionTypeRemote.StateSet,
- fromClient: null,
- payload: {} as GlobalState,
- },
- ),
- ).toBe(false);
- });
- });
- });
- describe('willBeMaster', () => {
- describe('when the action will cause the current client to be master', () => {
- it('should return true', () => {
- expect.assertions(1);
- expect(
- willBeMaster({ myClientName: 'a-slave-client' }, stateSet({ master: 'a-slave-client' })),
- ).toBe(true);
- });
- });
- describe('when the action will not change the master', () => {
- it('should return false', () => {
- expect.assertions(1);
- expect(willBeMaster({ myClientName: 'a-slave-client' }, stateSet({ seekTime: 123 }))).toBe(
- false,
- );
- });
- describe('but the current client is already master', () => {
- it('should still return false', () => {
- expect.assertions(1);
- expect(
- willBeMaster(
- { myClientName: 'a-client', player: { ...initialState.player, master: 'a-client' } },
- stateSet({ seekTime: 123 }),
- ),
- ).toBe(false);
- });
- });
- });
- });
|