2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2016-04-22 20:31:12 +02:00
|
|
|
import VideoTrack from '../../../src/js/tracks/video-track';
|
|
|
|
import {VideoTrackKind} from '../../../src/js/tracks/track-enums';
|
|
|
|
import TrackBaseline from './track-baseline';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('Video Track');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// do baseline track testing
|
|
|
|
TrackBaseline(VideoTrack, {
|
|
|
|
id: '1',
|
|
|
|
language: 'en',
|
|
|
|
label: 'English',
|
2016-08-03 21:27:03 +02:00
|
|
|
kind: 'main'
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('can create an VideoTrack a selected property', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const selected = true;
|
|
|
|
const track = new VideoTrack({
|
|
|
|
selected
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
2016-08-03 21:27:03 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, selected, 'selected value matches what we passed in');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('defaults when items not provided', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track = new VideoTrack();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.kind, '', 'kind defaulted to empty string');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
track.selected,
|
|
|
|
false,
|
|
|
|
'selected defaulted to true since there is one track'
|
|
|
|
);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.label, '', 'label defaults to empty string');
|
|
|
|
assert.equal(track.language, '', 'language defaults to empty string');
|
2017-01-18 08:52:23 +02:00
|
|
|
assert.ok(track.id.match(/vjs_track_\d+/), 'id defaults to vjs_track_GUID');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('kind can only be one of several options, defaults to empty string', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track1 = new VideoTrack({
|
2016-04-22 20:31:12 +02:00
|
|
|
kind: 'foo'
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track1.kind, '', 'the kind is set to empty string, not foo');
|
|
|
|
assert.notEqual(track1.kind, 'foo', 'the kind is set to empty string, not foo');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// loop through all possible kinds to verify
|
2016-08-03 21:27:03 +02:00
|
|
|
for (const key in VideoTrackKind) {
|
|
|
|
const currentKind = VideoTrackKind[key];
|
|
|
|
const track = new VideoTrack({kind: currentKind});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.kind, currentKind, 'the kind is set to ' + currentKind);
|
2016-04-22 20:31:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('selected can only be instantiated to true or false, defaults to false', function(assert) {
|
2016-04-22 20:31:12 +02:00
|
|
|
let track = new VideoTrack({
|
|
|
|
selected: 'foo'
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, false, 'the selected value is set to false, not foo');
|
|
|
|
assert.notEqual(track.selected, 'foo', 'the selected value is not set to foo');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track = new VideoTrack({
|
|
|
|
selected: true
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, true, 'the selected value is set to true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track = new VideoTrack({
|
|
|
|
selected: false
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, false, 'the selected value is set to false');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('selected can only be changed to true or false', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track = new VideoTrack();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.selected = 'foo';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(track.selected, 'foo', 'selected not set to invalid value, foo');
|
|
|
|
assert.equal(track.selected, false, 'selected remains on the old value, false');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.selected = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, true, 'selected was set to true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.selected = 'baz';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(track.selected, 'baz', 'selected not set to invalid value, baz');
|
|
|
|
assert.equal(track.selected, true, 'selected remains on the old value, true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.selected = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.selected, false, 'selected was set to false');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('when selected is changed selectedchange event is fired', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track = new VideoTrack({
|
2016-04-22 20:31:12 +02:00
|
|
|
selected: false
|
|
|
|
});
|
|
|
|
let eventsTriggered = 0;
|
2016-08-03 21:27:03 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
track.addEventListener('selectedchange', () => {
|
|
|
|
eventsTriggered++;
|
|
|
|
});
|
|
|
|
|
|
|
|
// two events
|
|
|
|
track.selected = true;
|
|
|
|
track.selected = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 2, 'two selected changes');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// no event here
|
|
|
|
track.selected = false;
|
|
|
|
track.selected = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 2, 'still two selected changes');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// one event
|
|
|
|
track.selected = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 3, 'three selected changes');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
track.off();
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|