Commit 70889c36 by Anton Stupak Committed by Vasyl Nakvasiuk

Add tests for Event Logger

parent 499c682d
...@@ -316,7 +316,6 @@ describe 'VideoCaptionAlpha', -> ...@@ -316,7 +316,6 @@ describe 'VideoCaptionAlpha', ->
beforeEach -> beforeEach ->
@player = jasmine.stubVideoPlayerAlpha @ @player = jasmine.stubVideoPlayerAlpha @
@caption = @player.caption @caption = @player.caption
@time = null
$(@caption).bind 'seek', (event, time) => @time = time $(@caption).bind 'seek', (event, time) => @time = time
describe 'when the video speed is 1.0x', -> describe 'when the video speed is 1.0x', ->
...@@ -325,7 +324,7 @@ describe 'VideoCaptionAlpha', -> ...@@ -325,7 +324,7 @@ describe 'VideoCaptionAlpha', ->
$('.subtitles li[data-start="30000"]').trigger('click') $('.subtitles li[data-start="30000"]').trigger('click')
it 'trigger seek event with the correct time', -> it 'trigger seek event with the correct time', ->
expect(@time).toEqual 30.000 expect(@player.currentTime).toEqual 30.000
describe 'when the video speed is not 1.0x', -> describe 'when the video speed is not 1.0x', ->
beforeEach -> beforeEach ->
...@@ -333,7 +332,7 @@ describe 'VideoCaptionAlpha', -> ...@@ -333,7 +332,7 @@ describe 'VideoCaptionAlpha', ->
$('.subtitles li[data-start="30000"]').trigger('click') $('.subtitles li[data-start="30000"]').trigger('click')
it 'trigger seek event with the correct time', -> it 'trigger seek event with the correct time', ->
expect(@time).toEqual 40.000 expect(@player.currentTime).toEqual 40.000
describe 'toggle', -> describe 'toggle', ->
beforeEach -> beforeEach ->
......
...@@ -67,13 +67,13 @@ describe 'VideoPlayerAlpha', -> ...@@ -67,13 +67,13 @@ describe 'VideoPlayerAlpha', ->
expect($(@player.control)).toHandleWith 'pause', @player.pause expect($(@player.control)).toHandleWith 'pause', @player.pause
it 'bind to video caption seek event', -> it 'bind to video caption seek event', ->
expect($(@player.caption)).toHandleWith 'seek', @player.onSeek expect($(@player.caption)).toHandleWith 'caption_seek', @player.onSeek
it 'bind to video speed control speedChange event', -> it 'bind to video speed control speedChange event', ->
expect($(@player.speedControl)).toHandleWith 'speedChange', @player.onSpeedChange expect($(@player.speedControl)).toHandleWith 'speedChange', @player.onSpeedChange
it 'bind to video progress slider seek event', -> it 'bind to video progress slider seek event', ->
expect($(@player.progressSlider)).toHandleWith 'seek', @player.onSeek expect($(@player.progressSlider)).toHandleWith 'slide_seek', @player.onSeek
it 'bind to video volume control volumeChange event', -> it 'bind to video volume control volumeChange event', ->
expect($(@player.volumeControl)).toHandleWith 'volumeChange', @player.onVolumeChange expect($(@player.volumeControl)).toHandleWith 'volumeChange', @player.onVolumeChange
...@@ -145,6 +145,7 @@ describe 'VideoPlayerAlpha', -> ...@@ -145,6 +145,7 @@ describe 'VideoPlayerAlpha', ->
describe 'onReady', -> describe 'onReady', ->
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false jasmine.stubVideoPlayerAlpha @, [], false
spyOn @video, 'log'
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />') $('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
@video.embed() @video.embed()
@player = @video.player @player = @video.player
...@@ -152,6 +153,9 @@ describe 'VideoPlayerAlpha', -> ...@@ -152,6 +153,9 @@ describe 'VideoPlayerAlpha', ->
spyOnEvent @player, 'updatePlayTime' spyOnEvent @player, 'updatePlayTime'
@player.onReady() @player.onReady()
it 'log the load_video event', ->
expect(@video.log).toHaveBeenCalledWith 'load_video'
describe 'when not on a touch based device', -> describe 'when not on a touch based device', ->
beforeEach -> beforeEach ->
spyOn @player, 'play' spyOn @player, 'play'
...@@ -201,7 +205,7 @@ describe 'VideoPlayerAlpha', -> ...@@ -201,7 +205,7 @@ describe 'VideoPlayerAlpha', ->
@player.onStateChange data: YT.PlayerState.PLAYING @player.onStateChange data: YT.PlayerState.PLAYING
it 'log the play_video event', -> it 'log the play_video event', ->
expect(@video.log).toHaveBeenCalledWith 'play_video' expect(@video.log).toHaveBeenCalledWith 'play_video', {currentTime: 0}
it 'pause other video player', -> it 'pause other video player', ->
expect(@anotherPlayer.onPause).toHaveBeenCalled() expect(@anotherPlayer.onPause).toHaveBeenCalled()
...@@ -234,7 +238,7 @@ describe 'VideoPlayerAlpha', -> ...@@ -234,7 +238,7 @@ describe 'VideoPlayerAlpha', ->
@player.onStateChange data: YT.PlayerState.PAUSED @player.onStateChange data: YT.PlayerState.PAUSED
it 'log the pause_video event', -> it 'log the pause_video event', ->
expect(@video.log).toHaveBeenCalledWith 'pause_video' expect(@video.log).toHaveBeenCalledWith 'pause_video', {currentTime: 0}
it 'clear update interval', -> it 'clear update interval', ->
expect(window.clearInterval).toHaveBeenCalledWith 100 expect(window.clearInterval).toHaveBeenCalledWith 100
...@@ -260,6 +264,16 @@ describe 'VideoPlayerAlpha', -> ...@@ -260,6 +264,16 @@ describe 'VideoPlayerAlpha', ->
expect(@player.caption.pause).toHaveBeenCalled() expect(@player.caption.pause).toHaveBeenCalled()
describe 'onSeek', -> describe 'onSeek', ->
conf = [{
desc : 'check if seek_video is logged with slide_seek type',
type: 'slide_seek',
obj: 'progressSlider'
},{
desc : 'check if seek_video is logged with caption_seek type',
type: 'caption_seek',
obj: 'caption'
}]
beforeEach -> beforeEach ->
jasmine.stubVideoPlayerAlpha @, [], false jasmine.stubVideoPlayerAlpha @, [], false
$('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />') $('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
...@@ -267,16 +281,30 @@ describe 'VideoPlayerAlpha', -> ...@@ -267,16 +281,30 @@ describe 'VideoPlayerAlpha', ->
spyOn window, 'clearInterval' spyOn window, 'clearInterval'
@player.player.interval = 100 @player.player.interval = 100
spyOn @player, 'updatePlayTime' spyOn @player, 'updatePlayTime'
@player.onSeek {}, 60 spyOn @video, 'log'
$.each conf, (key, value) ->
it value.desc, ->
type = value.type
old_time = 0
new_time = 60
$(@player[value.obj]).trigger value.type, new_time
expect(@video.log).toHaveBeenCalledWith 'seek_video',
old_time: old_time
new_time: new_time
type: value.type
it 'seek the player', -> it 'seek the player', ->
$(@player.progressSlider).trigger 'slide_seek', 60
expect(@player.player.seekTo).toHaveBeenCalledWith 60, true expect(@player.player.seekTo).toHaveBeenCalledWith 60, true
it 'call updatePlayTime on player', -> it 'call updatePlayTime on player', ->
$(@player.progressSlider).trigger 'slide_seek', 60
expect(@player.updatePlayTime).toHaveBeenCalledWith 60 expect(@player.updatePlayTime).toHaveBeenCalledWith 60
describe 'when the player is playing', -> describe 'when the player is playing', ->
beforeEach -> beforeEach ->
$(@player.progressSlider).trigger 'slide_seek', 60
@player.player.getPlayerState.andReturn YT.PlayerState.PLAYING @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING
@player.onSeek {}, 60 @player.onSeek {}, 60
...@@ -285,6 +313,7 @@ describe 'VideoPlayerAlpha', -> ...@@ -285,6 +313,7 @@ describe 'VideoPlayerAlpha', ->
describe 'when the player is not playing', -> describe 'when the player is not playing', ->
beforeEach -> beforeEach ->
$(@player.progressSlider).trigger 'slide_seek', 60
@player.player.getPlayerState.andReturn YT.PlayerState.PAUSED @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED
@player.onSeek {}, 60 @player.onSeek {}, 60
...@@ -299,11 +328,18 @@ describe 'VideoPlayerAlpha', -> ...@@ -299,11 +328,18 @@ describe 'VideoPlayerAlpha', ->
@player.currentTime = 60 @player.currentTime = 60
spyOn @player, 'updatePlayTime' spyOn @player, 'updatePlayTime'
spyOn(@video, 'setSpeed').andCallThrough() spyOn(@video, 'setSpeed').andCallThrough()
spyOn(@video, 'log')
describe 'always', -> describe 'always', ->
beforeEach -> beforeEach ->
@player.onSpeedChange {}, '0.75', false @player.onSpeedChange {}, '0.75', false
it 'check if speed_change_video is logged', ->
expect(@video.log).toHaveBeenCalledWith 'speed_change_video',
currentTime: @player.currentTime
old_speed: '1.0'
new_speed: '0.75'
it 'convert the current time to the new speed', -> it 'convert the current time to the new speed', ->
expect(@player.currentTime).toEqual '80.000' expect(@player.currentTime).toEqual '80.000'
......
...@@ -114,9 +114,7 @@ describe 'VideoProgressSliderAlpha', -> ...@@ -114,9 +114,7 @@ describe 'VideoProgressSliderAlpha', ->
beforeEach -> beforeEach ->
@player = jasmine.stubVideoPlayerAlpha @ @player = jasmine.stubVideoPlayerAlpha @
@progressSlider = @player.progressSlider @progressSlider = @player.progressSlider
@time = null spyOnEvent @progressSlider, 'slide_seek'
$(@progressSlider).bind 'seek', (event, time) => @time = time
spyOnEvent @progressSlider, 'seek'
@progressSlider.onSlide {}, value: 20 @progressSlider.onSlide {}, value: 20
it 'freeze the slider', -> it 'freeze the slider', ->
...@@ -126,8 +124,8 @@ describe 'VideoProgressSliderAlpha', -> ...@@ -126,8 +124,8 @@ describe 'VideoProgressSliderAlpha', ->
expect($.fn.qtip).toHaveBeenCalled() expect($.fn.qtip).toHaveBeenCalled()
it 'trigger seek event', -> it 'trigger seek event', ->
expect('seek').toHaveBeenTriggeredOn @progressSlider expect('slide_seek').toHaveBeenTriggeredOn @progressSlider
expect(@time).toEqual 20 expect(@player.currentTime).toEqual 20
describe 'onChange', -> describe 'onChange', ->
beforeEach -> beforeEach ->
...@@ -142,17 +140,15 @@ describe 'VideoProgressSliderAlpha', -> ...@@ -142,17 +140,15 @@ describe 'VideoProgressSliderAlpha', ->
beforeEach -> beforeEach ->
@player = jasmine.stubVideoPlayerAlpha @ @player = jasmine.stubVideoPlayerAlpha @
@progressSlider = @player.progressSlider @progressSlider = @player.progressSlider
@time = null spyOnEvent @progressSlider, 'slide_seek'
$(@progressSlider).bind 'seek', (event, time) => @time = time
spyOnEvent @progressSlider, 'seek'
@progressSlider.onStop {}, value: 20 @progressSlider.onStop {}, value: 20
it 'freeze the slider', -> it 'freeze the slider', ->
expect(@progressSlider.frozen).toBeTruthy() expect(@progressSlider.frozen).toBeTruthy()
it 'trigger seek event', -> it 'trigger seek event', ->
expect('seek').toHaveBeenTriggeredOn @progressSlider expect('slide_seek').toHaveBeenTriggeredOn @progressSlider
expect(@time).toEqual 20 expect(@player.currentTime).toEqual 20
it 'set timeout to unfreeze the slider', -> it 'set timeout to unfreeze the slider', ->
expect(window.setTimeout).toHaveBeenCalledWith jasmine.any(Function), 200 expect(window.setTimeout).toHaveBeenCalledWith jasmine.any(Function), 200
......
...@@ -272,12 +272,13 @@ describe 'VideoAlpha', -> ...@@ -272,12 +272,13 @@ describe 'VideoAlpha', ->
beforeEach -> beforeEach ->
loadFixtures 'videoalpha.html' loadFixtures 'videoalpha.html'
@video = new VideoAlpha '#example', @videosDefinition @video = new VideoAlpha '#example', @videosDefinition
@video.setSpeed '1.0'
spyOn Logger, 'log' spyOn Logger, 'log'
@video.player = { currentTime: 25 } @video.log 'someEvent', {
@video.log 'someEvent' currentTime: 25,
speed: '1.0'
}
it 'call the logger with valid parameters', -> it 'call the logger with valid extra parameters', ->
expect(Logger.log).toHaveBeenCalledWith 'someEvent', expect(Logger.log).toHaveBeenCalledWith 'someEvent',
id: 'id' id: 'id'
code: @normalSpeedYoutubeId code: @normalSpeedYoutubeId
......
...@@ -43,7 +43,7 @@ class @VideoProgressSliderAlpha extends SubviewAlpha ...@@ -43,7 +43,7 @@ class @VideoProgressSliderAlpha extends SubviewAlpha
onStop: (event, ui) => onStop: (event, ui) =>
@frozen = true @frozen = true
$(@).trigger('seek', ui.value) $(@).trigger('slide_seek', ui.value)
setTimeout (=> @frozen = false), 200 setTimeout (=> @frozen = false), 200
updateTooltip: (value)-> updateTooltip: (value)->
......
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