2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-05-04 01:12:38 +02:00
|
|
|
import videojs from '../../src/js/video.js';
|
|
|
|
import TestHelpers from './test-helpers.js';
|
2015-11-10 00:43:17 +02:00
|
|
|
import * as Dom from '../../src/js/utils/dom.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import document from 'global/document';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('video.js');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should create a video tag and have access children in old IE', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2013-02-09 01:18:49 +03:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"><source type="video/mp4"></video>';
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const vid = document.getElementById('test_vid_id');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(vid.childNodes.length === 1);
|
|
|
|
assert.ok(vid.childNodes[0].getAttribute('type') === 'video/mp4');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
|
|
|
assert.ok(videojs.getPlayers().test_vid_id === player,
|
2016-08-03 21:27:03 +02:00
|
|
|
'added player to global reference');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs('test_vid_id');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2016-08-03 21:27:03 +02:00
|
|
|
});
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance from el html5 tech', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = videojs(vid);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
|
|
|
assert.ok(videojs.getPlayers().test_vid_id === player,
|
2016-08-03 21:27:03 +02:00
|
|
|
'added player to global reference');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance from el techfaker', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
const player = videojs(vid, {techOrder: ['techFaker']});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
|
|
|
assert.ok(videojs.getPlayers().test_vid_id === player,
|
2016-08-03 21:27:03 +02:00
|
|
|
'added player to global reference');
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2015-05-20 00:33:52 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2015-05-20 00:33:52 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2016-08-03 21:27:03 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add the value to the languages object', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const code = 'es';
|
|
|
|
const data = {Hello: 'Hola'};
|
|
|
|
const result = videojs.addLanguage(code, data);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(videojs.options.languages[code], 'should exist');
|
|
|
|
assert.equal(videojs.options.languages.es.Hello, 'Hola', 'should match');
|
|
|
|
assert.deepEqual(result.Hello, videojs.options.languages.es.Hello, 'should also match');
|
2015-05-20 00:33:52 +02:00
|
|
|
});
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add the value to the languages object with lower case lang code', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const code = 'DE';
|
|
|
|
const data = {Hello: 'Guten Tag'};
|
|
|
|
const result = videojs.addLanguage(code, data);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(videojs.options.languages[code.toLowerCase()], 'should exist');
|
|
|
|
assert.equal(videojs.options.languages[code.toLowerCase()].Hello,
|
2016-08-03 21:27:03 +02:00
|
|
|
'Guten Tag',
|
|
|
|
'should match');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(result,
|
2016-08-03 21:27:03 +02:00
|
|
|
videojs.options.languages[code.toLowerCase()],
|
|
|
|
'should also match');
|
|
|
|
});
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should expose plugin registry function', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const pluginName = 'foo';
|
|
|
|
const pluginFunction = function(options) {};
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(videojs.plugin, 'should exist');
|
2015-05-04 01:12:38 +02:00
|
|
|
|
|
|
|
videojs.plugin(pluginName, pluginFunction);
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player.foo, 'should exist');
|
|
|
|
assert.equal(player.foo, pluginFunction, 'should be equal');
|
2016-08-25 16:58:42 +02:00
|
|
|
player.dispose();
|
2015-05-04 01:12:38 +02:00
|
|
|
});
|
2015-07-30 18:10:04 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should expose options and players properties for backward-compatibility', function(assert) {
|
|
|
|
assert.ok(typeof videojs.options, 'object', 'options should be an object');
|
|
|
|
assert.ok(typeof videojs.players, 'object', 'players should be an object');
|
2015-07-30 18:10:04 +02:00
|
|
|
});
|
2015-11-10 00:43:17 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should expose DOM functions', function(assert) {
|
2015-11-10 00:43:17 +02:00
|
|
|
|
|
|
|
// Keys are videojs methods, values are Dom methods.
|
2016-08-03 21:27:03 +02:00
|
|
|
const methods = {
|
2015-11-10 00:43:17 +02:00
|
|
|
isEl: 'isEl',
|
|
|
|
isTextNode: 'isTextNode',
|
2016-01-08 06:03:23 +02:00
|
|
|
createEl: 'createEl',
|
2015-11-10 00:43:17 +02:00
|
|
|
hasClass: 'hasElClass',
|
|
|
|
addClass: 'addElClass',
|
|
|
|
removeClass: 'removeElClass',
|
|
|
|
toggleClass: 'toggleElClass',
|
|
|
|
setAttributes: 'setElAttributes',
|
|
|
|
getAttributes: 'getElAttributes',
|
|
|
|
emptyEl: 'emptyEl',
|
|
|
|
insertContent: 'insertContent',
|
|
|
|
appendContent: 'appendContent'
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const keys = Object.keys(methods);
|
2015-11-10 00:43:17 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.expect(keys.length);
|
2015-11-10 00:43:17 +02:00
|
|
|
keys.forEach(function(vjsName) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const domName = methods[vjsName];
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.strictEqual(videojs[vjsName],
|
2016-08-03 21:27:03 +02:00
|
|
|
Dom[domName],
|
|
|
|
`videojs.${vjsName} is a reference to Dom.${domName}`);
|
2015-11-10 00:43:17 +02:00
|
|
|
});
|
|
|
|
});
|