forked from u-wave/react-vimeo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
167 lines (137 loc) · 5.07 KB
/
test.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import expect, { createSpy } from 'expect';
import render from './util/render';
describe('Vimeo', () => {
it('should create a Vimeo player when mounted', async () => {
const onReady = createSpy();
const { sdkMock, playerMock } = render({
video: 169408731,
onReady,
});
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ id: 169408731 });
await playerMock.ready();
expect(onReady).toHaveBeenCalled();
expect(onReady.calls[0].arguments[0]).toBe(playerMock);
});
it('should use `url` prop for full vimeo URLs', async () => {
const { sdkMock } = render({ video: 'https://vimeo.com/179290396' });
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ url: 'https://vimeo.com/179290396' });
});
it('should all onError when `ready()` fails', async () => {
const onError = createSpy();
const { sdkMock } = render({
video: 404,
shouldFail: true,
onError,
});
await Promise.resolve();
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ id: 404 });
expect(onError).toHaveBeenCalled();
expect(onError.calls[0].arguments[0]).toEqual(new Error('artificial failure'));
});
it('should load a different video when "video" prop changes', async () => {
const { sdkMock, playerMock, rerender } = render({
video: 169408731,
});
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ id: 169408731 });
await rerender({ video: 162959050 });
expect(playerMock.loadVideo).toHaveBeenCalled();
expect(playerMock.loadVideo.calls[0].arguments[0]).toEqual(162959050);
});
it('should pause the video using the "paused" prop', async () => {
const { playerMock, rerender } = render({
video: 169408731,
autoplay: true,
});
// Don't call `play` again when we were already playing
await rerender({ paused: false });
expect(playerMock.play).toNotHaveBeenCalled();
await rerender({ paused: true });
expect(playerMock.pause).toHaveBeenCalled();
await rerender({ paused: false });
expect(playerMock.play).toHaveBeenCalled();
});
it('should set the volume using the "volume" prop', async () => {
const { playerMock, rerender } = render({
video: 169408731,
volume: 0.5,
});
expect(playerMock.setVolume).toHaveBeenCalledWith(0.5);
await rerender({ volume: 1 });
expect(playerMock.setVolume).toHaveBeenCalledWith(1);
});
it('should set the start time using the "start" prop', async () => {
const { playerMock, rerender } = render({
video: 169408731,
start: 60,
});
expect(playerMock.setCurrentTime).toHaveBeenCalledWith(60);
playerMock.setCurrentTime.reset();
await rerender({ start: 90 });
expect(playerMock.setCurrentTime).toNotHaveBeenCalled();
await rerender({ video: 169408732, start: 120 });
expect(playerMock.setCurrentTime).toHaveBeenCalledWith(120);
});
it('should set the player color using the "color" prop', async () => {
const { playerMock, sdkMock, rerender } = render({
video: 169408731,
color: '#0000ff',
});
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ color: '#0000ff' });
await rerender({ color: '#ff0000' });
expect(playerMock.setColor).toHaveBeenCalledWith('#ff0000');
await rerender({ color: '#00ff00' });
expect(playerMock.setColor).toHaveBeenCalledWith('#00ff00');
});
it('should set the looping flag using the "loop" prop', async () => {
const { playerMock, sdkMock, rerender } = render({
video: 169408731,
loop: false,
});
expect(sdkMock).toHaveBeenCalled();
expect(sdkMock.calls[0].arguments[1]).toMatch({ loop: false });
await rerender({ loop: true });
expect(playerMock.setLoop).toHaveBeenCalledWith(true);
await rerender({ loop: false });
expect(playerMock.setLoop).toHaveBeenCalledWith(false);
});
it('should set the iframe width/height using the width/height props', async () => {
const { sdkMock, playerMock, rerender } = render({
video: 169408731,
width: 640,
height: 320,
});
expect(sdkMock.calls[0].arguments[1]).toMatch({
width: 640,
height: 320,
});
await rerender({
width: '100%',
height: 800,
});
expect(playerMock.setWidth).toHaveBeenCalledWith('100%');
expect(playerMock.setHeight).toHaveBeenCalledWith(800);
});
it('should set the playback rate using the "playbackRate" props', async () => {
const { playerMock, rerender } = render({
video: 169408731,
playbackRate: 0.5,
});
expect(playerMock.setPlaybackRate).toHaveBeenCalledWith(0.5);
await rerender({ playbackRate: 2 });
expect(playerMock.setPlaybackRate).toHaveBeenCalledWith(2);
});
it('should destroy player when unmounting', async () => {
const { playerMock, unmount } = render({
video: 169408731,
width: 640,
height: 320,
});
await unmount();
expect(playerMock.destroy).toHaveBeenCalled();
});
});