-
Notifications
You must be signed in to change notification settings - Fork 437
Expand file tree
/
Copy pathdate-ranges.test.js
More file actions
136 lines (120 loc) · 3.96 KB
/
Copy pathdate-ranges.test.js
File metadata and controls
136 lines (120 loc) · 3.96 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
import QUnit from 'qunit';
// import sinon from 'sinon';
// import window from 'videojs-global-compat/window';
import DateRangesStorage from '../../src/util/date-ranges';
import xhrFactory from '../../src/xhr';
import { useFakeEnvironment } from '../test-helpers';
// needed for plugin registration
import '../../src/videojs-http-streaming';
QUnit.module('DateRanges storage', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.clock = this.env.clock;
this.requests = this.env.requests;
this.fakeVhs = {
xhr: xhrFactory()
};
},
afterEach() {
this.env.restore();
}
});
QUnit.test('offset is set', function(assert) {
const dateRangesStorage = new DateRangesStorage();
const segments = [{
programDateTime: 2000,
duration: 1
}, {
programDateTime: 3000,
duration: 1
}];
dateRangesStorage.setOffset(segments);
assert.equal(dateRangesStorage.offset_, 2, 'offset is the PDT of the first segment');
});
QUnit.test('daterange text track cues - endDate is used for endTime calculation', function(assert) {
const dateRangesStorage = new DateRangesStorage();
const segments = [{
programDateTime: 2000,
duration: 1
}, {
programDateTime: 3000,
duration: 1
}];
const dateRanges = [{
startDate: new Date(2000),
scte35Out: '0xFC30200C00C00000E4612424',
endDate: new Date(3000),
id: 'testId1'
}];
dateRangesStorage.setOffset(segments);
dateRangesStorage.setPendingDateRanges(dateRanges);
const dateRangesToProcess = dateRangesStorage.getDateRangesToProcess();
assert.equal(dateRangesToProcess.length, 1, '1 dateRange exists in dateRangesToProcess array');
assert.equal(dateRangesToProcess[0].endTime, 1);
});
QUnit.test('daterange text track cues - endOnNext and classList are used', function(assert) {
const dateRangesStorage = new DateRangesStorage();
const segments = [{
programDateTime: 2000,
duration: 1
}, {
programDateTime: 3000,
duration: 1
}];
const dateRanges = [{
startDate: new Date(3000),
scte35Out: '0xFC30200C00C00000E4612424',
id: 'testId1',
class: 'TestClass',
endOnNext: true
}, {
startDate: new Date(4000),
scte35Out: '0xFC3020034BCC00000E46',
id: 'testId2',
class: 'TestClass'
}];
dateRangesStorage.setOffset(segments);
dateRangesStorage.setPendingDateRanges(dateRanges);
const dateRangesToProcess = dateRangesStorage.getDateRangesToProcess();
assert.equal(dateRangesToProcess[0].endTime, 2, 'startTime of the next dateRange with the same class is used as endTime');
});
QUnit.test('daterange text track cues - plannedDuration is used for endTime calculation', function(assert) {
const dateRangesStorage = new DateRangesStorage();
const segments = [{
programDateTime: 2000,
duration: 1
}, {
programDateTime: 3000,
duration: 1
}];
const dateRanges = [{
startDate: new Date(3000),
scte35Out: '0xFC30200C00C00000E4612424',
id: 'testId1',
plannedDuration: 40
}];
dateRangesStorage.setOffset(segments);
dateRangesStorage.setPendingDateRanges(dateRanges);
const dateRangesToProcess = dateRangesStorage.getDateRangesToProcess();
assert.equal(dateRangesToProcess[0].endTime, 41, 'endTime is startTime + plannedDuration is used when endDate, class and duration not available');
});
QUnit.test('daterange text track cues - duration is used for endTime calculation', function(assert) {
const dateRangesStorage = new DateRangesStorage();
const segments = [{
programDateTime: 2000,
duration: 1
}, {
programDateTime: 3000,
duration: 1
}];
const dateRanges = [{
startDate: new Date(3000),
scte35Out: '0xFC30200C00C00000E4612424',
id: 'testId1',
duration: 40
}];
dateRangesStorage.setOffset(segments);
dateRangesStorage.setPendingDateRanges(dateRanges);
const dateRangesToProcess = dateRangesStorage.getDateRangesToProcess();
assert.equal(dateRangesToProcess[0].endTime, 41, 'duration is used when endDate and class not available');
});