ad-cue-tags.test.js
7.26 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import QUnit from 'qunit';
import AdCueTags from '../src/ad-cue-tags';
import window from 'global/window';
QUnit.module('AdCueTags', {
beforeEach() {
this.track = {
cues: [],
addCue(cue) {
this.cues.push(cue);
},
clearTrack() {
this.cues = [];
}
};
}
});
QUnit.test('update tag cues', function() {
let testCue = new window.VTTCue(0, 10, 'test');
this.track.addCue(testCue);
AdCueTags.updateAdCues({}, this.track);
QUnit.equal(this.track.cues.length,
1,
'does not change cues if media does not have segment property');
QUnit.equal(this.track.cues[0],
testCue,
'does not change cues if media does not have segment property');
AdCueTags.updateAdCues({
segments: []
}, this.track);
QUnit.equal(this.track.cues.length,
1,
'does not remove cues even if no segments in playlist');
this.track.clearTrack();
AdCueTags.updateAdCues({
segments: [{
duration: 5.1,
cueOut: '11.5'
}, {
duration: 6.4,
cueOutCont: '5.1/11.5'
}, {
duration: 6,
cueIn: ''
}]
}, this.track, 10);
QUnit.equal(this.track.cues.length, 1, 'adds a single cue for entire ad');
testCue = this.track.cues[0];
QUnit.equal(testCue.startTime, 10, 'cue starts at 10');
QUnit.equal(testCue.endTime, 21.5, 'cue ends at start time plus duration');
this.track.clearTrack();
AdCueTags.updateAdCues({
segments: [{
duration: 10,
cueOutCont: '10/30'
}, {
duration: 10,
cueOutCont: '20/30'
}, {
duration: 10,
cueIn: ''
}]
}, this.track);
QUnit.equal(this.track.cues.length, 1,
'adds a single cue for entire ad when entering mid cue-out-cont');
testCue = this.track.cues[0];
QUnit.equal(testCue.startTime, 0, 'cue starts at 0');
QUnit.equal(testCue.endTime, 20, 'cue ends at start time plus duration');
QUnit.equal(testCue.adStartTime, -10, 'cue ad starts at -10');
QUnit.equal(testCue.adEndTime, 20, 'cue ad ends at 20');
});
QUnit.test('update incomplete cue in live playlist situation', function() {
AdCueTags.updateAdCues({
segments: [
{
duration: 10,
cueOut: '30'
},
{
duration: 10,
cueOutCont: '10/30'
}
]
}, this.track, 10);
QUnit.equal(this.track.cues.length, 1, 'adds a single cue for new ad');
let testCue = this.track.cues[0];
QUnit.equal(testCue.startTime, 10, 'cue starts at 10');
QUnit.equal(testCue.endTime, 30, 'cue ends at start time plus segment durations');
QUnit.equal(testCue.adStartTime, 10, 'cue ad starts at 10');
QUnit.equal(testCue.adEndTime, 40, 'cue ad ends at 40');
AdCueTags.updateAdCues({
segments: [
{
duration: 10,
cueOutCont: '10/30'
},
{
duration: 10,
cueOutCont: '20/30'
}
]
}, this.track, 20);
QUnit.equal(this.track.cues.length, 1, 'did not remove cue or add a new one');
QUnit.equal(testCue.startTime, 10, 'cue still starts at 10');
QUnit.equal(testCue.endTime, 40, 'cue end updated to include next segment duration');
QUnit.equal(testCue.adStartTime, 10, 'cue ad still starts at 10');
QUnit.equal(testCue.adEndTime, 40, 'cue ad still ends at 40');
AdCueTags.updateAdCues({
segments: [
{
duration: 10,
cueOutCont: '20/30'
},
{
duration: 10,
cueIn: ''
}
]
}, this.track, 30);
QUnit.equal(this.track.cues.length, 1, 'did not remove cue or add a new one');
QUnit.equal(testCue.startTime, 10, 'cue still starts at 10');
QUnit.equal(testCue.endTime, 40, 'cue end still 40');
QUnit.equal(testCue.adStartTime, 10, 'cue ad still starts at 10');
QUnit.equal(testCue.adEndTime, 40, 'cue ad still ends at 40');
});
QUnit.test('adjust cue end time in event of early CUE-IN', function() {
AdCueTags.updateAdCues({
segments: [
{
duration: 10,
cueOut: '30'
},
{
duration: 10,
cueOutCont: '10/30'
},
{
duration: 10,
cueOutCont: '20/30'
}
]
}, this.track, 10);
QUnit.equal(this.track.cues.length, 1, 'adds a single cue for new ad');
let testCue = this.track.cues[0];
QUnit.equal(testCue.startTime, 10, 'cue starts at 10');
QUnit.equal(testCue.endTime, 40, 'cue ends at start time plus segment durations');
QUnit.equal(testCue.adStartTime, 10, 'cue ad starts at 10');
QUnit.equal(testCue.adEndTime, 40, 'cue ad ends at 40');
AdCueTags.updateAdCues({
segments: [
{
duration: 10,
cueOutCont: '10/30'
},
{
duration: 10,
cueIn: ''
},
{
duration: 10
}
]
}, this.track, 20);
QUnit.equal(this.track.cues.length, 1, 'did not remove cue or add a new one');
QUnit.equal(testCue.startTime, 10, 'cue still starts at 10');
QUnit.equal(testCue.endTime, 30, 'cue end updated to 30');
QUnit.equal(testCue.adStartTime, 10, 'cue ad still starts at 10');
QUnit.equal(testCue.adEndTime, 30,
'cue ad end updated to 30 to account for early cueIn');
});
QUnit.test('correctly handle multiple ad cues', function() {
AdCueTags.updateAdCues({
segments: [
{
duration: 10
},
{
duration: 10
},
{
duration: 10
},
{
duration: 10,
cueOut: '30'
},
{
duration: 10,
cueOutCont: '10/30'
},
{
duration: 10,
cueOutCont: '20/30'
},
{
duration: 10,
cueIn: ''
},
{
duration: 10
},
{
duration: 10
},
{
duration: 10
},
{
duration: 10,
cueOut: '20'
},
{
duration: 10,
cueOutCont: '10/20'
},
{
duration: 10,
cueIn: ''
},
{
duration: 10
}
]
}, this.track);
QUnit.equal(this.track.cues.length, 2, 'correctly created 2 cues for the ads');
QUnit.equal(this.track.cues[0].startTime, 30, 'cue created at correct start time');
QUnit.equal(this.track.cues[0].endTime, 60, 'cue has correct end time');
QUnit.equal(this.track.cues[0].adStartTime, 30, 'cue has correct ad start time');
QUnit.equal(this.track.cues[0].adEndTime, 60, 'cue has correct ad end time');
QUnit.equal(this.track.cues[1].startTime, 100, 'cue created at correct start time');
QUnit.equal(this.track.cues[1].endTime, 120, 'cue has correct end time');
QUnit.equal(this.track.cues[1].adStartTime, 100, 'cue has correct ad start time');
QUnit.equal(this.track.cues[1].adEndTime, 120, 'cue has correct ad end time');
});
QUnit.test('findAdCue returns correct cue', function() {
this.track.cues = [
{
adStartTime: 0,
adEndTime: 30
},
{
adStartTime: 45,
adEndTime: 55
},
{
adStartTime: 100,
adEndTime: 120
}
];
let cue;
cue = AdCueTags.findAdCue(this.track, 15);
QUnit.equal(cue.adStartTime, 0, 'returned correct cue');
cue = AdCueTags.findAdCue(this.track, 40);
QUnit.equal(cue, null, 'cue not found, returned null');
cue = AdCueTags.findAdCue(this.track, 120);
QUnit.equal(cue.adStartTime, 100, 'returned correct cue');
cue = AdCueTags.findAdCue(this.track, 45);
QUnit.equal(cue.adStartTime, 45, 'returned correct cue');
});