Commit 499c682d by Anto Stupak Committed by Vasyl Nakvasiuk

Add tests for HTML5 part of Videoalpha

parent 70cc9a16
<div class="course-content">
<div id="video_example">
<div id="example">
<div
id="video_id"
class="video"
data-show-captions="true"
data-start=""
data-end=""
data-caption-asset-path="/static/subs/"
data-sub="test_name_of_the_subtitles"
data-mp4-source="test.mp4"
data-webm-source="test.webm"
data-ogg-source="test.ogv"
>
<div class="tc-wrapper">
<article class="video-wrapper">
<section class="video-player">
<div id="id"></div>
</section>
<section class="video-controls"></section>
</article>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
...@@ -20,10 +20,25 @@ jasmine.stubbedMetadata = ...@@ -20,10 +20,25 @@ jasmine.stubbedMetadata =
bogus: bogus:
duration: 100 duration: 100
jasmine.fireEvent = (el, eventName) ->
if document.createEvent
event = document.createEvent "HTMLEvents"
event.initEvent eventName, true, true
else
event = document.createEventObject()
event.eventType = eventName
event.eventName = eventName
if document.createEvent
el.dispatchEvent(event)
else
el.fireEvent("on" + event.eventType, event)
jasmine.stubbedCaption = jasmine.stubbedCaption =
start: [0, 10000, 20000, 30000] start: [0, 10000, 20000, 30000]
text: ['Caption at 0', 'Caption at 10000', 'Caption at 20000', 'Caption at 30000'] text: ['Caption at 0', 'Caption at 10000', 'Caption at 20000', 'Caption at 30000']
jasmine.stubbedHtml5Speeds = ['0.75', '1.0', '1.25', '1.50']
jasmine.stubRequests = -> jasmine.stubRequests = ->
spyOn($, 'ajax').andCallFake (settings) -> spyOn($, 'ajax').andCallFake (settings) ->
if match = settings.url.match /youtube\.com\/.+\/videos\/(.+)\?v=2&alt=jsonc/ if match = settings.url.match /youtube\.com\/.+\/videos\/(.+)\?v=2&alt=jsonc/
...@@ -63,11 +78,13 @@ jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) -> ...@@ -63,11 +78,13 @@ jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) ->
if createPlayer if createPlayer
return new VideoPlayer(video: context.video) return new VideoPlayer(video: context.video)
jasmine.stubVideoPlayerAlpha = (context, enableParts, createPlayer=true) -> jasmine.stubVideoPlayerAlpha = (context, enableParts, createPlayer=true, html5=false) ->
suite = context.suite suite = context.suite
currentPartName = suite.description while suite = suite.parentSuite currentPartName = suite.description while suite = suite.parentSuite
if html5 == false
loadFixtures 'videoalpha.html' loadFixtures 'videoalpha.html'
else
loadFixtures 'videoalpha_html5.html'
jasmine.stubRequests() jasmine.stubRequests()
YT.Player = undefined YT.Player = undefined
window.OldVideoPlayerAlpha = undefined window.OldVideoPlayerAlpha = undefined
......
describe 'VideoAlpha HTML5Video', ->
playbackRates = [0.75, 1.0, 1.25, 1.5]
STATUS = window.YT.PlayerState
playerVars =
controls: 0
wmode: 'transparent'
rel: 0
showinfo: 0
enablejsapi: 1
modestbranding: 1
html5: 1
file = window.location.href.replace(/\/common(.*)$/, '') + '/test_root/data/videoalpha/gizmo'
html5Sources =
mp4: "#{file}.mp4"
webm: "#{file}.webm"
ogg: "#{file}.ogv"
onReady = jasmine.createSpy 'onReady'
onStateChange = jasmine.createSpy 'onStateChange'
beforeEach ->
loadFixtures 'videoalpha_html5.html'
@el = $('#example').find('.video')
@player = new window.HTML5Video.Player @el,
playerVars: playerVars,
videoSources: html5Sources,
events:
onReady: onReady
onStateChange: onStateChange
@videoEl = @el.find('.video-player video').get(0)
it 'PlayerState', ->
expect(HTML5Video.PlayerState).toEqual STATUS
describe 'constructor', ->
it 'create an html5 video element', ->
expect(@el.find('.video-player div')).toContain 'video'
it 'check if sources are created in correct way', ->
sources = $(@videoEl).find('source')
videoTypes = []
videoSources = []
$.each html5Sources, (index, source) ->
videoTypes.push index
videoSources.push source
$.each sources, (index, source) ->
s = $(source)
expect($.inArray(s.attr('src'), videoSources)).not.toEqual -1
expect($.inArray(s.attr('type').replace('video/', ''), videoTypes))
.not.toEqual -1
it 'check if click event is handled on the player', ->
expect(@videoEl).toHandle 'click'
describe 'events:', ->
beforeEach ->
spyOn(@player, 'callStateChangeCallback').andCallThrough()
describe 'click', ->
describe 'when player is paused', ->
beforeEach ->
spyOn(@videoEl, 'play').andCallThrough()
@player.playerState = STATUS.PAUSED
$(@videoEl).trigger('click')
it 'native play event was called', ->
expect(@videoEl.play).toHaveBeenCalled()
it 'player state was changed', ->
expect(@player.playerState).toBe STATUS.PLAYING
it 'callback was called', ->
expect(@player.callStateChangeCallback).toHaveBeenCalled()
describe 'when player is played', ->
beforeEach ->
spyOn(@videoEl, 'pause').andCallThrough()
@player.playerState = STATUS.PLAYING
$(@videoEl).trigger('click')
it 'native pause event was called', ->
expect(@videoEl.pause).toHaveBeenCalled()
it 'player state was changed', ->
expect(@player.playerState).toBe STATUS.PAUSED
it 'callback was called', ->
expect(@player.callStateChangeCallback).toHaveBeenCalled()
describe 'play', ->
beforeEach ->
spyOn(@videoEl, 'play').andCallThrough()
@player.playerState = STATUS.PAUSED
@videoEl.play()
it 'native event was called', ->
expect(@videoEl.play).toHaveBeenCalled()
it 'player state was changed', ->
waitsFor ( ->
@player.playerState != HTML5Video.PlayerState.PAUSED
), 'Player state should be changed', 1000
runs ->
expect(@player.playerState).toBe STATUS.PLAYING
it 'callback was called', ->
waitsFor ( ->
@player.playerState != STATUS.PAUSED
), 'Player state should be changed', 1000
runs ->
expect(@player.callStateChangeCallback).toHaveBeenCalled()
describe 'pause', ->
beforeEach ->
spyOn(@videoEl, 'pause').andCallThrough()
@videoEl.play()
@videoEl.pause()
it 'native event was called', ->
expect(@videoEl.pause).toHaveBeenCalled()
it 'player state was changed', ->
waitsFor ( ->
@player.playerState != STATUS.UNSTARTED
), 'Player state should be changed', 1000
runs ->
expect(@player.playerState).toBe STATUS.PAUSED
it 'callback was called', ->
waitsFor ( ->
@player.playerState != HTML5Video.PlayerState.UNSTARTED
), 'Player state should be changed', 1000
runs ->
expect(@player.callStateChangeCallback).toHaveBeenCalled()
describe 'canplay', ->
beforeEach ->
waitsFor ( ->
@player.playerState != STATUS.UNSTARTED
), 'Video cannot be played', 1000
it 'player state was changed', ->
runs ->
expect(@player.playerState).toBe STATUS.PAUSED
it 'end property was defined', ->
runs ->
expect(@player.end).not.toBeNull()
it 'start position was defined', ->
runs ->
expect(@videoEl.currentTime).toBe(@player.start)
it 'callback was called', ->
runs ->
expect(@player.config.events.onReady).toHaveBeenCalled()
describe 'ended', ->
beforeEach ->
waitsFor ( ->
@player.playerState != STATUS.UNSTARTED
), 'Video cannot be played', 1000
it 'player state was changed', ->
runs ->
jasmine.fireEvent @videoEl, "ended"
expect(@player.playerState).toBe STATUS.ENDED
it 'callback was called', ->
jasmine.fireEvent @videoEl, "ended"
expect(@player.callStateChangeCallback).toHaveBeenCalled()
describe 'timeupdate', ->
beforeEach ->
spyOn(@videoEl, 'pause').andCallThrough()
waitsFor ( ->
@player.playerState != STATUS.UNSTARTED
), 'Video cannot be played', 1000
it 'player should be paused', ->
runs ->
@player.end = 3
@videoEl.currentTime = 5
jasmine.fireEvent @videoEl, "timeupdate"
expect(@videoEl.pause).toHaveBeenCalled()
it 'end param should be re-defined', ->
runs ->
@player.end = 3
@videoEl.currentTime = 5
jasmine.fireEvent @videoEl, "timeupdate"
expect(@player.end).toBe @videoEl.duration
describe 'methods:', ->
beforeEach ->
waitsFor ( ->
@volume = @videoEl.volume
@seek = @videoEl.currentTime
@player.playerState == STATUS.PAUSED
), 'Video cannot be played', 1000
it 'pauseVideo', ->
spyOn(@videoEl, 'pause').andCallThrough()
@player.pauseVideo()
expect(@videoEl.pause).toHaveBeenCalled()
describe 'seekTo', ->
it 'set new correct value', ->
runs ->
@player.seekTo(2)
expect(@videoEl.currentTime).toBe 2
it 'set new inccorrect values', ->
runs ->
@player.seekTo(-50)
expect(@videoEl.currentTime).toBe @seek
@player.seekTo('5')
expect(@videoEl.currentTime).toBe @seek
@player.seekTo(500000)
expect(@videoEl.currentTime).toBe @seek
describe 'setVolume', ->
it 'set new correct value', ->
runs ->
@player.setVolume(50)
expect(@videoEl.volume).toBe 50*0.01
it 'set new inccorrect values', ->
runs ->
@player.setVolume(-50)
expect(@videoEl.volume).toBe @volume
@player.setVolume('5')
expect(@videoEl.volume).toBe @volume
@player.setVolume(500000)
expect(@videoEl.volume).toBe @volume
it 'getCurrentTime', ->
runs ->
@videoEl.currentTime = 3
expect(@player.getCurrentTime()).toBe @videoEl.currentTime
it 'playVideo', ->
runs ->
spyOn(@videoEl, 'play').andCallThrough()
@player.playVideo()
expect(@videoEl.play).toHaveBeenCalled()
it 'getPlayerState', ->
runs ->
@player.playerState = STATUS.PLAYING
expect(@player.getPlayerState()).toBe STATUS.PLAYING
@player.playerState = STATUS.ENDED
expect(@player.getPlayerState()).toBe STATUS.ENDED
it 'getVolume', ->
runs ->
@volume = @videoEl.volume = 0.5
expect(@player.getVolume()).toBe @volume
it 'getDuration', ->
runs ->
@duration = @videoEl.duration
expect(@player.getDuration()).toBe @duration
describe 'setPlaybackRate', ->
it 'set a correct value', ->
@playbackRate = 1.5
@player.setPlaybackRate @playbackRate
expect(@videoEl.playbackRate).toBe @playbackRate
it 'set NaN value', ->
@playbackRate = NaN
@player.setPlaybackRate @playbackRate
expect(@videoEl.playbackRate).toBe 1.0
it 'getAvailablePlaybackRates', ->
expect(@player.getAvailablePlaybackRates()).toEqual playbackRates
describe 'VideoPlayerAlpha', -> describe 'VideoPlayerAlpha', ->
playerVars =
controls: 0
wmode: 'transparent'
rel: 0
showinfo: 0
enablejsapi: 1
modestbranding: 1
html5: 1
beforeEach -> beforeEach ->
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false
# It tries to call methods of VideoProgressSlider on Spy # It tries to call methods of VideoProgressSlider on Spy
for part in ['VideoCaptionAlpha', 'VideoSpeedControlAlpha', 'VideoVolumeControlAlpha', 'VideoProgressSliderAlpha', 'VideoControlAlpha'] for part in ['VideoCaptionAlpha', 'VideoSpeedControlAlpha', 'VideoVolumeControlAlpha', 'VideoProgressSliderAlpha', 'VideoControlAlpha']
spyOn(window[part].prototype, 'initialize').andCallThrough() spyOn(window[part].prototype, 'initialize').andCallThrough()
jasmine.stubVideoPlayerAlpha @, [], false
afterEach -> afterEach ->
YT.Player = undefined YT.Player = undefined
describe 'constructor', -> describe 'constructor', ->
beforeEach -> beforeEach ->
spyOn YT, 'Player'
$.fn.qtip.andCallFake -> $.fn.qtip.andCallFake ->
$(this).data('qtip', true) $(this).data('qtip', true)
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
describe 'always', -> describe 'always', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
it 'instanticate current time to zero', -> it 'instanticate current time to zero', ->
...@@ -51,23 +60,6 @@ describe 'VideoPlayerAlpha', -> ...@@ -51,23 +60,6 @@ describe 'VideoPlayerAlpha', ->
expect(@player.progressSlider).toBeDefined() expect(@player.progressSlider).toBeDefined()
expect(@player.progressSlider.el).toBe $('.slider', @player.el) expect(@player.progressSlider.el).toBe $('.slider', @player.el)
it 'create Youtube player', ->
expect(YT.Player).toHaveBeenCalledWith('id', {
playerVars:
controls: 0
wmode: 'transparent'
rel: 0
showinfo: 0
enablejsapi: 1
modestbranding: 1
html5: 1
videoId: 'normalSpeedYoutubeId'
events:
onReady: @player.onReady
onStateChange: @player.onStateChange
onPlaybackQualityChange: @player.onPlaybackQualityChange
})
it 'bind to video control play event', -> it 'bind to video control play event', ->
expect($(@player.control)).toHandleWith 'play', @player.play expect($(@player.control)).toHandleWith 'play', @player.play
...@@ -92,8 +84,36 @@ describe 'VideoPlayerAlpha', -> ...@@ -92,8 +84,36 @@ describe 'VideoPlayerAlpha', ->
it 'bind to fullscreen switching button', -> it 'bind to fullscreen switching button', ->
expect($('.add-fullscreen')).toHandleWith 'click', @player.toggleFullScreen expect($('.add-fullscreen')).toHandleWith 'click', @player.toggleFullScreen
it 'create Youtube player', ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
spyOn YT, 'Player'
@player = new VideoPlayerAlpha video: @video
expect(YT.Player).toHaveBeenCalledWith('id', {
playerVars: playerVars
videoId: 'normalSpeedYoutubeId'
events:
onReady: @player.onReady
onStateChange: @player.onStateChange
onPlaybackQualityChange: @player.onPlaybackQualityChange
})
it 'create HTML5 player', ->
jasmine.stubVideoPlayerAlpha @, [], false, true
spyOn HTML5Video, 'Player'
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video
expect(HTML5Video.Player).toHaveBeenCalledWith @video.el,
playerVars: playerVars
videoSources: @video.html5Sources
events:
onReady: @player.onReady
onStateChange: @player.onStateChange
describe 'when not on a touch based device', -> describe 'when not on a touch based device', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
$('.add-fullscreen, .hide-subtitles').removeData 'qtip' $('.add-fullscreen, .hide-subtitles').removeData 'qtip'
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
...@@ -108,6 +128,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -108,6 +128,8 @@ describe 'VideoPlayerAlpha', ->
describe 'when on a touch based device', -> describe 'when on a touch based device', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
window.onTouchBasedDevice.andReturn true window.onTouchBasedDevice.andReturn true
$('.add-fullscreen, .hide-subtitles').removeData 'qtip' $('.add-fullscreen, .hide-subtitles').removeData 'qtip'
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
...@@ -122,6 +144,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -122,6 +144,8 @@ describe 'VideoPlayerAlpha', ->
describe 'onReady', -> describe 'onReady', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@video.embed() @video.embed()
@player = @video.player @player = @video.player
spyOnEvent @player, 'ready' spyOnEvent @player, 'ready'
...@@ -146,6 +170,9 @@ describe 'VideoPlayerAlpha', -> ...@@ -146,6 +170,9 @@ describe 'VideoPlayerAlpha', ->
expect(@player.play).not.toHaveBeenCalled() expect(@player.play).not.toHaveBeenCalled()
describe 'onStateChange', -> describe 'onStateChange', ->
beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
describe 'when the video is unstarted', -> describe 'when the video is unstarted', ->
beforeEach -> beforeEach ->
...@@ -234,6 +261,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -234,6 +261,8 @@ describe 'VideoPlayerAlpha', ->
describe 'onSeek', -> describe 'onSeek', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
spyOn window, 'clearInterval' spyOn window, 'clearInterval'
@player.player.interval = 100 @player.player.interval = 100
...@@ -264,6 +293,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -264,6 +293,8 @@ describe 'VideoPlayerAlpha', ->
describe 'onSpeedChange', -> describe 'onSpeedChange', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@player.currentTime = 60 @player.currentTime = 60
spyOn @player, 'updatePlayTime' spyOn @player, 'updatePlayTime'
...@@ -306,6 +337,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -306,6 +337,8 @@ describe 'VideoPlayerAlpha', ->
describe 'onVolumeChange', -> describe 'onVolumeChange', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@player.onVolumeChange undefined, 60 @player.onVolumeChange undefined, 60
...@@ -314,6 +347,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -314,6 +347,8 @@ describe 'VideoPlayerAlpha', ->
describe 'update', -> describe 'update', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
spyOn @player, 'updatePlayTime' spyOn @player, 'updatePlayTime'
...@@ -335,6 +370,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -335,6 +370,8 @@ describe 'VideoPlayerAlpha', ->
describe 'updatePlayTime', -> describe 'updatePlayTime', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
spyOn(@video, 'getDuration').andReturn 1800 spyOn(@video, 'getDuration').andReturn 1800
@player.caption.updatePlayTime = jasmine.createSpy('VideoCaptionAlpha.updatePlayTime') @player.caption.updatePlayTime = jasmine.createSpy('VideoCaptionAlpha.updatePlayTime')
...@@ -352,6 +389,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -352,6 +389,8 @@ describe 'VideoPlayerAlpha', ->
describe 'toggleFullScreen', -> describe 'toggleFullScreen', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@player.caption.resize = jasmine.createSpy('VideoCaptionAlpha.resize') @player.caption.resize = jasmine.createSpy('VideoCaptionAlpha.resize')
...@@ -388,6 +427,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -388,6 +427,8 @@ describe 'VideoPlayerAlpha', ->
describe 'play', -> describe 'play', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
describe 'when the player is not ready', -> describe 'when the player is not ready', ->
...@@ -408,6 +449,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -408,6 +449,8 @@ describe 'VideoPlayerAlpha', ->
describe 'isPlaying', -> describe 'isPlaying', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
describe 'when the video is playing', -> describe 'when the video is playing', ->
...@@ -426,6 +469,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -426,6 +469,8 @@ describe 'VideoPlayerAlpha', ->
describe 'pause', -> describe 'pause', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@player.pause() @player.pause()
...@@ -434,6 +479,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -434,6 +479,8 @@ describe 'VideoPlayerAlpha', ->
describe 'duration', -> describe 'duration', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
spyOn @video, 'getDuration' spyOn @video, 'getDuration'
@player.duration() @player.duration()
...@@ -443,6 +490,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -443,6 +490,8 @@ describe 'VideoPlayerAlpha', ->
describe 'currentSpeed', -> describe 'currentSpeed', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@video.speed = '3.0' @video.speed = '3.0'
...@@ -451,6 +500,8 @@ describe 'VideoPlayerAlpha', -> ...@@ -451,6 +500,8 @@ describe 'VideoPlayerAlpha', ->
describe 'volume', -> describe 'volume', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@player = new VideoPlayerAlpha video: @video @player = new VideoPlayerAlpha video: @video
@player.player.getVolume.andReturn 42 @player.player.getVolume.andReturn 42
......
describe 'VideoAlpha', -> describe 'VideoAlpha', ->
metadata = undefined metadata =
slowerSpeedYoutubeId:
id: @slowerSpeedYoutubeId
duration: 300
normalSpeedYoutubeId:
id: @normalSpeedYoutubeId
duration: 200
beforeEach -> beforeEach ->
loadFixtures 'videoalpha.html'
jasmine.stubRequests() jasmine.stubRequests()
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false
@videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId' @videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId'
@slowerSpeedYoutubeId = 'slowerSpeedYoutubeId' @slowerSpeedYoutubeId = 'slowerSpeedYoutubeId'
@normalSpeedYoutubeId = 'normalSpeedYoutubeId' @normalSpeedYoutubeId = 'normalSpeedYoutubeId'
metadata =
slowerSpeedYoutubeId:
id: @slowerSpeedYoutubeId
duration: 300
normalSpeedYoutubeId:
id: @normalSpeedYoutubeId
duration: 200
afterEach -> afterEach ->
window.OldVideoPlayerAlpha = undefined window.OldVideoPlayerAlpha = undefined
window.onYouTubePlayerAPIReady = undefined window.onYouTubePlayerAPIReady = undefined
window.onHTML5PlayerAPIReady = undefined
describe 'constructor', -> describe 'constructor', ->
beforeEach -> describe 'YT', ->
@stubVideoPlayerAlpha = jasmine.createSpy('VideoPlayerAlpha')
$.cookie.andReturn '0.75'
describe 'by default', ->
beforeEach -> beforeEach ->
spyOn(window.VideoAlpha.prototype, 'fetchMetadata').andCallFake -> loadFixtures 'videoalpha.html'
@metadata = metadata @stubVideoPlayerAlpha = jasmine.createSpy('VideoPlayerAlpha')
@video = new VideoAlpha '#example', @videosDefinition $.cookie.andReturn '0.75'
it 'reset the current video player', ->
expect(window.OldVideoPlayerAlpha).toBeUndefined()
it 'set the elements', -> describe 'by default', ->
expect(@video.el).toBe '#video_id' beforeEach ->
spyOn(window.VideoAlpha.prototype, 'fetchMetadata').andCallFake ->
@metadata = metadata
@video = new VideoAlpha '#example', @videosDefinition
it 'parse the videos', -> it 'check videoType', ->
expect(@video.videos).toEqual expect(@video.videoType).toEqual('youtube')
'0.75': @slowerSpeedYoutubeId
'1.0': @normalSpeedYoutubeId
it 'fetch the video metadata', -> it 'reset the current video player', ->
expect(@video.fetchMetadata).toHaveBeenCalled expect(window.OldVideoPlayerAlpha).toBeUndefined()
expect(@video.metadata).toEqual metadata
it 'parse available video speeds', -> it 'set the elements', ->
expect(@video.speeds).toEqual ['0.75', '1.0'] expect(@video.el).toBe '#video_id'
it 'set current video speed via cookie', -> it 'parse the videos', ->
expect(@video.speed).toEqual '0.75' expect(@video.videos).toEqual
'0.75': @slowerSpeedYoutubeId
'1.0': @normalSpeedYoutubeId
it 'store a reference for this video player in the element', -> it 'fetch the video metadata', ->
expect($('.video').data('video')).toEqual @video expect(@video.fetchMetadata).toHaveBeenCalled
expect(@video.metadata).toEqual metadata
describe 'when the Youtube API is already available', -> it 'parse available video speeds', ->
beforeEach -> expect(@video.speeds).toEqual ['0.75', '1.0']
@originalYT = window.YT
window.YT = { Player: true }
spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha)
@video = new VideoAlpha '#example', @videosDefinition
afterEach -> it 'set current video speed via cookie', ->
window.YT = @originalYT expect(@video.speed).toEqual '0.75'
it 'create the Video Player', -> it 'store a reference for this video player in the element', ->
expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video) expect($('.video').data('video')).toEqual @video
expect(@video.player).toEqual @stubVideoPlayerAlpha
describe 'when the Youtube API is not ready', -> describe 'when the Youtube API is already available', ->
beforeEach -> beforeEach ->
@originalYT = window.YT @originalYT = window.YT
window.YT = {} window.YT = { Player: true }
@video = new VideoAlpha '#example', @videosDefinition spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha)
@video = new VideoAlpha '#example', @videosDefinition
afterEach -> afterEach ->
window.YT = @originalYT window.YT = @originalYT
it 'set the callback on the window object', -> it 'create the Video Player', ->
expect(window.onYouTubePlayerAPIReady).toEqual jasmine.any(Function) expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayerAlpha
describe 'when the Youtube API becoming ready', -> describe 'when the Youtube API is not ready', ->
beforeEach -> beforeEach ->
@originalYT = window.YT @originalYT = window.YT
window.YT = {} window.YT = {}
spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha) @video = new VideoAlpha '#example', @videosDefinition
@video = new VideoAlpha '#example', @videosDefinition
window.onYouTubePlayerAPIReady() afterEach ->
window.YT = @originalYT
afterEach -> it 'set the callback on the window object', ->
window.YT = @originalYT expect(window.onYouTubePlayerAPIReady).toEqual jasmine.any(Function)
it 'create the Video Player for all video elements', -> describe 'when the Youtube API becoming ready', ->
expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video) beforeEach ->
expect(@video.player).toEqual @stubVideoPlayerAlpha @originalYT = window.YT
window.YT = {}
spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha)
@video = new VideoAlpha '#example', @videosDefinition
window.onYouTubePlayerAPIReady()
afterEach ->
window.YT = @originalYT
it 'create the Video Player for all video elements', ->
expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayerAlpha
describe 'HTML5', ->
beforeEach ->
loadFixtures 'videoalpha_html5.html'
@stubVideoPlayerAlpha = jasmine.createSpy('VideoPlayerAlpha')
$.cookie.andReturn '0.75'
describe 'by default', ->
beforeEach ->
@originalHTML5 = window.HTML5Video.Player
window.HTML5Video.Player = undefined
@video = new VideoAlpha '#example', @videosDefinition
afterEach ->
window.HTML5Video.Player = @originalHTML5
it 'check videoType', ->
expect(@video.videoType).toEqual('html5')
it 'reset the current video player', ->
expect(window.OldVideoPlayerAlpha).toBeUndefined()
it 'set the elements', ->
expect(@video.el).toBe '#video_id'
it 'parse the videos if subtitles exist', ->
sub = 'test_name_of_the_subtitles'
expect(@video.videos).toEqual
'0.75': sub
'1.0': sub
'1.25': sub
'1.5': sub
it 'parse the videos if subtitles doesn\'t exist', ->
$('#example').find('.video').data('sub', '')
@video = new VideoAlpha '#example', @videosDefinition
sub = ''
expect(@video.videos).toEqual
'0.75': sub
'1.0': sub
'1.25': sub
'1.5': sub
it 'parse Html5 sources', ->
html5Sources =
mp4: 'test.mp4'
webm: 'test.webm'
ogg: 'test.ogv'
expect(@video.html5Sources).toEqual html5Sources
it 'parse available video speeds', ->
speeds = jasmine.stubbedHtml5Speeds
expect(@video.speeds).toEqual speeds
it 'set current video speed via cookie', ->
expect(@video.speed).toEqual '0.75'
it 'store a reference for this video player in the element', ->
expect($('.video').data('video')).toEqual @video
describe 'when the HTML5 API is already available', ->
beforeEach ->
@originalHTML5Video = window.HTML5Video
window.HTML5Video = { Player: true }
spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha)
@video = new VideoAlpha '#example', @videosDefinition
afterEach ->
window.HTML5Video = @originalHTML5Video
it 'create the Video Player', ->
expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayerAlpha
describe 'when the HTML5 API is not ready', ->
beforeEach ->
@originalHTML5Video = window.HTML5Video
window.HTML5Video = {}
@video = new VideoAlpha '#example', @videosDefinition
afterEach ->
window.HTML5Video = @originalHTML5Video
it 'set the callback on the window object', ->
expect(window.onHTML5PlayerAPIReady).toEqual jasmine.any(Function)
describe 'when the HTML5 API becoming ready', ->
beforeEach ->
@originalHTML5Video = window.HTML5Video
window.HTML5Video = {}
spyOn(window, 'VideoPlayerAlpha').andReturn(@stubVideoPlayerAlpha)
@video = new VideoAlpha '#example', @videosDefinition
window.onHTML5PlayerAPIReady()
afterEach ->
window.HTML5Video = @originalHTML5Video
it 'create the Video Player for all video elements', ->
expect(window.VideoPlayerAlpha).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayerAlpha
describe 'youtubeId', -> describe 'youtubeId', ->
beforeEach -> beforeEach ->
loadFixtures 'videoalpha.html'
$.cookie.andReturn '1.0' $.cookie.andReturn '1.0'
@video = new VideoAlpha '#example', @videosDefinition @video = new VideoAlpha '#example', @videosDefinition
...@@ -110,28 +216,53 @@ describe 'VideoAlpha', -> ...@@ -110,28 +216,53 @@ describe 'VideoAlpha', ->
expect(@video.youtubeId()).toEqual @normalSpeedYoutubeId expect(@video.youtubeId()).toEqual @normalSpeedYoutubeId
describe 'setSpeed', -> describe 'setSpeed', ->
beforeEach -> describe 'YT', ->
@video = new VideoAlpha '#example', @videosDefinition
describe 'when new speed is available', ->
beforeEach -> beforeEach ->
@video.setSpeed '0.75' loadFixtures 'videoalpha.html'
@video = new VideoAlpha '#example', @videosDefinition
describe 'when new speed is available', ->
beforeEach ->
@video.setSpeed '0.75'
it 'set new speed', ->
expect(@video.speed).toEqual '0.75'
it 'set new speed', -> it 'save setting for new speed', ->
expect(@video.speed).toEqual '0.75' expect($.cookie).toHaveBeenCalledWith 'video_speed', '0.75', expires: 3650, path: '/'
it 'save setting for new speed', -> describe 'when new speed is not available', ->
expect($.cookie).toHaveBeenCalledWith 'video_speed', '0.75', expires: 3650, path: '/' beforeEach ->
@video.setSpeed '1.75'
describe 'when new speed is not available', -> it 'set speed to 1.0x', ->
expect(@video.speed).toEqual '1.0'
describe 'HTML5', ->
beforeEach -> beforeEach ->
@video.setSpeed '1.75' loadFixtures 'videoalpha_html5.html'
@video = new VideoAlpha '#example', @videosDefinition
describe 'when new speed is available', ->
beforeEach ->
@video.setSpeed '0.75'
it 'set new speed', ->
expect(@video.speed).toEqual '0.75'
it 'save setting for new speed', ->
expect($.cookie).toHaveBeenCalledWith 'video_speed', '0.75', expires: 3650, path: '/'
describe 'when new speed is not available', ->
beforeEach ->
@video.setSpeed '1.75'
it 'set speed to 1.0x', -> it 'set speed to 1.0x', ->
expect(@video.speed).toEqual '1.0' expect(@video.speed).toEqual '1.0'
describe 'getDuration', -> describe 'getDuration', ->
beforeEach -> beforeEach ->
loadFixtures 'videoalpha.html'
@video = new VideoAlpha '#example', @videosDefinition @video = new VideoAlpha '#example', @videosDefinition
it 'return duration for current video', -> it 'return duration for current video', ->
...@@ -139,6 +270,7 @@ describe 'VideoAlpha', -> ...@@ -139,6 +270,7 @@ describe 'VideoAlpha', ->
describe 'log', -> describe 'log', ->
beforeEach -> beforeEach ->
loadFixtures 'videoalpha.html'
@video = new VideoAlpha '#example', @videosDefinition @video = new VideoAlpha '#example', @videosDefinition
@video.setSpeed '1.0' @video.setSpeed '1.0'
spyOn Logger, 'log' spyOn Logger, 'log'
......
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