Commit 8a3ef339 by Valera Rozuvan

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.
parent 417bf6dd
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<div id="video_example"> <div id="video_example">
<div id="example"> <div id="example">
<div id="video_id" class="video" <div id="video_id" class="video"
data-youtube-id-0-75="slowerSpeedYoutubeId" data-youtube-id-0-75="7tqY6eQzVhE"
data-youtube-id-1-0="normalSpeedYoutubeId" data-youtube-id-1-0="cogebirgzzM"
data-show-captions="true" data-show-captions="true"
data-start="" data-start=""
data-end="" data-end=""
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div <div
id="video_id" id="video_id"
class="videoalpha" class="videoalpha"
data-streams="0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId" data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM"
data-show-captions="true" data-show-captions="true"
data-start="" data-start=""
data-end="" data-end=""
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
data-start="" data-start=""
data-end="" data-end=""
data-caption-asset-path="/static/subs/" data-caption-asset-path="/static/subs/"
data-sub="test_name_of_the_subtitles" data-sub="Z5KLxerq05Y"
data-mp4-source="test_files/test.mp4" data-mp4-source="test_files/test.mp4"
data-webm-source="test_files/test.webm" data-webm-source="test_files/test.webm"
data-ogg-source="test_files/test.ogv" data-ogg-source="test_files/test.ogv"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
data-start="" data-start=""
data-end="" data-end=""
data-caption-asset-path="/static/subs/" data-caption-asset-path="/static/subs/"
data-sub="test_name_of_the_subtitles" data-sub="Z5KLxerq05Y"
data-mp4-source="test_files/test.mp4" data-mp4-source="test_files/test.mp4"
data-webm-source="test_files/test.webm" data-webm-source="test_files/test.webm"
data-ogg-source="test_files/test.ogv" data-ogg-source="test_files/test.ogv"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div <div
id="video_id" id="video_id"
class="videoalpha" class="videoalpha"
data-streams="0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId" data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM"
data-show-captions="false" data-show-captions="false"
data-start="" data-start=""
data-end="" data-end=""
......
...@@ -12,6 +12,9 @@ window.STATUS = window.YT.PlayerState ...@@ -12,6 +12,9 @@ window.STATUS = window.YT.PlayerState
oldAjaxWithPrefix = window.jQuery.ajaxWithPrefix oldAjaxWithPrefix = window.jQuery.ajaxWithPrefix
window.onTouchBasedDevice = ->
navigator.userAgent.match /iPhone|iPod|iPad/i
jasmine.stubbedCaption = jasmine.stubbedCaption =
end: [3120, 6270, 8490, 21620, 24920, 25750, 27900, 34380, 35550, 40250] end: [3120, 6270, 8490, 21620, 24920, 25750, 27900, 34380, 35550, 40250]
start: [1180, 3120, 6270, 14910, 21620, 24920, 25750, 27900, 34380, 35550] start: [1180, 3120, 6270, 14910, 21620, 24920, 25750, 27900, 34380, 35550]
...@@ -36,7 +39,7 @@ jasmine.stubbedCaption = ...@@ -36,7 +39,7 @@ jasmine.stubbedCaption =
# #
# We will replace it with a function that does: # 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. # 2.) Behaves the same a as the origianl in all other cases.
window.jQuery.ajaxWithPrefix = (url, settings) -> window.jQuery.ajaxWithPrefix = (url, settings) ->
...@@ -46,7 +49,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) -> ...@@ -46,7 +49,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) ->
success = settings.success success = settings.success
data = settings.data 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 if window.jQuery.isFunction(success) is true
success jasmine.stubbedCaption success jasmine.stubbedCaption
else if window.jQuery.isFunction(data) is true else if window.jQuery.isFunction(data) is true
...@@ -60,11 +63,11 @@ window.WAIT_TIMEOUT = 1000 ...@@ -60,11 +63,11 @@ window.WAIT_TIMEOUT = 1000
jasmine.getFixtures().fixturesPath = 'xmodule/js/fixtures' jasmine.getFixtures().fixturesPath = 'xmodule/js/fixtures'
jasmine.stubbedMetadata = jasmine.stubbedMetadata =
slowerSpeedYoutubeId: '7tqY6eQzVhE':
id: 'slowerSpeedYoutubeId' id: '7tqY6eQzVhE'
duration: 300 duration: 300
normalSpeedYoutubeId: 'cogebirgzzM':
id: 'normalSpeedYoutubeId' id: 'cogebirgzzM'
duration: 200 duration: 200
bogus: bogus:
duration: 100 duration: 100
...@@ -117,7 +120,7 @@ jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) -> ...@@ -117,7 +120,7 @@ jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) ->
loadFixtures 'video.html' loadFixtures 'video.html'
jasmine.stubRequests() jasmine.stubRequests()
YT.Player = undefined YT.Player = undefined
videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId' videosDefinition = '0.75:7tqY6eQzVhE,1.0:cogebirgzzM'
context.video = new Video '#example', videosDefinition context.video = new Video '#example', videosDefinition
jasmine.stubYoutubePlayer() jasmine.stubYoutubePlayer()
if createPlayer if createPlayer
...@@ -135,7 +138,7 @@ jasmine.stubVideoPlayerAlpha = (context, enableParts, html5=false) -> ...@@ -135,7 +138,7 @@ jasmine.stubVideoPlayerAlpha = (context, enableParts, html5=false) ->
YT.Player = undefined YT.Player = undefined
window.OldVideoPlayerAlpha = undefined window.OldVideoPlayerAlpha = undefined
jasmine.stubYoutubePlayer() jasmine.stubYoutubePlayer()
return new VideoAlpha '#example', '.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId' return new VideoAlpha '#example', '.75:7tqY6eQzVhE,1.0:cogebirgzzM'
# Stub jQuery.cookie # Stub jQuery.cookie
......
...@@ -19,7 +19,7 @@ describe 'VideoCaption', -> ...@@ -19,7 +19,7 @@ describe 'VideoCaption', ->
@caption = @player.caption @caption = @player.caption
it 'set the youtube id', -> it 'set the youtube id', ->
expect(@caption.youtubeId).toEqual 'normalSpeedYoutubeId' expect(@caption.youtubeId).toEqual 'cogebirgzzM'
it 'create the caption element', -> it 'create the caption element', ->
expect($('.video')).toContain 'ol.subtitles' expect($('.video')).toContain 'ol.subtitles'
......
...@@ -35,7 +35,7 @@ describe 'VideoPlayer', -> ...@@ -35,7 +35,7 @@ describe 'VideoPlayer', ->
expect(window.VideoCaption.prototype.initialize).toHaveBeenCalled() expect(window.VideoCaption.prototype.initialize).toHaveBeenCalled()
expect(@player.caption).toBeDefined() expect(@player.caption).toBeDefined()
expect(@player.caption.el).toBe @player.el 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.currentSpeed).toEqual '1.0'
expect(@player.caption.captionAssetPath).toEqual '/static/subs/' expect(@player.caption.captionAssetPath).toEqual '/static/subs/'
...@@ -60,7 +60,7 @@ describe 'VideoPlayer', -> ...@@ -60,7 +60,7 @@ describe 'VideoPlayer', ->
showinfo: 0 showinfo: 0
enablejsapi: 1 enablejsapi: 1
modestbranding: 1 modestbranding: 1
videoId: 'normalSpeedYoutubeId' videoId: 'cogebirgzzM'
events: events:
onReady: @player.onReady onReady: @player.onReady
onStateChange: @player.onStateChange onStateChange: @player.onStateChange
...@@ -290,7 +290,7 @@ describe 'VideoPlayer', -> ...@@ -290,7 +290,7 @@ describe 'VideoPlayer', ->
@player.onSpeedChange {}, '0.75' @player.onSpeedChange {}, '0.75'
it 'load the video', -> it 'load the video', ->
expect(@player.player.loadVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' expect(@player.player.loadVideoById).toHaveBeenCalledWith '7tqY6eQzVhE', '80.000'
it 'trigger updatePlayTime event', -> it 'trigger updatePlayTime event', ->
expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000'
...@@ -301,7 +301,7 @@ describe 'VideoPlayer', -> ...@@ -301,7 +301,7 @@ describe 'VideoPlayer', ->
@player.onSpeedChange {}, '0.75' @player.onSpeedChange {}, '0.75'
it 'cue the video', -> it 'cue the video', ->
expect(@player.player.cueVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' expect(@player.player.cueVideoById).toHaveBeenCalledWith '7tqY6eQzVhE', '80.000'
it 'trigger updatePlayTime event', -> it 'trigger updatePlayTime event', ->
expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000'
......
...@@ -5,14 +5,14 @@ describe 'Video', -> ...@@ -5,14 +5,14 @@ describe 'Video', ->
loadFixtures 'video.html' loadFixtures 'video.html'
jasmine.stubRequests() jasmine.stubRequests()
@slowerSpeedYoutubeId = 'slowerSpeedYoutubeId' @['7tqY6eQzVhE'] = '7tqY6eQzVhE'
@normalSpeedYoutubeId = 'normalSpeedYoutubeId' @['cogebirgzzM'] = 'cogebirgzzM'
metadata = metadata =
slowerSpeedYoutubeId: '7tqY6eQzVhE':
id: @slowerSpeedYoutubeId id: @['7tqY6eQzVhE']
duration: 300 duration: 300
normalSpeedYoutubeId: 'cogebirgzzM':
id: @normalSpeedYoutubeId id: @['cogebirgzzM']
duration: 200 duration: 200
afterEach -> afterEach ->
...@@ -38,8 +38,8 @@ describe 'Video', -> ...@@ -38,8 +38,8 @@ describe 'Video', ->
it 'parse the videos', -> it 'parse the videos', ->
expect(@video.videos).toEqual expect(@video.videos).toEqual
'0.75': @slowerSpeedYoutubeId '0.75': @['7tqY6eQzVhE']
'1.0': @normalSpeedYoutubeId '1.0': @['cogebirgzzM']
it 'fetch the video metadata', -> it 'fetch the video metadata', ->
expect(@video.fetchMetadata).toHaveBeenCalled expect(@video.fetchMetadata).toHaveBeenCalled
...@@ -102,12 +102,12 @@ describe 'Video', -> ...@@ -102,12 +102,12 @@ describe 'Video', ->
describe 'with speed', -> describe 'with speed', ->
it 'return the video id for given speed', -> it 'return the video id for given speed', ->
expect(@video.youtubeId('0.75')).toEqual @slowerSpeedYoutubeId expect(@video.youtubeId('0.75')).toEqual @['7tqY6eQzVhE']
expect(@video.youtubeId('1.0')).toEqual @normalSpeedYoutubeId expect(@video.youtubeId('1.0')).toEqual @['cogebirgzzM']
describe 'without speed', -> describe 'without speed', ->
it 'return the video id for current speed', -> it 'return the video id for current speed', ->
expect(@video.youtubeId()).toEqual @normalSpeedYoutubeId expect(@video.youtubeId()).toEqual @cogebirgzzM
describe 'setSpeed', -> describe 'setSpeed', ->
beforeEach -> beforeEach ->
...@@ -148,6 +148,6 @@ describe 'Video', -> ...@@ -148,6 +148,6 @@ describe 'Video', ->
it 'call the logger with valid parameters', -> it 'call the logger with valid parameters', ->
expect(Logger.log).toHaveBeenCalledWith 'someEvent', expect(Logger.log).toHaveBeenCalledWith 'someEvent',
id: 'id' id: 'id'
code: @normalSpeedYoutubeId code: @cogebirgzzM
currentTime: 25 currentTime: 25
speed: '1.0' speed: '1.0'
(function () { (function () {
xdescribe('VideoAlpha', function () { describe('VideoAlpha', function () {
var oldOTBD; var oldOTBD;
beforeEach(function () { beforeEach(function () {
jasmine.stubRequests(); jasmine.stubRequests();
oldOTBD = window.onTouchBasedDevice; 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:7tqY6eQzVhE,1.0:cogebirgzzM';
this.slowerSpeedYoutubeId = 'slowerSpeedYoutubeId'; this['7tqY6eQzVhE'] = '7tqY6eQzVhE';
this.normalSpeedYoutubeId = 'normalSpeedYoutubeId'; this['cogebirgzzM'] = 'cogebirgzzM';
}); });
afterEach(function () { afterEach(function () {
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
it('parse the videos', function () { it('parse the videos', function () {
expect(this.state.videos).toEqual({ expect(this.state.videos).toEqual({
'0.75': this.slowerSpeedYoutubeId, '0.75': this['7tqY6eQzVhE'],
'1.0': this.normalSpeedYoutubeId '1.0': this['cogebirgzzM']
}); });
}); });
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
}); });
it('parse the videos if subtitles exist', function () { it('parse the videos if subtitles exist', function () {
var sub = 'test_name_of_the_subtitles'; var sub = 'Z5KLxerq05Y';
expect(state.videos).toEqual({ expect(state.videos).toEqual({
'0.75': sub, '0.75': sub,
...@@ -165,14 +165,14 @@ ...@@ -165,14 +165,14 @@
describe('with speed', function () { describe('with speed', function () {
it('return the video id for given speed', function () { it('return the video id for given speed', function () {
expect(state.youtubeId('0.75')).toEqual(this.slowerSpeedYoutubeId); expect(state.youtubeId('0.75')).toEqual(this['7tqY6eQzVhE']);
expect(state.youtubeId('1.0')).toEqual(this.normalSpeedYoutubeId); expect(state.youtubeId('1.0')).toEqual(this['cogebirgzzM']);
}); });
}); });
describe('without speed', function () { describe('without speed', function () {
it('return the video id for current speed', function () { it('return the video id for current speed', function () {
expect(state.youtubeId()).toEqual(this.normalSpeedYoutubeId); expect(state.youtubeId()).toEqual(this.cogebirgzzM);
}); });
}); });
}); });
......
(function () { (function () {
xdescribe('VideoAlpha HTML5Video', function () { describe('VideoAlpha HTML5Video', function () {
var state, player, oldOTBD, 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() {
......
(function() { (function() {
xdescribe('VideoControlAlpha', function() { describe('VideoControlAlpha', function() {
var state, videoControl, oldOTBD; var state, videoControl, oldOTBD;
function initialize() { function initialize() {
......
(function() { (function() {
xdescribe('VideoPlayerAlpha', function() { describe('VideoPlayerAlpha', function() {
var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD; var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD;
function initialize(fixture) { function initialize(fixture) {
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
it('create video caption', function() { it('create video caption', function() {
expect(videoCaption).toBeDefined(); 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.speed).toEqual('1.0');
expect(state.config.caption_asset_path).toEqual('/static/subs/'); expect(state.config.caption_asset_path).toEqual('/static/subs/');
}); });
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
modestbranding: 1, modestbranding: 1,
html5: 1 html5: 1
}, },
videoId: 'normalSpeedYoutubeId', videoId: 'cogebirgzzM',
events: { events: {
onReady: videoPlayer.onReady, onReady: videoPlayer.onReady,
onStateChange: videoPlayer.onStateChange, onStateChange: videoPlayer.onStateChange,
......
(function() { (function() {
xdescribe('VideoProgressSliderAlpha', function() { describe('VideoProgressSliderAlpha', function() {
var state, videoPlayer, videoProgressSlider, oldOTBD; var state, videoPlayer, videoProgressSlider, oldOTBD;
function initialize() { function initialize() {
......
(function() { (function() {
xdescribe('VideoQualityControlAlpha', function() { describe('VideoQualityControlAlpha', function() {
var state, videoControl, videoQualityControl, oldOTBD; var state, videoControl, videoQualityControl, oldOTBD;
function initialize() { function initialize() {
......
(function() { (function() {
xdescribe('VideoSpeedControlAlpha', function() { describe('VideoSpeedControlAlpha', function() {
var state, videoPlayer, videoControl, videoSpeedControl; var state, videoPlayer, videoControl, videoSpeedControl;
function initialize() { function initialize() {
......
(function() { (function() {
xdescribe('VideoVolumeControlAlpha', function() { describe('VideoVolumeControlAlpha', function() {
var state, videoControl, videoVolumeControl, oldOTBD; var state, videoControl, videoVolumeControl, oldOTBD;
function initialize() { function initialize() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment