Fixes of different issues

Video_player_spec wouldn't run because of a syntax error.
All test would fail when error() was called
on an undefined JQuery object.
Tidy up spy on onTouchBaseDevice.
Fix dependecies between RequireJs modules
This commit is contained in:
jmclaus
2013-07-22 14:18:39 -04:00
committed by Alexander Kryklia
parent 47dac695fa
commit af0149e52a
20 changed files with 76 additions and 87 deletions

View File

@@ -1,7 +1,10 @@
(function () { (function () {
describe('VideoAlpha', function () { describe('VideoAlpha', function () {
var oldOTBD;
beforeEach(function () { beforeEach(function () {
jasmine.stubRequests(); jasmine.stubRequests();
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
this.videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId'; this.videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId';
this.slowerSpeedYoutubeId = 'slowerSpeedYoutubeId'; this.slowerSpeedYoutubeId = 'slowerSpeedYoutubeId';
@@ -13,6 +16,7 @@
window.onYouTubePlayerAPIReady = undefined; window.onYouTubePlayerAPIReady = undefined;
window.onHTML5PlayerAPIReady = undefined; window.onHTML5PlayerAPIReady = undefined;
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function () { describe('constructor', function () {

View File

@@ -1,6 +1,6 @@
(function () { (function () {
describe('VideoAlpha HTML5Video', function () { describe('VideoAlpha HTML5Video', function () {
var state, player, playbackRates = [0.75, 1.0, 1.25, 1.5]; var state, player, oldOTBD, playbackRates = [0.75, 1.0, 1.25, 1.5];
function initialize() { function initialize() {
loadFixtures('videoalpha_html5.html'); loadFixtures('videoalpha_html5.html');
@@ -9,6 +9,8 @@
} }
beforeEach(function () { beforeEach(function () {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
initialize(); initialize();
player.config.events.onReady = jasmine.createSpy('onReady'); player.config.events.onReady = jasmine.createSpy('onReady');
}); });
@@ -18,6 +20,7 @@
$.fn.scrollTo.reset(); $.fn.scrollTo.reset();
$('.subtitles').remove(); $('.subtitles').remove();
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('events:', function () { describe('events:', function () {

View File

@@ -1,28 +1,7 @@
Jasmine JavaScript tests status Jasmine JavaScript tests status
------------------------------- -------------------------------
As of 18.07.2013, 12:55, each individual tests file in this directory passes. However, As of 22.07.2013, all the tests in this directory pass. To disable each of them, change the top level "describe(" to "xdescribe(".
if you try to run all of them at the same time, weird things start to happen. In some
cases the browser crashes, in other cases there are failing tests with extremely crazy
failing messages.
I [Valera Rozuvan] believe that this is due to the fact that almost in every file there
is present the function initialize() which is invoked many-many-many times throughout
the file. With each invocation, initialize() instantiates a new VideoAlpha instance.
It shouoldn't be necessary to instantiate a new VideoAlpha instance for each it() test.
Many it() tests can be run in sequence on the same VideoAlpha instance - it is just a
matter of correctly planning the order in which the it() tests are run.
So, you can do either:
a.) Run tests individually, changing in each file the top level "xdescribe(" to
"describe(". Make sure that you change it back to "xdescribe(" once you are done.
b.) Refactor all the VideoAlpha tests so that they can be run all at once.
Good luck ^_^v (and thanks for all the fish!)
PS: When you are running the tests in chrome locally, make sure that chrome is started PS: When you are running the tests in chrome locally, make sure that chrome is started
with the option "--allow-file-access-from-files". with the option "--allow-file-access-from-files".

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoCaptionAlpha', function() { describe('VideoCaptionAlpha', function() {
var state, videoPlayer, videoCaption, videoSpeedControl; var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('videoalpha_all.html');
@@ -11,6 +11,7 @@
} }
beforeEach(function() { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
initialize(); initialize();
}); });
@@ -20,6 +21,7 @@
$.fn.scrollTo.reset(); $.fn.scrollTo.reset();
$('.subtitles').remove(); $('.subtitles').remove();
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoControlAlpha', function() { describe('VideoControlAlpha', function() {
var state, videoControl; var state, videoControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('videoalpha_all.html');
@@ -8,13 +8,18 @@
videoControl = state.videoControl; videoControl = state.videoControl;
} }
beforeEach(function(){
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
});
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {
beforeEach(function() { beforeEach(function() {
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
initialize(); initialize();
}); });
@@ -46,10 +51,6 @@
initialize(); initialize();
}); });
afterEach(function(){
window.onTouchBasedDevice.andReturn(false);
});
it('does not add the play class to video control', function() { it('does not add the play class to video control', function() {
expect($('.video_control')).not.toHaveClass('play'); expect($('.video_control')).not.toHaveClass('play');
expect($('.video_control')).not.toHaveAttr('title', 'Play'); expect($('.video_control')).not.toHaveAttr('title', 'Play');

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoPlayerAlpha', function() { describe('VideoPlayerAlpha', function() {
var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl; var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD;
function initialize(fixture) { function initialize(fixture) {
if (typeof fixture === 'undefined') { if (typeof fixture === 'undefined') {
@@ -23,8 +23,14 @@
initialize('videoalpha.html'); initialize('videoalpha.html');
} }
beforeEach(function () {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
});
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {
@@ -68,7 +74,6 @@
it('create video progress slider', function() { it('create video progress slider', function() {
expect(videoProgressSlider).toBeDefined(); expect(videoProgressSlider).toBeDefined();
console.log('videoProgressSlider', videoProgressSlider, state, state.videoControl.sliderEl)
expect(videoProgressSlider.el).toHaveClass('slider'); expect(videoProgressSlider.el).toHaveClass('slider');
}); });
@@ -160,22 +165,11 @@
// }); // });
describe('when not on a touch based device', function() { describe('when not on a touch based device', function() {
var oldOTBD;
beforeEach(function() { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; window.onTouchBasedDevice.andReturn(true);
window.onTouchBasedDevice = function () {
return true;
};
initialize(); initialize();
}); });
afterEach(function () {
window.onTouchBasedDevice = oldOTBD;
});
it('does not add the tooltip to fullscreen button', function() { it('does not add the tooltip to fullscreen button', function() {
expect($('.add-fullscreen')).not.toHaveData('qtip'); expect($('.add-fullscreen')).not.toHaveData('qtip');
}); });
@@ -190,19 +184,9 @@
var oldOTBD; var oldOTBD;
beforeEach(function() { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = function () {
return false;
};
initialize(); initialize();
}); });
afterEach(function () {
window.onTouchBasedDevice = oldOTBD;
});
it('add the tooltip to fullscreen button', function() { it('add the tooltip to fullscreen button', function() {
expect($('.add-fullscreen')).toHaveData('qtip'); expect($('.add-fullscreen')).toHaveData('qtip');
}); });
@@ -759,7 +743,7 @@
it('set the player volume', function() { it('set the player volume', function() {
player.setVolume(60); player.setVolume(60);
expect(Number(player.getVolume().toFixed(1)).toEqual(0.6); expect(player.getVolume()).toEqual(0.6);
}); });
}); });
}); });

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoProgressSliderAlpha', function() { describe('VideoProgressSliderAlpha', function() {
var state, videoPlayer, videoProgressSlider; var state, videoPlayer, videoProgressSlider, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('videoalpha_all.html');
@@ -10,12 +10,14 @@
} }
beforeEach(function() { beforeEach(function() {
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
}); });
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoQualityControlAlpha', function() { describe('VideoQualityControlAlpha', function() {
var state, videoControl, videoQualityControl; var state, videoControl, videoQualityControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha.html'); loadFixtures('videoalpha.html');
@@ -9,9 +9,14 @@
videoQualityControl = state.videoQualityControl; videoQualityControl = state.videoQualityControl;
} }
beforeEach(function() {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
});
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {

View File

@@ -11,12 +11,14 @@
} }
beforeEach(function() { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
}); });
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {

View File

@@ -1,6 +1,6 @@
(function() { (function() {
describe('VideoVolumeControlAlpha', function() { describe('VideoVolumeControlAlpha', function() {
var state, videoControl, videoVolumeControl; var state, videoControl, videoVolumeControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('videoalpha_all.html');
@@ -9,10 +9,14 @@
videoVolumeControl = state.videoVolumeControl; videoVolumeControl = state.videoVolumeControl;
} }
beforeEach(function() {
oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
});
afterEach(function() { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function() {

View File

@@ -12,8 +12,8 @@
(function (requirejs, require, define) { (function (requirejs, require, define) {
define( define(
'videoalpha/display/initialize.js', 'videoalpha/02_initialize.js',
['videoalpha/display/video_player.js'], ['videoalpha/04_video_player.js'],
function (VideoPlayer) { function (VideoPlayer) {
/** /**

View File

@@ -14,7 +14,7 @@
(function (requirejs, require, define) { (function (requirejs, require, define) {
define( define(
'videoalpha/display/html5_video.js', 'videoalpha/03_html5_video.js',
[], [],
function () { function () {
var HTML5Video = {}; var HTML5Video = {};
@@ -67,7 +67,7 @@ function () {
if (isNaN(this.video.duration)) { if (isNaN(this.video.duration)) {
return 0; return 0;
} }
return this.video.duration; return this.video.duration;
}; };

View File

@@ -2,8 +2,8 @@
// VideoPlayer module. // VideoPlayer module.
define( define(
'videoalpha/display/video_player.js', 'videoalpha/04_video_player.js',
['videoalpha/display/html5_video.js'], ['videoalpha/03_html5_video.js'],
function (HTML5Video) { function (HTML5Video) {
// VideoPlayer() function - what this module "exports". // VideoPlayer() function - what this module "exports".

View File

@@ -2,7 +2,7 @@
// VideoControl module. // VideoControl module.
define( define(
'videoalpha/display/video_control.js', 'videoalpha/05_video_control.js',
[], [],
function () { function () {

View File

@@ -2,7 +2,7 @@
// VideoQualityControl module. // VideoQualityControl module.
define( define(
'videoalpha/display/video_quality_control.js', 'videoalpha/06_video_quality_control.js',
[], [],
function () { function () {

View File

@@ -9,7 +9,7 @@ mind, or whether to act, and in acting, to live."
// VideoProgressSlider module. // VideoProgressSlider module.
define( define(
'videoalpha/display/video_progress_slider.js', 'videoalpha/07_video_progress_slider.js',
[], [],
function () { function () {

View File

@@ -2,7 +2,7 @@
// VideoVolumeControl module. // VideoVolumeControl module.
define( define(
'videoalpha/display/video_volume_control.js', 'videoalpha/08_video_volume_control.js',
[], [],
function () { function () {

View File

@@ -2,7 +2,7 @@
// VideoSpeedControl module. // VideoSpeedControl module.
define( define(
'videoalpha/display/video_speed_control.js', 'videoalpha/09_video_speed_control.js',
[], [],
function () { function () {
@@ -44,7 +44,7 @@ function () {
state.videoControl.secondaryControlsEl.prepend(state.videoSpeedControl.el); state.videoControl.secondaryControlsEl.prepend(state.videoSpeedControl.el);
$.each(state.videoSpeedControl.speeds, function(index, speed) { $.each(state.videoSpeedControl.speeds, function(index, speed) {
//var link = $('<a href="#">' + speed + 'x</a>'); //var link = $('<a href="#">' + speed + 'x</a>');
var link = '<a href="#">' + speed + 'x</a>'; var link = '<a href="#">' + speed + 'x</a>';

View File

@@ -2,7 +2,7 @@
// VideoCaption module. // VideoCaption module.
define( define(
'videoalpha/display/video_caption.js', 'videoalpha/10_video_caption.js',
[], [],
function () { function () {
@@ -109,11 +109,11 @@ function () {
} }
function fetchCaption() { function fetchCaption() {
var _this = this; var _this = this, jQueryObject;
this.videoCaption.hideCaptions(this.hide_captions); this.videoCaption.hideCaptions(this.hide_captions);
$.getWithPrefix(this.videoCaption.captionURL(), function(captions) { jQueryObject = $.getWithPrefix(this.videoCaption.captionURL(), function(captions) {
_this.videoCaption.captions = captions.text; _this.videoCaption.captions = captions.text;
_this.videoCaption.start = captions.start; _this.videoCaption.start = captions.start;
_this.videoCaption.loaded = true; _this.videoCaption.loaded = true;
@@ -125,8 +125,11 @@ function () {
} else { } else {
_this.videoCaption.renderCaption(); _this.videoCaption.renderCaption();
} }
}) });
.error(function(){console.error('Subtitles not found. Upload subtitles to server!');});
if (typeof jQueryObject === 'undefined') {
console.error('Subtitles not found. Upload subtitles to server!');
}
} }
function captionURL() { function captionURL() {

View File

@@ -3,13 +3,13 @@
// Main module. // Main module.
require( require(
[ [
'videoalpha/display/initialize.js', 'videoalpha/02_initialize.js',
'videoalpha/display/video_control.js', 'videoalpha/05_video_control.js',
'videoalpha/display/video_quality_control.js', 'videoalpha/06_video_quality_control.js',
'videoalpha/display/video_progress_slider.js', 'videoalpha/07_video_progress_slider.js',
'videoalpha/display/video_volume_control.js', 'videoalpha/08_video_volume_control.js',
'videoalpha/display/video_speed_control.js', 'videoalpha/09_video_speed_control.js',
'videoalpha/display/video_caption.js' 'videoalpha/10_video_caption.js'
], ],
function ( function (
Initialize, Initialize,