From af0149e52a5ddcaca0b4ea60abedd3ad59d0bfe6 Mon Sep 17 00:00:00 2001 From: jmclaus Date: Mon, 22 Jul 2013 14:18:39 -0400 Subject: [PATCH] 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 --- .../js/spec/videoalpha/general_spec.js | 4 +++ .../js/spec/videoalpha/html5_video_spec.js | 5 ++- .../xmodule/js/spec/videoalpha/readme.md | 23 +----------- .../js/spec/videoalpha/video_caption_spec.js | 4 ++- .../js/spec/videoalpha/video_control_spec.js | 13 +++---- .../js/spec/videoalpha/video_player_spec.js | 36 ++++++------------- .../videoalpha/video_progress_slider_spec.js | 6 ++-- .../videoalpha/video_quality_control_spec.js | 9 +++-- .../videoalpha/video_speed_control_spec.js | 4 ++- .../videoalpha/video_volume_control_spec.js | 8 +++-- .../js/src/videoalpha/02_initialize.js | 4 +-- .../js/src/videoalpha/03_html5_video.js | 4 +-- .../js/src/videoalpha/04_video_player.js | 4 +-- .../js/src/videoalpha/05_video_control.js | 2 +- .../videoalpha/06_video_quality_control.js | 2 +- .../videoalpha/07_video_progress_slider.js | 2 +- .../src/videoalpha/08_video_volume_control.js | 2 +- .../src/videoalpha/09_video_speed_control.js | 4 +-- .../js/src/videoalpha/10_video_caption.js | 13 ++++--- .../xmodule/js/src/videoalpha/11_main.js | 14 ++++---- 20 files changed, 76 insertions(+), 87 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js index dab066b91e..00f47dacaf 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js @@ -1,7 +1,10 @@ (function () { describe('VideoAlpha', function () { + var oldOTBD; + beforeEach(function () { jasmine.stubRequests(); + oldOTBD = window.onTouchBasedDevice; window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); this.videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId'; this.slowerSpeedYoutubeId = 'slowerSpeedYoutubeId'; @@ -13,6 +16,7 @@ window.onYouTubePlayerAPIReady = undefined; window.onHTML5PlayerAPIReady = undefined; $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function () { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/html5_video_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/html5_video_spec.js index 62c8844e5e..b8b03ee6bf 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/html5_video_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/html5_video_spec.js @@ -1,6 +1,6 @@ (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() { loadFixtures('videoalpha_html5.html'); @@ -9,6 +9,8 @@ } beforeEach(function () { + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); initialize(); player.config.events.onReady = jasmine.createSpy('onReady'); }); @@ -18,6 +20,7 @@ $.fn.scrollTo.reset(); $('.subtitles').remove(); $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('events:', function () { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/readme.md b/common/lib/xmodule/xmodule/js/spec/videoalpha/readme.md index d9b59ec8e9..9609faa2ee 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/readme.md +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/readme.md @@ -1,28 +1,7 @@ Jasmine JavaScript tests status ------------------------------- -As of 18.07.2013, 12:55, each individual tests file in this directory passes. However, -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!) - - +As of 22.07.2013, all the tests in this directory pass. To disable each of them, change the top level "describe(" to "xdescribe(". PS: When you are running the tests in chrome locally, make sure that chrome is started with the option "--allow-file-access-from-files". diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_caption_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_caption_spec.js index fd94979d89..b7ba8f585f 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_caption_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_caption_spec.js @@ -1,6 +1,6 @@ (function() { describe('VideoCaptionAlpha', function() { - var state, videoPlayer, videoCaption, videoSpeedControl; + var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD; function initialize() { loadFixtures('videoalpha_all.html'); @@ -11,6 +11,7 @@ } beforeEach(function() { + oldOTBD = window.onTouchBasedDevice; window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); initialize(); }); @@ -20,6 +21,7 @@ $.fn.scrollTo.reset(); $('.subtitles').remove(); $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_control_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_control_spec.js index a3c98320a8..dfa7a75368 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_control_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_control_spec.js @@ -1,6 +1,6 @@ (function() { describe('VideoControlAlpha', function() { - var state, videoControl; + var state, videoControl, oldOTBD; function initialize() { loadFixtures('videoalpha_all.html'); @@ -8,13 +8,18 @@ videoControl = state.videoControl; } + beforeEach(function(){ + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); + }); + afterEach(function() { $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { beforeEach(function() { - window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); initialize(); }); @@ -46,10 +51,6 @@ initialize(); }); - afterEach(function(){ - window.onTouchBasedDevice.andReturn(false); - }); - it('does not add the play class to video control', function() { expect($('.video_control')).not.toHaveClass('play'); expect($('.video_control')).not.toHaveAttr('title', 'Play'); diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_player_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_player_spec.js index b0f24ba09a..dc50060c0e 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_player_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_player_spec.js @@ -1,6 +1,6 @@ (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) { if (typeof fixture === 'undefined') { @@ -23,8 +23,14 @@ initialize('videoalpha.html'); } + beforeEach(function () { + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); + }); + afterEach(function() { - $('source').remove(); + $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { @@ -68,7 +74,6 @@ it('create video progress slider', function() { expect(videoProgressSlider).toBeDefined(); - console.log('videoProgressSlider', videoProgressSlider, state, state.videoControl.sliderEl) expect(videoProgressSlider.el).toHaveClass('slider'); }); @@ -160,22 +165,11 @@ // }); describe('when not on a touch based device', function() { - var oldOTBD; - beforeEach(function() { - oldOTBD = window.onTouchBasedDevice; - - window.onTouchBasedDevice = function () { - return true; - }; - + window.onTouchBasedDevice.andReturn(true); initialize(); }); - afterEach(function () { - window.onTouchBasedDevice = oldOTBD; - }); - it('does not add the tooltip to fullscreen button', function() { expect($('.add-fullscreen')).not.toHaveData('qtip'); }); @@ -190,19 +184,9 @@ var oldOTBD; beforeEach(function() { - oldOTBD = window.onTouchBasedDevice; - - window.onTouchBasedDevice = function () { - return false; - }; - initialize(); }); - afterEach(function () { - window.onTouchBasedDevice = oldOTBD; - }); - it('add the tooltip to fullscreen button', function() { expect($('.add-fullscreen')).toHaveData('qtip'); }); @@ -759,7 +743,7 @@ it('set the player volume', function() { player.setVolume(60); - expect(Number(player.getVolume().toFixed(1)).toEqual(0.6); + expect(player.getVolume()).toEqual(0.6); }); }); }); diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_progress_slider_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_progress_slider_spec.js index db1a8a2ad9..b89b1baea8 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_progress_slider_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_progress_slider_spec.js @@ -1,6 +1,6 @@ (function() { describe('VideoProgressSliderAlpha', function() { - var state, videoPlayer, videoProgressSlider; + var state, videoPlayer, videoProgressSlider, oldOTBD; function initialize() { loadFixtures('videoalpha_all.html'); @@ -10,12 +10,14 @@ } beforeEach(function() { - window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); }); afterEach(function() { $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_quality_control_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_quality_control_spec.js index 9bc535b2f0..1605551e63 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_quality_control_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_quality_control_spec.js @@ -1,6 +1,6 @@ (function() { describe('VideoQualityControlAlpha', function() { - var state, videoControl, videoQualityControl; + var state, videoControl, videoQualityControl, oldOTBD; function initialize() { loadFixtures('videoalpha.html'); @@ -9,9 +9,14 @@ videoQualityControl = state.videoQualityControl; } + beforeEach(function() { + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); + }); afterEach(function() { - $('source').remove(); + $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_speed_control_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_speed_control_spec.js index 71b89419c1..ab28dfd41e 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_speed_control_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_speed_control_spec.js @@ -11,12 +11,14 @@ } beforeEach(function() { + oldOTBD = window.onTouchBasedDevice; window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); }); afterEach(function() { - $('source').remove(); + $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { diff --git a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_volume_control_spec.js b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_volume_control_spec.js index 0d6adef58d..dfed7c351d 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/video_volume_control_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/video_volume_control_spec.js @@ -1,6 +1,6 @@ (function() { describe('VideoVolumeControlAlpha', function() { - var state, videoControl, videoVolumeControl; + var state, videoControl, videoVolumeControl, oldOTBD; function initialize() { loadFixtures('videoalpha_all.html'); @@ -9,10 +9,14 @@ videoVolumeControl = state.videoVolumeControl; } - + beforeEach(function() { + oldOTBD = window.onTouchBasedDevice; + window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); + }); afterEach(function() { $('source').remove(); + window.onTouchBasedDevice = oldOTBD; }); describe('constructor', function() { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/02_initialize.js b/common/lib/xmodule/xmodule/js/src/videoalpha/02_initialize.js index c64ebbd5d8..0eaa43c4d2 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/02_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/02_initialize.js @@ -12,8 +12,8 @@ (function (requirejs, require, define) { define( -'videoalpha/display/initialize.js', -['videoalpha/display/video_player.js'], +'videoalpha/02_initialize.js', +['videoalpha/04_video_player.js'], function (VideoPlayer) { /** diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/03_html5_video.js b/common/lib/xmodule/xmodule/js/src/videoalpha/03_html5_video.js index 59b6adade8..0f4bf904b6 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/03_html5_video.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/03_html5_video.js @@ -14,7 +14,7 @@ (function (requirejs, require, define) { define( -'videoalpha/display/html5_video.js', +'videoalpha/03_html5_video.js', [], function () { var HTML5Video = {}; @@ -67,7 +67,7 @@ function () { if (isNaN(this.video.duration)) { return 0; } - + return this.video.duration; }; diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/04_video_player.js b/common/lib/xmodule/xmodule/js/src/videoalpha/04_video_player.js index b37f3f9042..62fb7ce797 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/04_video_player.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/04_video_player.js @@ -2,8 +2,8 @@ // VideoPlayer module. define( -'videoalpha/display/video_player.js', -['videoalpha/display/html5_video.js'], +'videoalpha/04_video_player.js', +['videoalpha/03_html5_video.js'], function (HTML5Video) { // VideoPlayer() function - what this module "exports". diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/05_video_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/05_video_control.js index 008f7f8e70..493fe0fa6f 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/05_video_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/05_video_control.js @@ -2,7 +2,7 @@ // VideoControl module. define( -'videoalpha/display/video_control.js', +'videoalpha/05_video_control.js', [], function () { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/06_video_quality_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/06_video_quality_control.js index 67840e4902..6b7d376e3b 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/06_video_quality_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/06_video_quality_control.js @@ -2,7 +2,7 @@ // VideoQualityControl module. define( -'videoalpha/display/video_quality_control.js', +'videoalpha/06_video_quality_control.js', [], function () { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/07_video_progress_slider.js b/common/lib/xmodule/xmodule/js/src/videoalpha/07_video_progress_slider.js index 156d66cac4..b3a11f86e7 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/07_video_progress_slider.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/07_video_progress_slider.js @@ -9,7 +9,7 @@ mind, or whether to act, and in acting, to live." // VideoProgressSlider module. define( -'videoalpha/display/video_progress_slider.js', +'videoalpha/07_video_progress_slider.js', [], function () { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/08_video_volume_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/08_video_volume_control.js index c3892cbaae..24b3054a4d 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/08_video_volume_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/08_video_volume_control.js @@ -2,7 +2,7 @@ // VideoVolumeControl module. define( -'videoalpha/display/video_volume_control.js', +'videoalpha/08_video_volume_control.js', [], function () { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/09_video_speed_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/09_video_speed_control.js index d5476606bd..2eb2cddc93 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/09_video_speed_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/09_video_speed_control.js @@ -2,7 +2,7 @@ // VideoSpeedControl module. define( -'videoalpha/display/video_speed_control.js', +'videoalpha/09_video_speed_control.js', [], function () { @@ -44,7 +44,7 @@ function () { state.videoControl.secondaryControlsEl.prepend(state.videoSpeedControl.el); $.each(state.videoSpeedControl.speeds, function(index, speed) { - + //var link = $('' + speed + 'x'); var link = '' + speed + 'x'; diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/10_video_caption.js b/common/lib/xmodule/xmodule/js/src/videoalpha/10_video_caption.js index e44219bb79..0e41f9820d 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/10_video_caption.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/10_video_caption.js @@ -2,7 +2,7 @@ // VideoCaption module. define( -'videoalpha/display/video_caption.js', +'videoalpha/10_video_caption.js', [], function () { @@ -109,11 +109,11 @@ function () { } function fetchCaption() { - var _this = this; + var _this = this, jQueryObject; 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.start = captions.start; _this.videoCaption.loaded = true; @@ -125,8 +125,11 @@ function () { } else { _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() { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/11_main.js b/common/lib/xmodule/xmodule/js/src/videoalpha/11_main.js index 513e977ead..190eaed52a 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/11_main.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/11_main.js @@ -3,13 +3,13 @@ // Main module. require( [ - 'videoalpha/display/initialize.js', - 'videoalpha/display/video_control.js', - 'videoalpha/display/video_quality_control.js', - 'videoalpha/display/video_progress_slider.js', - 'videoalpha/display/video_volume_control.js', - 'videoalpha/display/video_speed_control.js', - 'videoalpha/display/video_caption.js' + 'videoalpha/02_initialize.js', + 'videoalpha/05_video_control.js', + 'videoalpha/06_video_quality_control.js', + 'videoalpha/07_video_progress_slider.js', + 'videoalpha/08_video_volume_control.js', + 'videoalpha/09_video_speed_control.js', + 'videoalpha/10_video_caption.js' ], function ( Initialize,