Skip to content

Commit

Permalink
updated reducer unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
testtttt23 committed Aug 9, 2017
1 parent e971cab commit 5073d22
Showing 1 changed file with 188 additions and 149 deletions.
337 changes: 188 additions & 149 deletions src/reducer/reducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockMedia = (mediaType) => {
};
const id = 'TestPlayer';

describe('jPlayer reducer', () => {
describe('reducer', () => {
let state;

beforeEach(() => {
Expand Down Expand Up @@ -43,151 +43,157 @@ describe('jPlayer reducer', () => {
});
});

it('should handle generic SET_OPTION value', () => {
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'preload',
value: 'auto',
});
describe('SET_OPTION', () => {
it('should handle generic value', () => {
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'preload',
value: 'auto',
});

expect(newState[id]).toEqual({
preload: 'auto',
expect(newState[id]).toEqual({
preload: 'auto',
});
});
});

it('setOption handles media', () => {
mockMedia('audio');
const src = 'test.mp3';
it('should handle media', () => {
mockMedia('audio');
const src = 'test.mp3';

const media = {
sources: {
mp3: src,
},
};
const media = {
sources: {
mp3: src,
},
};

const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'media',
value: media,
});
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'media',
value: media,
});

expect(newState[id].media).toBe(media);
});
expect(newState[id].media).toBe(media);
});

it('setOption handles no media', () => {
const media = {};
it('should handle no media', () => {
const media = {};

const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'media',
value: media,
});
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'media',
value: media,
});

expect(newState[id]).toEqual({
...defaultStatus,
expect(newState[id]).toEqual({
...defaultStatus,
});
});
});

it('setOption handles playHeadPercent', () => {
const percent = 22.3;
const src = 'test.mp3';
it('should handle playHeadPercent', () => {
const percent = 22.3;
const src = 'test.mp3';

state[id].src = src;
state[id].src = src;

const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'playHeadPercent',
value: percent,
});
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'playHeadPercent',
value: percent,
});

expect(newState[id]).toEqual({
playHeadPercent: percent,
src,
expect(newState[id]).toEqual({
playHeadPercent: percent,
src,
});
});
});

it('setOption handles volume', () => {
const volume = 0.23;
it('should handle volume', () => {
const volume = 0.23;

const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'volume',
value: volume,
});
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'volume',
value: volume,
});

expect(newState[id]).toEqual({
volume,
muted: false,
expect(newState[id]).toEqual({
volume,
muted: false,
});
});
});

it('setOption handles muted', () => {
const mute = true;
it('should handle muted', () => {
const mute = true;

const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'muted',
value: mute,
});
const newState = reducer(state, {
type: actionNames.SET_OPTION,
id,
key: 'muted',
value: mute,
});

expect(newState[id]).toEqual({
muted: mute,
expect(newState[id]).toEqual({
muted: mute,
});
});
});

it('should handle SET_MEDIA', () => {
mockMedia('audio');
const src = 'test.mp3';
const media = {
sources: {
mp3: src,
},
};
describe('SET_MEDIA', () => {
it('should handle media', () => {
mockMedia('audio');

const newState = reducer(state, {
type: actionNames.SET_MEDIA,
id,
media,
});
const src = 'test.mp3';
const media = {
sources: {
mp3: src,
},
};

expect(newState[id]).toEqual({
...defaultStatus,
mediaSettings: {
formats: [{
supplied: 'mp3',
supported: 'probably',
}],
const newState = reducer(state, {
type: actionNames.SET_MEDIA,
id,
media,
});

expect(newState[id]).toEqual({
...defaultStatus,
mediaSettings: {
formats: [{
supplied: 'mp3',
supported: 'probably',
}],
video: false,
nonSupported: false,
},
media,
video: false,
nonSupported: false,
},
media,
video: false,
src,
error: undefined,
src,
error: undefined,
});
});
});

it('SET_MEDIA should handle non supported format', () => {
mockMedia('audio');
const media = {
sources: {
xxx: 'test.xxx',
},
};
it('should handle non supported format', () => {
mockMedia('audio');

const newState = reducer(state, {
type: actionNames.SET_MEDIA,
id,
media,
});
const media = {
sources: {
xxx: 'test.xxx',
},
};

const newState = reducer(state, {
type: actionNames.SET_MEDIA,
id,
media,
});

expect(newState[id].error).toExist();
expect(newState[id].error).toExist();
});
});

describe('PLAY', () => {
Expand Down Expand Up @@ -336,43 +342,76 @@ describe('jPlayer reducer', () => {
});
});

it('should handle MUTE', () => {
const newState = reducer(state, {
type: actionNames.MUTE,
id,
mute: true,
});
describe('MUTE', () => {
it('should set muted', () => {
const newState = reducer(state, {
type: actionNames.MUTE,
id,
mute: true,
});

expect(newState[id]).toEqual({
muted: true,
expect(newState[id]).toEqual({
muted: true,
});
});
});

// it('should handle MUTE', () => {
// reducerData.muteData.forEach((test) => {
// const jPlayer = reducer(state, test.action)[jPlayerOneId];

// Object.keys(test.expected).forEach((key) => {
// expect(jPlayer[key]).toEqual(test.expected[key]);
// });
// });
// });

// it('should handle FOCUS', () => {
// state = getDefaultJPlayers(3).jPlayers;

// reducerData.focusData.forEach((test) => {
// state[test.id] = test.state;

// const jPlayers = reducer(state, test.action);

// Object.keys(jPlayers).forEach((key) => {
// if (test.id !== key) {
// expect(jPlayers[key].focused).toBeFalsy();
// } else {
// expect(jPlayers[key].focused).toBeTruthy();
// }
// });
// });
// });
describe('FOCUS', () => {
it('does not focus if keyEnabled not true', () => {
const newState = reducer(state, {
type: actionNames.FOCUS,
id,
});

expect(newState[id]).toEqual({});
});

it('other player keeps focused if keyEnabled not true', () => {
state.SecondPlayer = {
keyEnabled: true,
focused: true,
};

const newState = reducer(state, {
type: actionNames.FOCUS,
id,
});

expect(newState.SecondPlayer).toEqual({
keyEnabled: true,
focused: true,
});
});

it('does focus if keyEnabled true', () => {
state[id].keyEnabled = true;

const newState = reducer(state, {
type: actionNames.FOCUS,
id,
});

expect(newState[id]).toEqual({
focused: true,
keyEnabled: true,
});
});

it('sets all other jPlayers focused to false if keyEnabled true', () => {
state.SecondPlayer = {
keyEnabled: true,
};
state[id].keyEnabled = true;

const newState = reducer(state, {
type: actionNames.FOCUS,
id,
});

expect(newState.SecondPlayer).toEqual({
keyEnabled: true,
focused: false,
});
});
});
});

0 comments on commit 5073d22

Please sign in to comment.