1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/test/unit/tracks/track.test.js
claudiah12 ee0637c078
feat(track): make label property mutable and fire a labelchange event when the label is changed (#6928)
Allows the editing of a track's label after its creation. Menu buttons will listen for the labelchange event and update their content accordingly.

This is technically divergent from the spec, which says it's readonly, but it can be useful for Video.js users.

Co-authored-by: Claudia Hinkle <chinkle@chinkle-mn1.linkedin.biz>
2020-11-10 18:11:53 -05:00

59 lines
1.5 KiB
JavaScript

/* eslint-env qunit */
import TrackBaseline from './track-baseline';
import Track from '../../../src/js/tracks/track.js';
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
const defaultTech = {
textTracks() {
return new TextTrackList();
},
on() {},
off() {},
currentTime() {}
};
// do baseline track testing
QUnit.module('Track');
TrackBaseline(Track, {
id: '1',
kind: 'subtitles',
mode: 'disabled',
label: 'English',
language: 'en'
// tech is added in baseline
// tech: new TechFaker()
});
QUnit.test('defaults when items not provided', function(assert) {
const track = new Track({
tech: defaultTech
});
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');
assert.ok(track.id.match(/vjs_track_\d+/), 'id defaults to vjs_track_GUID');
});
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();
});