-
Notifications
You must be signed in to change notification settings - Fork 13
/
playbackRangeEnd.spec.tsx
198 lines (159 loc) · 5.81 KB
/
playbackRangeEnd.spec.tsx
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import React from 'react';
import { mount } from '@cypress/react';
import HoverVideoPlayer from 'react-hover-video-player';
import { makeMockVideoSrc } from '../utils';
import { videoElementSelector } from '../constants';
describe('Playback works as expected when only playbackRangeEnd is set', () => {
it('behaves correctly when loop is true and restartOnPaused is false', () => {
mount(
<HoverVideoPlayer
videoSrc={makeMockVideoSrc()}
playbackRangeEnd={0.5}
// loop is true by default
// restartOnPaused is false by default
/>
);
cy.checkVideoPlaybackState('paused');
// The video should initially be set to the start
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0);
// Mouse over the container to start loading/playing
cy.triggerEventOnPlayer('mouseenter');
cy.checkVideoPlaybackState('playing', 'The video should start playing');
cy.log('The video should play through to the end of its playback range');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('be.closeTo', 0.5, 0.03);
cy.log('The video should loop back the start');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('be.closeTo', 0, 0.03);
cy.checkVideoPlaybackState(
'playing',
'The video should still be playing after looping'
);
cy.log(
'The video should play through to the end of its playback range again'
);
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('be.closeTo', 0.5, 0.03);
cy.log('The video should be looped back around to the start again');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('be.closeTo', 0, 0.03);
cy.checkVideoPlaybackState(
'playing',
'The video should still be playing after looping a second time'
);
// Mouse out of the container to pause
cy.triggerEventOnPlayer('mouseleave');
cy.checkVideoPlaybackState('paused');
});
it('behaves correctly when loop is false and restartOnPaused is true', () => {
mount(
<HoverVideoPlayer
videoSrc={makeMockVideoSrc()}
playbackRangeEnd={0.5}
loop={false}
restartOnPaused
/>
);
cy.checkVideoPlaybackState('paused');
cy.log('The video should initially be set to the start of the video');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0);
// Mouse over the container to start loading/playing
cy.triggerEventOnPlayer('mouseenter');
cy.checkVideoPlaybackState('playing');
cy.log('The video should play through to the end of its duration');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
cy.checkVideoPlaybackState('paused');
cy.triggerEventOnPlayer('mouseleave');
cy.checkVideoPlaybackState('paused');
cy.log(
'The video should be reset to the start of the playback range when the user mouses out'
);
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0);
cy.triggerEventOnPlayer('mouseenter');
cy.checkVideoPlaybackState('playing');
cy.log('The video should play through to the end of its duration again');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
cy.checkVideoPlaybackState('paused');
});
it('behaves correctly when loop and restartOnPaused are both false', () => {
mount(
<HoverVideoPlayer
videoSrc={makeMockVideoSrc()}
playbackRangeEnd={0.5}
loop={false}
// restartOnPaused is false by default
/>
);
cy.checkVideoPlaybackState('paused');
cy.log('The video should initially be set to the start of the video');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0);
cy.log('Mouse over the container to start loading/playing');
cy.triggerEventOnPlayer('mouseenter');
cy.checkVideoPlaybackState('playing');
cy.log('The video should play through to the end of its playback range');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
cy.checkVideoPlaybackState('paused');
cy.triggerEventOnPlayer('mouseleave');
cy.checkVideoPlaybackState('paused');
cy.log('The video should still be stuck at the end of its duration');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
cy.triggerEventOnPlayer('mouseenter');
cy.checkVideoPlaybackState(
'paused',
'The video should stay paused because it is stuck at the end and restartOnPaused is false'
);
cy.log('The video should still be at the end of its duration');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
});
it('keeps the video inside the playback range', () => {
mount(
<HoverVideoPlayer
videoSrc={makeMockVideoSrc()}
playbackRangeEnd={0.5}
loop={false}
// restartOnPaused is false by default
/>
);
cy.log('The video should initially be set to the start');
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0);
cy.log(
"Attempt to set the video's time to after the end of the playback range"
);
cy.get(videoElementSelector).invoke('prop', 'currentTime', 5);
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 5);
// Make the video start playing
cy.triggerEventOnPlayer('mouseenter');
cy.log(
'The video should have been set back to the end of the playback range'
);
cy.get(videoElementSelector)
.invoke('prop', 'currentTime')
.should('equal', 0.5);
});
});