/
keyControlContainer.spec.jsx
137 lines (107 loc) · 3.28 KB
/
keyControlContainer.spec.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React from 'react';
import expect from 'expect';
import proxyquire from 'proxyquire';
import containerSetup from '../../../util/specHelpers/containerSetup.spec';
proxyquire.noCallThru();
let onKeyDown;
const id = 'TestPlayer';
const mockKeyControl = ({ keyBindings }) =>
<button onKeyDown={() => onKeyDown(keyBindings)} />;
const keyControlContainer = proxyquire('./keyControlContainer', {
'./keyControl': mockKeyControl,
}).default;
const setup = (jPlaylists, jPlayers, props) =>
containerSetup(keyControlContainer, jPlaylists, jPlayers, props);
describe('keyControlContainer', () => {
let jPlaylists;
let jPlayers;
beforeEach(() => {
jPlaylists = {
[id]: {
current: 0,
loop: 'off',
playlist: [
{
id: 0,
sources: {
mp3: 'test.mp3',
},
},
{
id: 1,
sources: {
mp3: 'testTwo.mp3',
},
},
],
},
};
jPlayers = {
[id]: {},
};
});
describe('custom keyBindings', () => {
it('merges custom keyBinding with different name', () => {
onKeyDown = ({ test }) => test.fn();
const customKeySpy = expect.createSpy();
const customKeyBindings = {
test: {
key: 20,
fn: customKeySpy,
},
};
const { wrapper } = setup(jPlaylists, jPlayers, { keyBindings: customKeyBindings });
wrapper.simulate('keydown');
expect(customKeySpy).toHaveBeenCalled();
});
it('custom keyBinding overwrite default function with same name', () => {
onKeyDown = ({ shuffle }) => shuffle.fn();
const customKeySpy = expect.createSpy();
const customKeyBindings = {
shuffle: {
fn: customKeySpy,
},
};
const { wrapper } = setup(jPlaylists, jPlayers, { keyBindings: customKeyBindings });
wrapper.simulate('keydown');
expect(customKeySpy).toHaveBeenCalled();
});
});
describe('next', () => {
it('plays next media', () => {
onKeyDown = ({ next }) => next.fn();
const { wrapper, store } = setup(jPlaylists, jPlayers);
wrapper.simulate('keydown');
const jPlaylist = store.getState().jPlaylists[id];
expect(jPlaylist.current).toBe(1);
});
});
describe('next', () => {
it('plays previous media', () => {
jPlaylists[id].current = 1;
onKeyDown = ({ previous }) => previous.fn();
const { wrapper, store } = setup(jPlaylists, jPlayers);
wrapper.simulate('keydown');
const jPlaylist = store.getState().jPlaylists[id];
expect(jPlaylist.current).toBe(0);
});
});
describe('shuffle', () => {
it('shuffles the media', () => {
onKeyDown = ({ shuffle }) => shuffle.fn();
const { wrapper, store } = setup(jPlaylists, jPlayers);
wrapper.simulate('keydown');
const jPlaylist = store.getState().jPlaylists[id];
expect(jPlaylist.shuffled).toBe(true);
});
});
describe('loop', () => {
it('loops the media', () => {
onKeyDown = ({ loop }) => loop.fn();
const { wrapper, store } = setup(jPlaylists, jPlayers);
wrapper.simulate('keydown');
const jPlaylist = store.getState().jPlaylists[id];
expect(jPlaylist.loop).toBe('loop');
});
});
});