2016-08-03 15:27:03 -04:00
|
|
|
/* eslint-env qunit */
|
2016-04-22 14:31:12 -04:00
|
|
|
import TrackBaseline from './track-baseline';
|
|
|
|
import Track from '../../../src/js/tracks/track.js';
|
2017-01-19 15:16:28 -05:00
|
|
|
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
|
2016-04-22 14:31:12 -04:00
|
|
|
|
|
|
|
const defaultTech = {
|
2017-01-19 15:16:28 -05:00
|
|
|
textTracks() {
|
|
|
|
return new TextTrackList();
|
|
|
|
},
|
2016-04-22 14:31:12 -04:00
|
|
|
on() {},
|
|
|
|
off() {},
|
|
|
|
currentTime() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// do baseline track testing
|
2016-08-03 15:27:03 -04:00
|
|
|
QUnit.module('Track');
|
2016-04-22 14:31:12 -04:00
|
|
|
|
|
|
|
TrackBaseline(Track, {
|
|
|
|
id: '1',
|
|
|
|
kind: 'subtitles',
|
|
|
|
mode: 'disabled',
|
|
|
|
label: 'English',
|
2019-03-18 15:49:48 -04:00
|
|
|
language: 'en'
|
|
|
|
// tech is added in baseline
|
|
|
|
// tech: new TechFaker()
|
2016-04-22 14:31:12 -04:00
|
|
|
});
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('defaults when items not provided', function(assert) {
|
2016-08-03 15:27:03 -04:00
|
|
|
const track = new Track({
|
2016-04-22 14:31:12 -04:00
|
|
|
tech: defaultTech
|
|
|
|
});
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(track.kind, '', 'kind defaulted to empty string');
|
|
|
|
assert.equal(track.label, '', 'label defaults to empty string');
|
|
|
|
assert.equal(track.language, '', 'language defaults to empty string');
|
2017-01-18 01:52:23 -05:00
|
|
|
assert.ok(track.id.match(/vjs_track_\d+/), 'id defaults to vjs_track_GUID');
|
2016-04-22 14:31:12 -04:00
|
|
|
});
|
2020-11-10 18:11:53 -05:00
|
|
|
|
|
|
|
QUnit.test('label is updated and labelchange event is fired when label is changed', function(assert) {
|
|
|
|
const track = new Track({
|
|
|
|
tech: defaultTech
|
|
|
|
});
|
|
|
|
let eventsTriggered = 0;
|
|
|
|
|
|
|
|
track.addEventListener('labelchange', () => {
|
|
|
|
eventsTriggered++;
|
|
|
|
});
|
|
|
|
|
|
|
|
track.label = 'English (auto)';
|
|
|
|
assert.equal(eventsTriggered, 1, 'one label change');
|
|
|
|
assert.equal(track.label, 'English (auto)');
|
|
|
|
|
|
|
|
track.label = 'English (auto)';
|
|
|
|
assert.equal(eventsTriggered, 1, 'additional label change not fired when new label is the same as old');
|
|
|
|
assert.equal(track.label, 'English (auto)');
|
|
|
|
|
|
|
|
track.off();
|
|
|
|
});
|