From 8a3ef339858d4589315be021518d10c0789bb587 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Thu, 8 Aug 2013 11:57:57 +0300 Subject: [PATCH] Fixing tests related to fetching YouTube metadata. Previously we were using dummy YouTube IDs such as "slowerSpeedYoutubeId", and "normalSpeedYoutubeId". This was causing errors when the code tried to fetch metadata from YouTube with that ID. We can't stub these fetch requests because the data that is fetched is necessary. For example it contains the length of the video. --- .../xmodule/xmodule/js/fixtures/video.html | 4 ++-- .../xmodule/js/fixtures/videoalpha.html | 2 +- .../xmodule/js/fixtures/videoalpha_all.html | 2 +- .../xmodule/js/fixtures/videoalpha_html5.html | 2 +- .../js/fixtures/videoalpha_no_captions.html | 2 +- .../lib/xmodule/xmodule/js/spec/helper.coffee | 19 ++++++++------- .../video/display/video_caption_spec.coffee | 2 +- .../video/display/video_player_spec.coffee | 8 +++---- .../xmodule/js/spec/video/display_spec.coffee | 24 +++++++++---------- .../js/spec/videoalpha/general_spec.js | 20 ++++++++-------- .../js/spec/videoalpha/html5_video_spec.js | 2 +- .../js/spec/videoalpha/video_control_spec.js | 2 +- .../js/spec/videoalpha/video_player_spec.js | 6 ++--- .../videoalpha/video_progress_slider_spec.js | 2 +- .../videoalpha/video_quality_control_spec.js | 2 +- .../videoalpha/video_speed_control_spec.js | 2 +- .../videoalpha/video_volume_control_spec.js | 2 +- 17 files changed, 53 insertions(+), 50 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/fixtures/video.html b/common/lib/xmodule/xmodule/js/fixtures/video.html index 1b27255b1e..3273dd3aa7 100644 --- a/common/lib/xmodule/xmodule/js/fixtures/video.html +++ b/common/lib/xmodule/xmodule/js/fixtures/video.html @@ -2,8 +2,8 @@
+ navigator.userAgent.match /iPhone|iPod|iPad/i + jasmine.stubbedCaption = end: [3120, 6270, 8490, 21620, 24920, 25750, 27900, 34380, 35550, 40250] start: [1180, 3120, 6270, 14910, 21620, 24920, 25750, 27900, 34380, 35550] @@ -36,7 +39,7 @@ jasmine.stubbedCaption = # # We will replace it with a function that does: # -# 1.) Return a hard coded captions object if the file name contains 'test_name_of_the_subtitles'. +# 1.) Return a hard coded captions object if the file name contains 'Z5KLxerq05Y'. # 2.) Behaves the same a as the origianl in all other cases. window.jQuery.ajaxWithPrefix = (url, settings) -> @@ -46,7 +49,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) -> success = settings.success data = settings.data - if url.match(/test_name_of_the_subtitles/g) isnt null or url.match(/slowerSpeedYoutubeId/g) isnt null or url.match(/normalSpeedYoutubeId/g) isnt null + if url.match(/Z5KLxerq05Y/g) isnt null or url.match(/7tqY6eQzVhE/g) isnt null or url.match(/cogebirgzzM/g) isnt null if window.jQuery.isFunction(success) is true success jasmine.stubbedCaption else if window.jQuery.isFunction(data) is true @@ -60,11 +63,11 @@ window.WAIT_TIMEOUT = 1000 jasmine.getFixtures().fixturesPath = 'xmodule/js/fixtures' jasmine.stubbedMetadata = - slowerSpeedYoutubeId: - id: 'slowerSpeedYoutubeId' + '7tqY6eQzVhE': + id: '7tqY6eQzVhE' duration: 300 - normalSpeedYoutubeId: - id: 'normalSpeedYoutubeId' + 'cogebirgzzM': + id: 'cogebirgzzM' duration: 200 bogus: duration: 100 @@ -117,7 +120,7 @@ jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) -> loadFixtures 'video.html' jasmine.stubRequests() YT.Player = undefined - videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId' + videosDefinition = '0.75:7tqY6eQzVhE,1.0:cogebirgzzM' context.video = new Video '#example', videosDefinition jasmine.stubYoutubePlayer() if createPlayer @@ -135,7 +138,7 @@ jasmine.stubVideoPlayerAlpha = (context, enableParts, html5=false) -> YT.Player = undefined window.OldVideoPlayerAlpha = undefined jasmine.stubYoutubePlayer() - return new VideoAlpha '#example', '.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId' + return new VideoAlpha '#example', '.75:7tqY6eQzVhE,1.0:cogebirgzzM' # Stub jQuery.cookie diff --git a/common/lib/xmodule/xmodule/js/spec/video/display/video_caption_spec.coffee b/common/lib/xmodule/xmodule/js/spec/video/display/video_caption_spec.coffee index 7f4f6073cb..2c339b3ca2 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/display/video_caption_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/video/display/video_caption_spec.coffee @@ -19,7 +19,7 @@ describe 'VideoCaption', -> @caption = @player.caption it 'set the youtube id', -> - expect(@caption.youtubeId).toEqual 'normalSpeedYoutubeId' + expect(@caption.youtubeId).toEqual 'cogebirgzzM' it 'create the caption element', -> expect($('.video')).toContain 'ol.subtitles' diff --git a/common/lib/xmodule/xmodule/js/spec/video/display/video_player_spec.coffee b/common/lib/xmodule/xmodule/js/spec/video/display/video_player_spec.coffee index dab8c0815a..9cec0e6e96 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/display/video_player_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/video/display/video_player_spec.coffee @@ -35,7 +35,7 @@ describe 'VideoPlayer', -> expect(window.VideoCaption.prototype.initialize).toHaveBeenCalled() expect(@player.caption).toBeDefined() expect(@player.caption.el).toBe @player.el - expect(@player.caption.youtubeId).toEqual 'normalSpeedYoutubeId' + expect(@player.caption.youtubeId).toEqual 'cogebirgzzM' expect(@player.caption.currentSpeed).toEqual '1.0' expect(@player.caption.captionAssetPath).toEqual '/static/subs/' @@ -60,7 +60,7 @@ describe 'VideoPlayer', -> showinfo: 0 enablejsapi: 1 modestbranding: 1 - videoId: 'normalSpeedYoutubeId' + videoId: 'cogebirgzzM' events: onReady: @player.onReady onStateChange: @player.onStateChange @@ -290,7 +290,7 @@ describe 'VideoPlayer', -> @player.onSpeedChange {}, '0.75' it 'load the video', -> - expect(@player.player.loadVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' + expect(@player.player.loadVideoById).toHaveBeenCalledWith '7tqY6eQzVhE', '80.000' it 'trigger updatePlayTime event', -> expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' @@ -301,7 +301,7 @@ describe 'VideoPlayer', -> @player.onSpeedChange {}, '0.75' it 'cue the video', -> - expect(@player.player.cueVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' + expect(@player.player.cueVideoById).toHaveBeenCalledWith '7tqY6eQzVhE', '80.000' it 'trigger updatePlayTime event', -> expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' diff --git a/common/lib/xmodule/xmodule/js/spec/video/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/video/display_spec.coffee index 0ba0cc85f8..35a56a83ae 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/video/display_spec.coffee @@ -5,14 +5,14 @@ describe 'Video', -> loadFixtures 'video.html' jasmine.stubRequests() - @slowerSpeedYoutubeId = 'slowerSpeedYoutubeId' - @normalSpeedYoutubeId = 'normalSpeedYoutubeId' + @['7tqY6eQzVhE'] = '7tqY6eQzVhE' + @['cogebirgzzM'] = 'cogebirgzzM' metadata = - slowerSpeedYoutubeId: - id: @slowerSpeedYoutubeId + '7tqY6eQzVhE': + id: @['7tqY6eQzVhE'] duration: 300 - normalSpeedYoutubeId: - id: @normalSpeedYoutubeId + 'cogebirgzzM': + id: @['cogebirgzzM'] duration: 200 afterEach -> @@ -38,8 +38,8 @@ describe 'Video', -> it 'parse the videos', -> expect(@video.videos).toEqual - '0.75': @slowerSpeedYoutubeId - '1.0': @normalSpeedYoutubeId + '0.75': @['7tqY6eQzVhE'] + '1.0': @['cogebirgzzM'] it 'fetch the video metadata', -> expect(@video.fetchMetadata).toHaveBeenCalled @@ -102,12 +102,12 @@ describe 'Video', -> describe 'with speed', -> it 'return the video id for given speed', -> - expect(@video.youtubeId('0.75')).toEqual @slowerSpeedYoutubeId - expect(@video.youtubeId('1.0')).toEqual @normalSpeedYoutubeId + expect(@video.youtubeId('0.75')).toEqual @['7tqY6eQzVhE'] + expect(@video.youtubeId('1.0')).toEqual @['cogebirgzzM'] describe 'without speed', -> it 'return the video id for current speed', -> - expect(@video.youtubeId()).toEqual @normalSpeedYoutubeId + expect(@video.youtubeId()).toEqual @cogebirgzzM describe 'setSpeed', -> beforeEach -> @@ -148,6 +148,6 @@ describe 'Video', -> it 'call the logger with valid parameters', -> expect(Logger.log).toHaveBeenCalledWith 'someEvent', id: 'id' - code: @normalSpeedYoutubeId + code: @cogebirgzzM currentTime: 25 speed: '1.0' 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 415ac440ad..39a1e64c65 100644 --- a/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/videoalpha/general_spec.js @@ -1,14 +1,14 @@ (function () { - xdescribe('VideoAlpha', 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'; - this.normalSpeedYoutubeId = 'normalSpeedYoutubeId'; + this.videosDefinition = '0.75:7tqY6eQzVhE,1.0:cogebirgzzM'; + this['7tqY6eQzVhE'] = '7tqY6eQzVhE'; + this['cogebirgzzM'] = 'cogebirgzzM'; }); afterEach(function () { @@ -45,8 +45,8 @@ it('parse the videos', function () { expect(this.state.videos).toEqual({ - '0.75': this.slowerSpeedYoutubeId, - '1.0': this.normalSpeedYoutubeId + '0.75': this['7tqY6eQzVhE'], + '1.0': this['cogebirgzzM'] }); }); @@ -91,7 +91,7 @@ }); it('parse the videos if subtitles exist', function () { - var sub = 'test_name_of_the_subtitles'; + var sub = 'Z5KLxerq05Y'; expect(state.videos).toEqual({ '0.75': sub, @@ -165,14 +165,14 @@ describe('with speed', function () { it('return the video id for given speed', function () { - expect(state.youtubeId('0.75')).toEqual(this.slowerSpeedYoutubeId); - expect(state.youtubeId('1.0')).toEqual(this.normalSpeedYoutubeId); + expect(state.youtubeId('0.75')).toEqual(this['7tqY6eQzVhE']); + expect(state.youtubeId('1.0')).toEqual(this['cogebirgzzM']); }); }); describe('without speed', function () { it('return the video id for current speed', function () { - expect(state.youtubeId()).toEqual(this.normalSpeedYoutubeId); + expect(state.youtubeId()).toEqual(this.cogebirgzzM); }); }); }); 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 9a6c44052c..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,5 +1,5 @@ (function () { - xdescribe('VideoAlpha HTML5Video', function () { + describe('VideoAlpha HTML5Video', function () { var state, player, oldOTBD, playbackRates = [0.75, 1.0, 1.25, 1.5]; function initialize() { 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 b98fd1e413..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,5 +1,5 @@ (function() { - xdescribe('VideoControlAlpha', function() { + describe('VideoControlAlpha', function() { var state, videoControl, oldOTBD; function initialize() { 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 18e442b227..7566ca0964 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,5 +1,5 @@ (function() { - xdescribe('VideoPlayerAlpha', function() { + describe('VideoPlayerAlpha', function() { var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD; function initialize(fixture) { @@ -54,7 +54,7 @@ it('create video caption', function() { expect(videoCaption).toBeDefined(); - expect(state.youtubeId()).toEqual('test_name_of_the_subtitles'); + expect(state.youtubeId()).toEqual('Z5KLxerq05Y'); expect(state.speed).toEqual('1.0'); expect(state.config.caption_asset_path).toEqual('/static/subs/'); }); @@ -98,7 +98,7 @@ modestbranding: 1, html5: 1 }, - videoId: 'normalSpeedYoutubeId', + videoId: 'cogebirgzzM', events: { onReady: videoPlayer.onReady, onStateChange: videoPlayer.onStateChange, 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 f0e177d5d7..f19d4245c5 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,5 +1,5 @@ (function() { - xdescribe('VideoProgressSliderAlpha', function() { + describe('VideoProgressSliderAlpha', function() { var state, videoPlayer, videoProgressSlider, oldOTBD; function initialize() { 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 7126dc5921..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,5 +1,5 @@ (function() { - xdescribe('VideoQualityControlAlpha', function() { + describe('VideoQualityControlAlpha', function() { var state, videoControl, videoQualityControl, oldOTBD; function initialize() { 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 c40a9c7295..fe2a537781 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 @@ -1,5 +1,5 @@ (function() { - xdescribe('VideoSpeedControlAlpha', function() { + describe('VideoSpeedControlAlpha', function() { var state, videoPlayer, videoControl, videoSpeedControl; function initialize() { 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 f7f6c6c583..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,5 +1,5 @@ (function() { - xdescribe('VideoVolumeControlAlpha', function() { + describe('VideoVolumeControlAlpha', function() { var state, videoControl, videoVolumeControl, oldOTBD; function initialize() {