2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2015-03-26 06:43:41 +02:00
|
|
|
import TextTrackCueList from '../../../src/js/tracks/text-track-cue-list.js';
|
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
const genericTracks = [
|
2015-03-26 06:43:41 +02:00
|
|
|
{
|
|
|
|
id: '1'
|
|
|
|
}, {
|
|
|
|
id: '2'
|
|
|
|
}, {
|
|
|
|
id: '3'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.module('Text Track Cue List');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('TextTrackCueList\'s length is set correctly', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.length, genericTracks.length, 'the length is ' + genericTracks.length);
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('can get cues by id', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.getCueById('1').id, 1, 'id "1" has id of "1"');
|
|
|
|
assert.equal(ttcl.getCueById('2').id, 2, 'id "2" has id of "2"');
|
|
|
|
assert.equal(ttcl.getCueById('3').id, 3, 'id "3" has id of "3"');
|
|
|
|
assert.ok(!ttcl.getCueById(1), 'there isn\'t an item with "numeric" id of `1`');
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('length is updated when new tracks are added or removed', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.length, genericTracks.length + 1,
|
2016-08-03 21:27:47 +02:00
|
|
|
'the length is ' + (genericTracks.length + 1));
|
2015-02-14 01:18:07 +02:00
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}, {id: '101'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.length, genericTracks.length + 2,
|
2016-08-03 21:27:47 +02:00
|
|
|
'the length is ' + (genericTracks.length + 2));
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.length, genericTracks.length + 1,
|
2016-08-03 21:27:47 +02:00
|
|
|
'the length is ' + (genericTracks.length + 1));
|
2015-02-14 01:18:07 +02:00
|
|
|
ttcl.setCues_(genericTracks);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl.length, genericTracks.length, 'the length is ' + genericTracks.length);
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('can access items by index', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
|
|
|
const length = ttcl.length;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.expect(length);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
for (let i = 0; i < length; i++) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[i].id, String(i + 1), 'the id of a track matches the index + 1');
|
2015-02-14 01:18:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('can access new items by index', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}]));
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[3].id, '100', 'id of item at index 3 is 100');
|
2015-02-14 01:18:07 +02:00
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}, {id: '101'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[4].id, '101', 'id of item at index 4 is 101');
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('cannot access removed items by index', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}, {id: '101'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[3].id, '100', 'id of item at index 3 is 100');
|
|
|
|
assert.equal(ttcl[4].id, '101', 'id of item at index 4 is 101');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(!ttcl[3], 'nothing at index 3');
|
|
|
|
assert.ok(!ttcl[4], 'nothing at index 4');
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('new item available at old index', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttcl = new TextTrackCueList(genericTracks);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '100'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[3].id, '100', 'id of item at index 3 is 100');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(!ttcl[3], 'nothing at index 3');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttcl.setCues_(genericTracks.concat([{id: '101'}]));
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(ttcl[3].id, '101', 'id of new item at index 3 is now 101');
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|