2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2016-04-22 20:31:12 +02:00
|
|
|
import AudioTrack from '../../../src/js/tracks/audio-track.js';
|
|
|
|
import {AudioTrackKind} from '../../../src/js/tracks/track-enums.js';
|
|
|
|
import TrackBaseline from './track-baseline';
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.module('Audio Track');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// do baseline track testing
|
|
|
|
TrackBaseline(AudioTrack, {
|
|
|
|
id: '1',
|
|
|
|
language: 'en',
|
|
|
|
label: 'English',
|
2016-08-03 21:27:47 +02:00
|
|
|
kind: 'main'
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2023-03-22 16:00:01 +02:00
|
|
|
QUnit.test('can create an enabled property on an AudioTrack', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const enabled = true;
|
|
|
|
const track = new AudioTrack({
|
|
|
|
enabled
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
2016-08-03 21:27:47 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, enabled, 'enabled 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:47 +02:00
|
|
|
const track = new AudioTrack();
|
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');
|
|
|
|
assert.equal(track.enabled, false, 'enabled defaulted to true since there is one track');
|
|
|
|
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:47 +02:00
|
|
|
const track1 = new AudioTrack({
|
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:47 +02:00
|
|
|
for (const key in AudioTrackKind) {
|
|
|
|
const currentKind = AudioTrackKind[key];
|
|
|
|
const track = new AudioTrack({
|
|
|
|
kind: currentKind
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
2016-08-03 21:27:47 +02:00
|
|
|
|
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('enabled can only be instantiated to true or false, defaults to false', function(assert) {
|
2016-04-22 20:31:12 +02:00
|
|
|
let track = new AudioTrack({
|
|
|
|
enabled: 'foo'
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'the enabled value is set to false, not foo');
|
|
|
|
assert.notEqual(track.enabled, 'foo', 'the enabled value is not set to foo');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track = new AudioTrack({
|
|
|
|
enabled: true
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, true, 'the enabled value is set to true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track = new AudioTrack({
|
|
|
|
enabled: false
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'the enabled value is set to false');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('enabled can only be changed to true or false', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new AudioTrack();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = 'foo';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(track.enabled, 'foo', 'enabled not set to invalid value, foo');
|
|
|
|
assert.equal(track.enabled, false, 'enabled remains on the old value, false');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, true, 'enabled was set to true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = 'baz';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(track.enabled, 'baz', 'enabled not set to invalid value, baz');
|
|
|
|
assert.equal(track.enabled, true, 'enabled remains on the old value, true');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'enabled was set to false');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('when enabled is changed enabledchange event is fired', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new AudioTrack({
|
2016-04-22 20:31:12 +02:00
|
|
|
tech: this.tech,
|
|
|
|
enabled: false
|
|
|
|
});
|
|
|
|
let eventsTriggered = 0;
|
2016-08-03 21:27:47 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
track.addEventListener('enabledchange', () => {
|
|
|
|
eventsTriggered++;
|
|
|
|
});
|
|
|
|
|
|
|
|
// two events
|
|
|
|
track.enabled = true;
|
|
|
|
track.enabled = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 2, 'two enabled changes');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// no event here
|
|
|
|
track.enabled = false;
|
|
|
|
track.enabled = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 2, 'still two enabled changes');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// one event
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 3, 'three enabled changes');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
// no events
|
|
|
|
track.enabled = true;
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(eventsTriggered, 3, 'still three enabled changes');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
track.off();
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|