Commit 47409654 by cahrens

Skip tests instead of commenting them out (for merge that is coming).

parent 05428f5b
...@@ -70,12 +70,12 @@ describe 'Problem', -> ...@@ -70,12 +70,12 @@ describe 'Problem', ->
it 'bind the math input', -> it 'bind the math input', ->
expect($('input.math')).toHandleWith 'keyup', @problem.refreshMath expect($('input.math')).toHandleWith 'keyup', @problem.refreshMath
# TODO figure out why this is failing # TODO: figure out why failing
# it 'replace math content on the page', -> xit 'replace math content on the page', ->
# expect(MathJax.Hub.Queue.mostRecentCall.args).toEqual [ expect(MathJax.Hub.Queue.mostRecentCall.args).toEqual [
# ['Text', @stubbedJax, ''], ['Text', @stubbedJax, ''],
# [@problem.updateMathML, @stubbedJax, $('#input_example_1').get(0)] [@problem.updateMathML, @stubbedJax, $('#input_example_1').get(0)]
# ] ]
describe 'render', -> describe 'render', ->
beforeEach -> beforeEach ->
...@@ -138,14 +138,14 @@ describe 'Problem', -> ...@@ -138,14 +138,14 @@ describe 'Problem', ->
@problem.check() @problem.check()
expect(@problem.el.html()).toEqual 'Incorrect!' expect(@problem.el.html()).toEqual 'Incorrect!'
# TODO figure out why this is failing # TODO: figure out why failing
# describe 'when the response is undetermined', -> xdescribe 'when the response is undetermined', ->
# it 'alert the response', -> it 'alert the response', ->
# spyOn window, 'alert' spyOn window, 'alert'
# spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
# callback(success: 'Number Only!') callback(success: 'Number Only!')
# @problem.check() @problem.check()
# expect(window.alert).toHaveBeenCalledWith 'Number Only!' expect(window.alert).toHaveBeenCalledWith 'Number Only!'
describe 'reset', -> describe 'reset', ->
beforeEach -> beforeEach ->
...@@ -264,12 +264,12 @@ describe 'Problem', -> ...@@ -264,12 +264,12 @@ describe 'Problem', ->
expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_save', expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_save',
'foo=1&bar=2', jasmine.any(Function) 'foo=1&bar=2', jasmine.any(Function)
# TODO figure out why this is failing # TODO: figure out why failing
# it 'alert to the user', -> xit 'alert to the user', ->
# spyOn window, 'alert' spyOn window, 'alert'
# spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'OK') spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'OK')
# @problem.save() @problem.save()
# expect(window.alert).toHaveBeenCalledWith 'Saved' expect(window.alert).toHaveBeenCalledWith 'Saved'
describe 'refreshMath', -> describe 'refreshMath', ->
beforeEach -> beforeEach ->
...@@ -323,10 +323,10 @@ describe 'Problem', -> ...@@ -323,10 +323,10 @@ describe 'Problem', ->
@problem.refreshAnswers() @problem.refreshAnswers()
expect(@stubCodeMirror.save).toHaveBeenCalled() expect(@stubCodeMirror.save).toHaveBeenCalled()
# TODO figure out why this is failing # TODO: figure out why failing
# it 'serialize all answers', -> xit 'serialize all answers', ->
# @problem.refreshAnswers() @problem.refreshAnswers()
# expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two" expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two"
#describe 'Sequence', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'Sequence', ->
# # Stub MathJax beforeEach ->
# window.MathJax = { Hub: { Queue: -> } } # Stub MathJax
# spyOn Logger, 'log' window.MathJax = { Hub: { Queue: -> } }
# spyOn Logger, 'log'
# loadFixtures 'sequence.html'
# @items = $.parseJSON readFixtures('items.json') loadFixtures 'sequence.html'
# @items = $.parseJSON readFixtures('items.json')
# describe 'constructor', ->
# beforeEach -> describe 'constructor', ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1 beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1
# it 'set the element', ->
# expect(@sequence.el).toEqual $('#sequence_1') it 'set the element', ->
# expect(@sequence.el).toEqual $('#sequence_1')
# it 'build the navigation', ->
# classes = $('#sequence-list li>a').map(-> $(this).attr('class')).get() it 'build the navigation', ->
# elements = $('#sequence-list li>a').map(-> $(this).attr('data-element')).get() classes = $('#sequence-list li>a').map(-> $(this).attr('class')).get()
# titles = $('#sequence-list li>a>p').map(-> $(this).html()).get() elements = $('#sequence-list li>a').map(-> $(this).attr('data-element')).get()
# titles = $('#sequence-list li>a>p').map(-> $(this).html()).get()
# expect(classes).toEqual ['seq_video_active', 'seq_video_inactive', 'seq_problem_inactive']
# expect(elements).toEqual ['1', '2', '3'] expect(classes).toEqual ['seq_video_active', 'seq_video_inactive', 'seq_problem_inactive']
# expect(titles).toEqual ['Video 1', 'Video 2', 'Sample Problem'] expect(elements).toEqual ['1', '2', '3']
# expect(titles).toEqual ['Video 1', 'Video 2', 'Sample Problem']
# it 'bind the page events', ->
# expect($('#sequence-list a')).toHandleWith 'click', @sequence.goto it 'bind the page events', ->
# expect($('#sequence-list a')).toHandleWith 'click', @sequence.goto
# it 'render the active sequence content', ->
# expect($('#seq_content').html()).toEqual 'Video 1' it 'render the active sequence content', ->
# expect($('#seq_content').html()).toEqual 'Video 1'
# describe 'toggleArrows', ->
# beforeEach -> describe 'toggleArrows', ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1 beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1
# describe 'when the first tab is active', ->
# beforeEach -> describe 'when the first tab is active', ->
# @sequence.position = 1 beforeEach ->
# @sequence.toggleArrows() @sequence.position = 1
# @sequence.toggleArrows()
# it 'disable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).toHaveClass 'disabled' it 'disable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).toHaveClass 'disabled'
# it 'enable the next button', ->
# expect($('.sequence-nav-buttons .next a')).not.toHaveClass 'disabled' it 'enable the next button', ->
# expect($('.sequence-nav-buttons .next a')).toHandleWith 'click', @sequence.next expect($('.sequence-nav-buttons .next a')).not.toHaveClass 'disabled'
# expect($('.sequence-nav-buttons .next a')).toHandleWith 'click', @sequence.next
# describe 'when the middle tab is active', ->
# beforeEach -> describe 'when the middle tab is active', ->
# @sequence.position = 2 beforeEach ->
# @sequence.toggleArrows() @sequence.position = 2
# @sequence.toggleArrows()
# it 'enable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).not.toHaveClass 'disabled' it 'enable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).toHandleWith 'click', @sequence.previous expect($('.sequence-nav-buttons .prev a')).not.toHaveClass 'disabled'
# expect($('.sequence-nav-buttons .prev a')).toHandleWith 'click', @sequence.previous
# it 'enable the next button', ->
# expect($('.sequence-nav-buttons .next a')).not.toHaveClass 'disabled' it 'enable the next button', ->
# expect($('.sequence-nav-buttons .next a')).toHandleWith 'click', @sequence.next expect($('.sequence-nav-buttons .next a')).not.toHaveClass 'disabled'
# expect($('.sequence-nav-buttons .next a')).toHandleWith 'click', @sequence.next
# describe 'when the last tab is active', ->
# beforeEach -> describe 'when the last tab is active', ->
# @sequence.position = 3 beforeEach ->
# @sequence.toggleArrows() @sequence.position = 3
# @sequence.toggleArrows()
# it 'enable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).not.toHaveClass 'disabled' it 'enable the previous button', ->
# expect($('.sequence-nav-buttons .prev a')).toHandleWith 'click', @sequence.previous expect($('.sequence-nav-buttons .prev a')).not.toHaveClass 'disabled'
# expect($('.sequence-nav-buttons .prev a')).toHandleWith 'click', @sequence.previous
# it 'disable the next button', ->
# expect($('.sequence-nav-buttons .next a')).toHaveClass 'disabled' it 'disable the next button', ->
# expect($('.sequence-nav-buttons .next a')).toHaveClass 'disabled'
# describe 'render', ->
# beforeEach -> describe 'render', ->
# spyOn $, 'postWithPrefix' beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence' spyOn $, 'postWithPrefix'
# spyOnEvent @sequence.el, 'contentChanged' @sequence = new Sequence '1', 'sequence_1', @items, 'sequence'
# spyOn(@sequence, 'toggleArrows').andCallThrough() spyOnEvent @sequence.el, 'contentChanged'
# spyOn(@sequence, 'toggleArrows').andCallThrough()
# describe 'with a different position than the current one', ->
# beforeEach -> describe 'with a different position than the current one', ->
# @sequence.render 1 beforeEach ->
# @sequence.render 1
# describe 'with no previous position', ->
# it 'does not save the new position', -> describe 'with no previous position', ->
# expect($.postWithPrefix).not.toHaveBeenCalled() it 'does not save the new position', ->
# expect($.postWithPrefix).not.toHaveBeenCalled()
# describe 'with previous position', ->
# beforeEach -> describe 'with previous position', ->
# @sequence.position = 2 beforeEach ->
# @sequence.render 1 @sequence.position = 2
# @sequence.render 1
# it 'mark the previous tab as visited', ->
# expect($('[data-element="2"]')).toHaveClass 'seq_video_visited' it 'mark the previous tab as visited', ->
# expect($('[data-element="2"]')).toHaveClass 'seq_video_visited'
# it 'save the new position', ->
# expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/goto_position', position: 1 it 'save the new position', ->
# expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/goto_position', position: 1
# it 'mark new tab as active', ->
# expect($('[data-element="1"]')).toHaveClass 'seq_video_active' it 'mark new tab as active', ->
# expect($('[data-element="1"]')).toHaveClass 'seq_video_active'
# it 'render the new content', ->
# expect($('#seq_content').html()).toEqual 'Video 1' it 'render the new content', ->
# expect($('#seq_content').html()).toEqual 'Video 1'
# it 'update the position', ->
# expect(@sequence.position).toEqual 1 it 'update the position', ->
# expect(@sequence.position).toEqual 1
# it 're-update the arrows', ->
# expect(@sequence.toggleArrows).toHaveBeenCalled() it 're-update the arrows', ->
# expect(@sequence.toggleArrows).toHaveBeenCalled()
# it 'trigger contentChanged event', ->
# expect('contentChanged').toHaveBeenTriggeredOn @sequence.el it 'trigger contentChanged event', ->
# expect('contentChanged').toHaveBeenTriggeredOn @sequence.el
# describe 'with the same position as the current one', ->
# it 'should not trigger contentChanged event', -> describe 'with the same position as the current one', ->
# @sequence.position = 2 it 'should not trigger contentChanged event', ->
# @sequence.render 2 @sequence.position = 2
# expect('contentChanged').not.toHaveBeenTriggeredOn @sequence.el @sequence.render 2
# expect('contentChanged').not.toHaveBeenTriggeredOn @sequence.el
# describe 'goto', ->
# beforeEach -> describe 'goto', ->
# jasmine.stubRequests() beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2 jasmine.stubRequests()
# $('[data-element="3"]').click() @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
# $('[data-element="3"]').click()
# it 'log the sequence goto event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_goto', old: 2, new: 3, id: '1' it 'log the sequence goto event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_goto', old: 2, new: 3, id: '1'
# it 'call render on the right sequence', ->
# expect($('#seq_content').html()).toEqual 'Sample Problem' it 'call render on the right sequence', ->
# expect($('#seq_content').html()).toEqual 'Sample Problem'
# describe 'next', ->
# beforeEach -> describe 'next', ->
# jasmine.stubRequests() beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2 jasmine.stubRequests()
# $('.sequence-nav-buttons .next a').click() @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
# $('.sequence-nav-buttons .next a').click()
# it 'log the next sequence event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_next', old: 2, new: 3, id: '1' it 'log the next sequence event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_next', old: 2, new: 3, id: '1'
# it 'call render on the next sequence', ->
# expect($('#seq_content').html()).toEqual 'Sample Problem' it 'call render on the next sequence', ->
# expect($('#seq_content').html()).toEqual 'Sample Problem'
# describe 'previous', ->
# beforeEach -> describe 'previous', ->
# jasmine.stubRequests() beforeEach ->
# @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2 jasmine.stubRequests()
# $('.sequence-nav-buttons .prev a').click() @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
# $('.sequence-nav-buttons .prev a').click()
# it 'log the previous sequence event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_prev', old: 2, new: 1, id: '1' it 'log the previous sequence event', ->
# expect(Logger.log).toHaveBeenCalledWith 'seq_prev', old: 2, new: 1, id: '1'
# it 'call render on the previous sequence', ->
# expect($('#seq_content').html()).toEqual 'Video 1' it 'call render on the previous sequence', ->
# expect($('#seq_content').html()).toEqual 'Video 1'
# describe 'link_for', ->
# it 'return a link for specific position', -> describe 'link_for', ->
# sequence = new Sequence '1', 'sequence_1', @items, 2 it 'return a link for specific position', ->
# expect(sequence.link_for(2)).toBe '[data-element="2"]' sequence = new Sequence '1', 'sequence_1', @items, 2
expect(sequence.link_for(2)).toBe '[data-element="2"]'
#describe 'VideoCaption', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoCaption', ->
# jasmine.stubVideoPlayer @ beforeEach ->
# $('.subtitles').remove() jasmine.stubVideoPlayer @
# $('.subtitles').remove()
# afterEach ->
# YT.Player = undefined afterEach ->
# $.fn.scrollTo.reset() YT.Player = undefined
# $.fn.scrollTo.reset()
# describe 'constructor', ->
# beforeEach -> describe 'constructor', ->
# spyOn($, 'getWithPrefix').andCallThrough() beforeEach ->
# spyOn($, 'getWithPrefix').andCallThrough()
# describe 'always', ->
# beforeEach -> describe 'always', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# it 'set the youtube id', ->
# expect(@caption.youtubeId).toEqual 'def456' it 'set the youtube id', ->
# expect(@caption.youtubeId).toEqual 'def456'
# it 'create the caption element', ->
# expect($('.video')).toContain 'ol.subtitles' it 'create the caption element', ->
# expect($('.video')).toContain 'ol.subtitles'
# it 'add caption control to video player', ->
# expect($('.video')).toContain 'a.hide-subtitles' it 'add caption control to video player', ->
# expect($('.video')).toContain 'a.hide-subtitles'
# it 'fetch the caption', ->
# expect($.getWithPrefix).toHaveBeenCalledWith @caption.captionURL(), jasmine.any(Function) it 'fetch the caption', ->
# expect($.getWithPrefix).toHaveBeenCalledWith @caption.captionURL(), jasmine.any(Function)
# it 'bind window resize event', ->
# expect($(window)).toHandleWith 'resize', @caption.resize it 'bind window resize event', ->
# expect($(window)).toHandleWith 'resize', @caption.resize
# it 'bind the hide caption button', ->
# expect($('.hide-subtitles')).toHandleWith 'click', @caption.toggle it 'bind the hide caption button', ->
# expect($('.hide-subtitles')).toHandleWith 'click', @caption.toggle
# it 'bind the mouse movement', ->
# expect($('.subtitles')).toHandleWith 'mouseover', @caption.onMouseEnter it 'bind the mouse movement', ->
# expect($('.subtitles')).toHandleWith 'mouseout', @caption.onMouseLeave expect($('.subtitles')).toHandleWith 'mouseover', @caption.onMouseEnter
# expect($('.subtitles')).toHandleWith 'mousemove', @caption.onMovement expect($('.subtitles')).toHandleWith 'mouseout', @caption.onMouseLeave
# expect($('.subtitles')).toHandleWith 'mousewheel', @caption.onMovement expect($('.subtitles')).toHandleWith 'mousemove', @caption.onMovement
# expect($('.subtitles')).toHandleWith 'DOMMouseScroll', @caption.onMovement expect($('.subtitles')).toHandleWith 'mousewheel', @caption.onMovement
# expect($('.subtitles')).toHandleWith 'DOMMouseScroll', @caption.onMovement
# describe 'when on a non touch-based device', ->
# beforeEach -> describe 'when on a non touch-based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn false beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' spyOn(window, 'onTouchBasedDevice').andReturn false
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# it 'render the caption', ->
# expect($('.subtitles').html()).toMatch new RegExp(''' it 'render the caption', ->
# <li data-index="0" data-start="0">Caption at 0</li> expect($('.subtitles').html()).toMatch new RegExp('''
# <li data-index="1" data-start="10000">Caption at 10000</li> <li data-index="0" data-start="0">Caption at 0</li>
# <li data-index="2" data-start="20000">Caption at 20000</li> <li data-index="1" data-start="10000">Caption at 10000</li>
# <li data-index="3" data-start="30000">Caption at 30000</li> <li data-index="2" data-start="20000">Caption at 20000</li>
# '''.replace(/\n/g, '')) <li data-index="3" data-start="30000">Caption at 30000</li>
# '''.replace(/\n/g, ''))
# it 'add a padding element to caption', ->
# expect($('.subtitles li:first')).toBe '.spacing' it 'add a padding element to caption', ->
# expect($('.subtitles li:last')).toBe '.spacing' expect($('.subtitles li:first')).toBe '.spacing'
# expect($('.subtitles li:last')).toBe '.spacing'
# it 'bind all the caption link', ->
# $('.subtitles li[data-index]').each (index, link) => it 'bind all the caption link', ->
# expect($(link)).toHandleWith 'click', @caption.seekPlayer $('.subtitles li[data-index]').each (index, link) =>
# expect($(link)).toHandleWith 'click', @caption.seekPlayer
# it 'set rendered to true', ->
# expect(@caption.rendered).toBeTruthy() it 'set rendered to true', ->
# expect(@caption.rendered).toBeTruthy()
# describe 'when on a touch-based device', ->
# beforeEach -> describe 'when on a touch-based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' spyOn(window, 'onTouchBasedDevice').andReturn true
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# it 'show explaination message', ->
# expect($('.subtitles li')).toHaveHtml "Caption will be displayed when you start playing the video." it 'show explaination message', ->
# expect($('.subtitles li')).toHaveHtml "Caption will be displayed when you start playing the video."
# it 'does not set rendered to true', ->
# expect(@caption.rendered).toBeFalsy() it 'does not set rendered to true', ->
# expect(@caption.rendered).toBeFalsy()
# describe 'mouse movement', ->
# beforeEach -> describe 'mouse movement', ->
# spyOn(window, 'setTimeout').andReturn 100 beforeEach ->
# spyOn window, 'clearTimeout' spyOn(window, 'setTimeout').andReturn 100
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' spyOn window, 'clearTimeout'
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# describe 'when cursor is outside of the caption box', ->
# beforeEach -> describe 'when cursor is outside of the caption box', ->
# $(window).trigger jQuery.Event 'mousemove' beforeEach ->
# $(window).trigger jQuery.Event 'mousemove'
# it 'does not set freezing timeout', ->
# expect(@caption.frozen).toBeFalsy() it 'does not set freezing timeout', ->
# expect(@caption.frozen).toBeFalsy()
# describe 'when cursor is in the caption box', ->
# beforeEach -> describe 'when cursor is in the caption box', ->
# $('.subtitles').trigger jQuery.Event 'mouseenter' beforeEach ->
# $('.subtitles').trigger jQuery.Event 'mouseenter'
# it 'set the freezing timeout', ->
# expect(@caption.frozen).toEqual 100 it 'set the freezing timeout', ->
# expect(@caption.frozen).toEqual 100
# describe 'when the cursor is moving', ->
# beforeEach -> describe 'when the cursor is moving', ->
# $('.subtitles').trigger jQuery.Event 'mousemove' beforeEach ->
# $('.subtitles').trigger jQuery.Event 'mousemove'
# it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100 it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100
# describe 'when the mouse is scrolling', ->
# beforeEach -> describe 'when the mouse is scrolling', ->
# $('.subtitles').trigger jQuery.Event 'mousewheel' beforeEach ->
# $('.subtitles').trigger jQuery.Event 'mousewheel'
# it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100 it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100
# describe 'when cursor is moving out of the caption box', ->
# beforeEach -> describe 'when cursor is moving out of the caption box', ->
# @caption.frozen = 100 beforeEach ->
# $.fn.scrollTo.reset() @caption.frozen = 100
# $.fn.scrollTo.reset()
# describe 'always', ->
# beforeEach -> describe 'always', ->
# $('.subtitles').trigger jQuery.Event 'mouseout' beforeEach ->
# $('.subtitles').trigger jQuery.Event 'mouseout'
# it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100 it 'reset the freezing timeout', ->
# expect(window.clearTimeout).toHaveBeenCalledWith 100
# it 'unfreeze the caption', ->
# expect(@caption.frozen).toBeNull() it 'unfreeze the caption', ->
# expect(@caption.frozen).toBeNull()
# describe 'when the player is playing', ->
# beforeEach -> describe 'when the player is playing', ->
# @caption.playing = true beforeEach ->
# $('.subtitles li[data-index]:first').addClass 'current' @caption.playing = true
# $('.subtitles').trigger jQuery.Event 'mouseout' $('.subtitles li[data-index]:first').addClass 'current'
# $('.subtitles').trigger jQuery.Event 'mouseout'
# it 'scroll the caption', ->
# expect($.fn.scrollTo).toHaveBeenCalled() it 'scroll the caption', ->
# expect($.fn.scrollTo).toHaveBeenCalled()
# describe 'when the player is not playing', ->
# beforeEach -> describe 'when the player is not playing', ->
# @caption.playing = false beforeEach ->
# $('.subtitles').trigger jQuery.Event 'mouseout' @caption.playing = false
# $('.subtitles').trigger jQuery.Event 'mouseout'
# it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled() it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled()
# describe 'search', ->
# beforeEach -> describe 'search', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# it 'return a correct caption index', ->
# expect(@caption.search(0)).toEqual 0 it 'return a correct caption index', ->
# expect(@caption.search(9999)).toEqual 0 expect(@caption.search(0)).toEqual 0
# expect(@caption.search(10000)).toEqual 1 expect(@caption.search(9999)).toEqual 0
# expect(@caption.search(15000)).toEqual 1 expect(@caption.search(10000)).toEqual 1
# expect(@caption.search(30000)).toEqual 3 expect(@caption.search(15000)).toEqual 1
# expect(@caption.search(30001)).toEqual 3 expect(@caption.search(30000)).toEqual 3
# expect(@caption.search(30001)).toEqual 3
# describe 'play', ->
# describe 'when the caption was not rendered', -> describe 'play', ->
# beforeEach -> describe 'when the caption was not rendered', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' spyOn(window, 'onTouchBasedDevice').andReturn true
# @caption.play() @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# @caption.play()
# it 'render the caption', ->
# expect($('.subtitles').html()).toMatch new RegExp( it 'render the caption', ->
# '''<li data-index="0" data-start="0">Caption at 0</li>''' + expect($('.subtitles').html()).toMatch new RegExp(
# '''<li data-index="1" data-start="10000">Caption at 10000</li>''' + '''<li data-index="0" data-start="0">Caption at 0</li>''' +
# '''<li data-index="2" data-start="20000">Caption at 20000</li>''' + '''<li data-index="1" data-start="10000">Caption at 10000</li>''' +
# '''<li data-index="3" data-start="30000">Caption at 30000</li>''' '''<li data-index="2" data-start="20000">Caption at 20000</li>''' +
# ) '''<li data-index="3" data-start="30000">Caption at 30000</li>'''
# )
# it 'add a padding element to caption', ->
# expect($('.subtitles li:first')).toBe '.spacing' it 'add a padding element to caption', ->
# expect($('.subtitles li:last')).toBe '.spacing' expect($('.subtitles li:first')).toBe '.spacing'
# expect($('.subtitles li:last')).toBe '.spacing'
# it 'bind all the caption link', ->
# $('.subtitles li[data-index]').each (index, link) => it 'bind all the caption link', ->
# expect($(link)).toHandleWith 'click', @caption.seekPlayer $('.subtitles li[data-index]').each (index, link) =>
# expect($(link)).toHandleWith 'click', @caption.seekPlayer
# it 'set rendered to true', ->
# expect(@caption.rendered).toBeTruthy() it 'set rendered to true', ->
# expect(@caption.rendered).toBeTruthy()
# it 'set playing to true', ->
# expect(@caption.playing).toBeTruthy() it 'set playing to true', ->
# expect(@caption.playing).toBeTruthy()
# describe 'pause', ->
# beforeEach -> describe 'pause', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @caption.playing = true @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# @caption.pause() @caption.playing = true
# @caption.pause()
# it 'set playing to false', ->
# expect(@caption.playing).toBeFalsy() it 'set playing to false', ->
# expect(@caption.playing).toBeFalsy()
# describe 'updatePlayTime', ->
# beforeEach -> describe 'updatePlayTime', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# describe 'when the video speed is 1.0x', ->
# beforeEach -> describe 'when the video speed is 1.0x', ->
# @caption.currentSpeed = '1.0' beforeEach ->
# @caption.updatePlayTime 25.000 @caption.currentSpeed = '1.0'
# @caption.updatePlayTime 25.000
# it 'search the caption based on time', ->
# expect(@caption.currentIndex).toEqual 2 it 'search the caption based on time', ->
# expect(@caption.currentIndex).toEqual 2
# describe 'when the video speed is not 1.0x', ->
# beforeEach -> describe 'when the video speed is not 1.0x', ->
# @caption.currentSpeed = '0.75' beforeEach ->
# @caption.updatePlayTime 25.000 @caption.currentSpeed = '0.75'
# @caption.updatePlayTime 25.000
# it 'search the caption based on 1.0x speed', ->
# expect(@caption.currentIndex).toEqual 1 it 'search the caption based on 1.0x speed', ->
# expect(@caption.currentIndex).toEqual 1
# describe 'when the index is not the same', ->
# beforeEach -> describe 'when the index is not the same', ->
# @caption.currentIndex = 1 beforeEach ->
# $('.subtitles li[data-index=1]').addClass 'current' @caption.currentIndex = 1
# @caption.updatePlayTime 25.000 $('.subtitles li[data-index=1]').addClass 'current'
# @caption.updatePlayTime 25.000
# it 'deactivate the previous caption', ->
# expect($('.subtitles li[data-index=1]')).not.toHaveClass 'current' it 'deactivate the previous caption', ->
# expect($('.subtitles li[data-index=1]')).not.toHaveClass 'current'
# it 'activate new caption', ->
# expect($('.subtitles li[data-index=2]')).toHaveClass 'current' it 'activate new caption', ->
# expect($('.subtitles li[data-index=2]')).toHaveClass 'current'
# it 'save new index', ->
# expect(@caption.currentIndex).toEqual 2 it 'save new index', ->
# expect(@caption.currentIndex).toEqual 2
# it 'scroll caption to new position', ->
# expect($.fn.scrollTo).toHaveBeenCalled() it 'scroll caption to new position', ->
# expect($.fn.scrollTo).toHaveBeenCalled()
# describe 'when the index is the same', ->
# beforeEach -> describe 'when the index is the same', ->
# @caption.currentIndex = 1 beforeEach ->
# $('.subtitles li[data-index=1]').addClass 'current' @caption.currentIndex = 1
# @caption.updatePlayTime 15.000 $('.subtitles li[data-index=1]').addClass 'current'
# @caption.updatePlayTime 15.000
# it 'does not change current subtitle', ->
# expect($('.subtitles li[data-index=1]')).toHaveClass 'current' it 'does not change current subtitle', ->
# expect($('.subtitles li[data-index=1]')).toHaveClass 'current'
# describe 'resize', ->
# beforeEach -> describe 'resize', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# $('.subtitles li[data-index=1]').addClass 'current' @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# @caption.resize() $('.subtitles li[data-index=1]').addClass 'current'
# @caption.resize()
# it 'set the height of caption container', ->
# expect(parseInt($('.subtitles').css('maxHeight'))).toEqual $('.video-wrapper').height() it 'set the height of caption container', ->
# expect(parseInt($('.subtitles').css('maxHeight'))).toEqual $('.video-wrapper').height()
# it 'set the height of caption spacing', ->
# expect(parseInt($('.subtitles .spacing:first').css('height'))).toEqual( it 'set the height of caption spacing', ->
# $('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):first').height() / 2) expect(parseInt($('.subtitles .spacing:first').css('height'))).toEqual(
# expect(parseInt($('.subtitles .spacing:last').css('height'))).toEqual( $('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):first').height() / 2)
# $('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):last').height() / 2) expect(parseInt($('.subtitles .spacing:last').css('height'))).toEqual(
# $('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):last').height() / 2)
# it 'scroll caption to new position', ->
# expect($.fn.scrollTo).toHaveBeenCalled() it 'scroll caption to new position', ->
# expect($.fn.scrollTo).toHaveBeenCalled()
# describe 'scrollCaption', ->
# beforeEach -> describe 'scrollCaption', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# describe 'when frozen', ->
# beforeEach -> describe 'when frozen', ->
# @caption.frozen = true beforeEach ->
# $('.subtitles li[data-index=1]').addClass 'current' @caption.frozen = true
# @caption.scrollCaption() $('.subtitles li[data-index=1]').addClass 'current'
# @caption.scrollCaption()
# it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled() it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled()
# describe 'when not frozen', ->
# beforeEach -> describe 'when not frozen', ->
# @caption.frozen = false beforeEach ->
# @caption.frozen = false
# describe 'when there is no current caption', ->
# beforeEach -> describe 'when there is no current caption', ->
# @caption.scrollCaption() beforeEach ->
# @caption.scrollCaption()
# it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled() it 'does not scroll the caption', ->
# expect($.fn.scrollTo).not.toHaveBeenCalled()
# describe 'when there is a current caption', ->
# beforeEach -> describe 'when there is a current caption', ->
# $('.subtitles li[data-index=1]').addClass 'current' beforeEach ->
# @caption.scrollCaption() $('.subtitles li[data-index=1]').addClass 'current'
# @caption.scrollCaption()
# it 'scroll to current caption', ->
# expect($.fn.scrollTo).toHaveBeenCalledWith $('.subtitles .current:first', @caption.el), it 'scroll to current caption', ->
# offset: - ($('.video-wrapper').height() / 2 - $('.subtitles .current:first').height() / 2) expect($.fn.scrollTo).toHaveBeenCalledWith $('.subtitles .current:first', @caption.el),
# offset: - ($('.video-wrapper').height() / 2 - $('.subtitles .current:first').height() / 2)
# describe 'seekPlayer', ->
# beforeEach -> describe 'seekPlayer', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# @time = null @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# $(@caption).bind 'seek', (event, time) => @time = time @time = null
# $(@caption).bind 'seek', (event, time) => @time = time
# describe 'when the video speed is 1.0x', ->
# beforeEach -> describe 'when the video speed is 1.0x', ->
# @caption.currentSpeed = '1.0' beforeEach ->
# $('.subtitles li[data-start="30000"]').click() @caption.currentSpeed = '1.0'
# $('.subtitles li[data-start="30000"]').click()
# it 'trigger seek event with the correct time', ->
# expect(@time).toEqual 30.000 it 'trigger seek event with the correct time', ->
# expect(@time).toEqual 30.000
# describe 'when the video speed is not 1.0x', ->
# beforeEach -> describe 'when the video speed is not 1.0x', ->
# @caption.currentSpeed = '0.75' beforeEach ->
# $('.subtitles li[data-start="30000"]').click() @caption.currentSpeed = '0.75'
# $('.subtitles li[data-start="30000"]').click()
# it 'trigger seek event with the correct time', ->
# expect(@time).toEqual 40.000 it 'trigger seek event with the correct time', ->
# expect(@time).toEqual 40.000
# describe 'toggle', ->
# beforeEach -> describe 'toggle', ->
# @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0' beforeEach ->
# $('.subtitles li[data-index=1]').addClass 'current' @caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
# $('.subtitles li[data-index=1]').addClass 'current'
# describe 'when the caption is visible', ->
# beforeEach -> describe 'when the caption is visible', ->
# @caption.el.removeClass 'closed' beforeEach ->
# @caption.toggle jQuery.Event('click') @caption.el.removeClass 'closed'
# @caption.toggle jQuery.Event('click')
# it 'hide the caption', ->
# expect(@caption.el).toHaveClass 'closed' it 'hide the caption', ->
# expect(@caption.el).toHaveClass 'closed'
#
# describe 'when the caption is hidden', ->
# beforeEach -> describe 'when the caption is hidden', ->
# @caption.el.addClass 'closed' beforeEach ->
# @caption.toggle jQuery.Event('click') @caption.el.addClass 'closed'
# @caption.toggle jQuery.Event('click')
# it 'show the caption', ->
# expect(@caption.el).not.toHaveClass 'closed' it 'show the caption', ->
# expect(@caption.el).not.toHaveClass 'closed'
# it 'scroll the caption', ->
# expect($.fn.scrollTo).toHaveBeenCalled() it 'scroll the caption', ->
expect($.fn.scrollTo).toHaveBeenCalled()
#describe 'VideoControl', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoControl', ->
# jasmine.stubVideoPlayer @ beforeEach ->
# $('.video-controls').html '' jasmine.stubVideoPlayer @
# $('.video-controls').html ''
# describe 'constructor', ->
# it 'render the video controls', -> describe 'constructor', ->
# new VideoControl(el: $('.video-controls')) it 'render the video controls', ->
# expect($('.video-controls').html()).toContain ''' new VideoControl(el: $('.video-controls'))
# <div class="slider"></div> expect($('.video-controls').html()).toContain '''
# <div> <div class="slider"></div>
# <ul class="vcr"> <div>
# <li><a class="video_control play" href="#">Play</a></li> <ul class="vcr">
# <li> <li><a class="video_control play" href="#">Play</a></li>
# <div class="vidtime">0:00 / 0:00</div> <li>
# </li> <div class="vidtime">0:00 / 0:00</div>
# </ul> </li>
# <div class="secondary-controls"> </ul>
# <a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a> <div class="secondary-controls">
# </div> <a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a>
# </div> </div>
# ''' </div>
# '''
# it 'bind the playback button', ->
# control = new VideoControl(el: $('.video-controls')) it 'bind the playback button', ->
# expect($('.video_control')).toHandleWith 'click', control.togglePlayback control = new VideoControl(el: $('.video-controls'))
# expect($('.video_control')).toHandleWith 'click', control.togglePlayback
# describe 'when on a touch based device', ->
# beforeEach -> describe 'when on a touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# spyOn(window, 'onTouchBasedDevice').andReturn true
# it 'does not add the play class to video control', ->
# new VideoControl(el: $('.video-controls')) it 'does not add the play class to video control', ->
# expect($('.video_control')).not.toHaveClass 'play' new VideoControl(el: $('.video-controls'))
# expect($('.video_control')).not.toHaveHtml 'Play' expect($('.video_control')).not.toHaveClass 'play'
# expect($('.video_control')).not.toHaveHtml 'Play'
#
# describe 'when on a non-touch based device', ->
# beforeEach -> describe 'when on a non-touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn false beforeEach ->
# spyOn(window, 'onTouchBasedDevice').andReturn false
# it 'add the play class to video control', ->
# new VideoControl(el: $('.video-controls')) it 'add the play class to video control', ->
# expect($('.video_control')).toHaveClass 'play' new VideoControl(el: $('.video-controls'))
# expect($('.video_control')).toHaveHtml 'Play' expect($('.video_control')).toHaveClass 'play'
# expect($('.video_control')).toHaveHtml 'Play'
# describe 'play', ->
# beforeEach -> describe 'play', ->
# @control = new VideoControl(el: $('.video-controls')) beforeEach ->
# @control.play() @control = new VideoControl(el: $('.video-controls'))
# @control.play()
# it 'switch playback button to play state', ->
# expect($('.video_control')).not.toHaveClass 'play' it 'switch playback button to play state', ->
# expect($('.video_control')).toHaveClass 'pause' expect($('.video_control')).not.toHaveClass 'play'
# expect($('.video_control')).toHaveHtml 'Pause' expect($('.video_control')).toHaveClass 'pause'
# expect($('.video_control')).toHaveHtml 'Pause'
# describe 'pause', ->
# beforeEach -> describe 'pause', ->
# @control = new VideoControl(el: $('.video-controls')) beforeEach ->
# @control.pause() @control = new VideoControl(el: $('.video-controls'))
# @control.pause()
# it 'switch playback button to pause state', ->
# expect($('.video_control')).not.toHaveClass 'pause' it 'switch playback button to pause state', ->
# expect($('.video_control')).toHaveClass 'play' expect($('.video_control')).not.toHaveClass 'pause'
# expect($('.video_control')).toHaveHtml 'Play' expect($('.video_control')).toHaveClass 'play'
# expect($('.video_control')).toHaveHtml 'Play'
# describe 'togglePlayback', ->
# beforeEach -> describe 'togglePlayback', ->
# @control = new VideoControl(el: $('.video-controls')) beforeEach ->
# @control = new VideoControl(el: $('.video-controls'))
# describe 'when the control does not have play or pause class', ->
# beforeEach -> describe 'when the control does not have play or pause class', ->
# $('.video_control').removeClass('play').removeClass('pause') beforeEach ->
# $('.video_control').removeClass('play').removeClass('pause')
# describe 'when the video is playing', ->
# beforeEach -> describe 'when the video is playing', ->
# $('.video_control').addClass('play') beforeEach ->
# spyOnEvent @control, 'pause' $('.video_control').addClass('play')
# @control.togglePlayback jQuery.Event('click') spyOnEvent @control, 'pause'
# @control.togglePlayback jQuery.Event('click')
# it 'does not trigger the pause event', ->
# expect('pause').not.toHaveBeenTriggeredOn @control it 'does not trigger the pause event', ->
# expect('pause').not.toHaveBeenTriggeredOn @control
# describe 'when the video is paused', ->
# beforeEach -> describe 'when the video is paused', ->
# $('.video_control').addClass('pause') beforeEach ->
# spyOnEvent @control, 'play' $('.video_control').addClass('pause')
# @control.togglePlayback jQuery.Event('click') spyOnEvent @control, 'play'
# @control.togglePlayback jQuery.Event('click')
# it 'does not trigger the play event', ->
# expect('play').not.toHaveBeenTriggeredOn @control it 'does not trigger the play event', ->
# expect('play').not.toHaveBeenTriggeredOn @control
# describe 'when the video is playing', ->
# beforeEach -> describe 'when the video is playing', ->
# spyOnEvent @control, 'pause' beforeEach ->
# $('.video_control').addClass 'pause' spyOnEvent @control, 'pause'
# @control.togglePlayback jQuery.Event('click') $('.video_control').addClass 'pause'
# @control.togglePlayback jQuery.Event('click')
# it 'trigger the pause event', ->
# expect('pause').toHaveBeenTriggeredOn @control it 'trigger the pause event', ->
# expect('pause').toHaveBeenTriggeredOn @control
# describe 'when the video is paused', ->
# beforeEach -> describe 'when the video is paused', ->
# spyOnEvent @control, 'play' beforeEach ->
# $('.video_control').addClass 'play' spyOnEvent @control, 'play'
# @control.togglePlayback jQuery.Event('click') $('.video_control').addClass 'play'
# @control.togglePlayback jQuery.Event('click')
# it 'trigger the play event', ->
# expect('play').toHaveBeenTriggeredOn @control it 'trigger the play event', ->
expect('play').toHaveBeenTriggeredOn @control
#describe 'VideoPlayer', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoPlayer', ->
# jasmine.stubVideoPlayer @, [], false beforeEach ->
# jasmine.stubVideoPlayer @, [], false
# afterEach ->
# YT.Player = undefined afterEach ->
# YT.Player = undefined
# describe 'constructor', ->
# beforeEach -> describe 'constructor', ->
# spyOn window, 'VideoControl' beforeEach ->
# spyOn YT, 'Player' spyOn window, 'VideoControl'
# $.fn.qtip.andCallFake -> spyOn YT, 'Player'
# $(this).data('qtip', true) $.fn.qtip.andCallFake ->
# $('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />') $(this).data('qtip', true)
# $('.video').append $('<div class="add-fullscreen" /><div class="hide-subtitles" />')
# describe 'always', ->
# beforeEach -> describe 'always', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player = new VideoPlayer video: @video
# it 'instanticate current time to zero', ->
# expect(@player.currentTime).toEqual 0 it 'instanticate current time to zero', ->
# expect(@player.currentTime).toEqual 0
# it 'set the element', ->
# expect(@player.el).toBe '#video_example' it 'set the element', ->
# expect(@player.el).toBe '#video_example'
# it 'create video control', ->
# expect(window.VideoControl).toHaveBeenCalledWith el: $('.video-controls', @player.el) it 'create video control', ->
# expect(window.VideoControl).toHaveBeenCalledWith el: $('.video-controls', @player.el)
# it 'create video caption', ->
# expect(window.VideoCaption).toHaveBeenCalledWith el: @player.el, youtubeId: 'normalSpeedYoutubeId', currentSpeed: '1.0' it 'create video caption', ->
# expect(window.VideoCaption).toHaveBeenCalledWith el: @player.el, youtubeId: 'normalSpeedYoutubeId', currentSpeed: '1.0'
# it 'create video speed control', ->
# expect(window.VideoSpeedControl).toHaveBeenCalledWith el: $('.secondary-controls', @player.el), speeds: ['0.75', '1.0'], currentSpeed: '1.0' it 'create video speed control', ->
# expect(window.VideoSpeedControl).toHaveBeenCalledWith el: $('.secondary-controls', @player.el), speeds: ['0.75', '1.0'], currentSpeed: '1.0'
# it 'create video progress slider', ->
# expect(window.VideoProgressSlider).toHaveBeenCalledWith el: $('.slider', @player.el) it 'create video progress slider', ->
# expect(window.VideoProgressSlider).toHaveBeenCalledWith el: $('.slider', @player.el)
# it 'create Youtube player', ->
# expect(YT.Player).toHaveBeenCalledWith 'example' it 'create Youtube player', ->
# playerVars: expect(YT.Player).toHaveBeenCalledWith 'example'
# controls: 0 playerVars:
# wmode: 'transparent' controls: 0
# rel: 0 wmode: 'transparent'
# showinfo: 0 rel: 0
# enablejsapi: 1 showinfo: 0
# videoId: 'normalSpeedYoutubeId' enablejsapi: 1
# events: videoId: 'normalSpeedYoutubeId'
# onReady: @player.onReady events:
# onStateChange: @player.onStateChange onReady: @player.onReady
# onStateChange: @player.onStateChange
# it 'bind to video control play event', ->
# expect($(@player.control)).toHandleWith 'play', @player.play it 'bind to video control play event', ->
# expect($(@player.control)).toHandleWith 'play', @player.play
# it 'bind to video control pause event', ->
# expect($(@player.control)).toHandleWith 'pause', @player.pause it 'bind to video control pause event', ->
# expect($(@player.control)).toHandleWith 'pause', @player.pause
# it 'bind to video caption seek event', ->
# expect($(@player.caption)).toHandleWith 'seek', @player.onSeek it 'bind to video caption seek event', ->
# expect($(@player.caption)).toHandleWith 'seek', @player.onSeek
# it 'bind to video speed control speedChange event', ->
# expect($(@player.speedControl)).toHandleWith 'speedChange', @player.onSpeedChange it 'bind to video speed control speedChange event', ->
# expect($(@player.speedControl)).toHandleWith 'speedChange', @player.onSpeedChange
# it 'bind to video progress slider seek event', ->
# expect($(@player.progressSlider)).toHandleWith 'seek', @player.onSeek it 'bind to video progress slider seek event', ->
# expect($(@player.progressSlider)).toHandleWith 'seek', @player.onSeek
# it 'bind to video volume control volumeChange event', ->
# expect($(@player.volumeControl)).toHandleWith 'volumeChange', @player.onVolumeChange it 'bind to video volume control volumeChange event', ->
# expect($(@player.volumeControl)).toHandleWith 'volumeChange', @player.onVolumeChange
# it 'bind to key press', ->
# expect($(document)).toHandleWith 'keyup', @player.bindExitFullScreen it 'bind to key press', ->
# expect($(document)).toHandleWith 'keyup', @player.bindExitFullScreen
# it 'bind to fullscreen switching button', ->
# expect($('.add-fullscreen')).toHandleWith 'click', @player.toggleFullScreen it 'bind to fullscreen switching button', ->
# expect($('.add-fullscreen')).toHandleWith 'click', @player.toggleFullScreen
# describe 'when not on a touch based device', ->
# beforeEach -> describe 'when not on a touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn false beforeEach ->
# $('.add-fullscreen, .hide-subtitles').removeData 'qtip' spyOn(window, 'onTouchBasedDevice').andReturn false
# @player = new VideoPlayer video: @video $('.add-fullscreen, .hide-subtitles').removeData 'qtip'
# @player = new VideoPlayer video: @video
# it 'add the tooltip to fullscreen and subtitle button', ->
# expect($('.add-fullscreen')).toHaveData 'qtip' it 'add the tooltip to fullscreen and subtitle button', ->
# expect($('.hide-subtitles')).toHaveData 'qtip' expect($('.add-fullscreen')).toHaveData 'qtip'
# expect($('.hide-subtitles')).toHaveData 'qtip'
# it 'create video volume control', ->
# expect(window.VideoVolumeControl).toHaveBeenCalledWith el: $('.secondary-controls', @player.el) it 'create video volume control', ->
# expect(window.VideoVolumeControl).toHaveBeenCalledWith el: $('.secondary-controls', @player.el)
# describe 'when on a touch based device', ->
# beforeEach -> describe 'when on a touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# $('.add-fullscreen, .hide-subtitles').removeData 'qtip' spyOn(window, 'onTouchBasedDevice').andReturn true
# @player = new VideoPlayer video: @video $('.add-fullscreen, .hide-subtitles').removeData 'qtip'
# @player = new VideoPlayer video: @video
# it 'does not add the tooltip to fullscreen and subtitle button', ->
# expect($('.add-fullscreen')).not.toHaveData 'qtip' it 'does not add the tooltip to fullscreen and subtitle button', ->
# expect($('.hide-subtitles')).not.toHaveData 'qtip' expect($('.add-fullscreen')).not.toHaveData 'qtip'
# expect($('.hide-subtitles')).not.toHaveData 'qtip'
# it 'does not create video volume control', ->
# expect(window.VideoVolumeControl).not.toHaveBeenCalled() it 'does not create video volume control', ->
# expect(window.VideoVolumeControl).not.toHaveBeenCalled()
# describe 'onReady', ->
# beforeEach -> describe 'onReady', ->
# @video.embed() beforeEach ->
# @player = @video.player @video.embed()
# spyOnEvent @player, 'ready' @player = @video.player
# spyOnEvent @player, 'updatePlayTime' spyOnEvent @player, 'ready'
# @player.onReady() spyOnEvent @player, 'updatePlayTime'
# @player.onReady()
# describe 'when not on a touch based device', ->
# beforeEach -> describe 'when not on a touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn false beforeEach ->
# spyOn @player, 'play' spyOn(window, 'onTouchBasedDevice').andReturn false
# @player.onReady() spyOn @player, 'play'
# @player.onReady()
# it 'autoplay the first video', ->
# expect(@player.play).toHaveBeenCalled() it 'autoplay the first video', ->
# expect(@player.play).toHaveBeenCalled()
# describe 'when on a touch based device', ->
# beforeEach -> describe 'when on a touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# spyOn @player, 'play' spyOn(window, 'onTouchBasedDevice').andReturn true
# @player.onReady() spyOn @player, 'play'
# @player.onReady()
# it 'does not autoplay the first video', ->
# expect(@player.play).not.toHaveBeenCalled() it 'does not autoplay the first video', ->
# expect(@player.play).not.toHaveBeenCalled()
# describe 'onStateChange', ->
# beforeEach -> describe 'onStateChange', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player = new VideoPlayer video: @video
# describe 'when the video is unstarted', ->
# beforeEach -> describe 'when the video is unstarted', ->
# spyOn @player.control, 'pause' beforeEach ->
# @player.caption.pause = jasmine.createSpy('VideoCaption.pause') spyOn @player.control, 'pause'
# @player.onStateChange data: YT.PlayerState.UNSTARTED @player.caption.pause = jasmine.createSpy('VideoCaption.pause')
# @player.onStateChange data: YT.PlayerState.UNSTARTED
# it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled() it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled()
# it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled() it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled()
# describe 'when the video is playing', ->
# beforeEach -> describe 'when the video is playing', ->
# @anotherPlayer = jasmine.createSpyObj 'AnotherPlayer', ['pauseVideo'] beforeEach ->
# window.player = @anotherPlayer @anotherPlayer = jasmine.createSpyObj 'AnotherPlayer', ['pauseVideo']
# spyOn @video, 'log' window.player = @anotherPlayer
# spyOn(window, 'setInterval').andReturn 100 spyOn @video, 'log'
# spyOn @player.control, 'play' spyOn(window, 'setInterval').andReturn 100
# @player.caption.play = jasmine.createSpy('VideoCaption.play') spyOn @player.control, 'play'
# @player.progressSlider.play = jasmine.createSpy('VideoProgressSlider.play') @player.caption.play = jasmine.createSpy('VideoCaption.play')
# @player.player.getVideoEmbedCode.andReturn 'embedCode' @player.progressSlider.play = jasmine.createSpy('VideoProgressSlider.play')
# @player.onStateChange data: YT.PlayerState.PLAYING @player.player.getVideoEmbedCode.andReturn 'embedCode'
# @player.onStateChange data: YT.PlayerState.PLAYING
# it 'log the play_video event', ->
# expect(@video.log).toHaveBeenCalledWith 'play_video' it 'log the play_video event', ->
# expect(@video.log).toHaveBeenCalledWith 'play_video'
# it 'pause other video player', ->
# expect(@anotherPlayer.pauseVideo).toHaveBeenCalled() it 'pause other video player', ->
# expect(@anotherPlayer.pauseVideo).toHaveBeenCalled()
# it 'set current video player as active player', ->
# expect(window.player).toEqual @player.player it 'set current video player as active player', ->
# expect(window.player).toEqual @player.player
# it 'set update interval', ->
# expect(window.setInterval).toHaveBeenCalledWith @player.update, 200 it 'set update interval', ->
# expect(@player.player.interval).toEqual 100 expect(window.setInterval).toHaveBeenCalledWith @player.update, 200
# expect(@player.player.interval).toEqual 100
# it 'play the video control', ->
# expect(@player.control.play).toHaveBeenCalled() it 'play the video control', ->
# expect(@player.control.play).toHaveBeenCalled()
# it 'play the video caption', ->
# expect(@player.caption.play).toHaveBeenCalled() it 'play the video caption', ->
# expect(@player.caption.play).toHaveBeenCalled()
# it 'play the video progress slider', ->
# expect(@player.progressSlider.play).toHaveBeenCalled() it 'play the video progress slider', ->
# expect(@player.progressSlider.play).toHaveBeenCalled()
# describe 'when the video is paused', ->
# beforeEach -> describe 'when the video is paused', ->
# @player = new VideoPlayer video: @video beforeEach ->
# window.player = @player.player @player = new VideoPlayer video: @video
# spyOn @video, 'log' window.player = @player.player
# spyOn window, 'clearInterval' spyOn @video, 'log'
# spyOn @player.control, 'pause' spyOn window, 'clearInterval'
# @player.caption.pause = jasmine.createSpy('VideoCaption.pause') spyOn @player.control, 'pause'
# @player.player.interval = 100 @player.caption.pause = jasmine.createSpy('VideoCaption.pause')
# @player.player.getVideoEmbedCode.andReturn 'embedCode' @player.player.interval = 100
# @player.onStateChange data: YT.PlayerState.PAUSED @player.player.getVideoEmbedCode.andReturn 'embedCode'
# @player.onStateChange data: YT.PlayerState.PAUSED
# it 'log the pause_video event', ->
# expect(@video.log).toHaveBeenCalledWith 'pause_video' it 'log the pause_video event', ->
# expect(@video.log).toHaveBeenCalledWith 'pause_video'
# it 'set current video player as inactive', ->
# expect(window.player).toBeNull() it 'set current video player as inactive', ->
# expect(window.player).toBeNull()
# it 'clear update interval', ->
# expect(window.clearInterval).toHaveBeenCalledWith 100 it 'clear update interval', ->
# expect(@player.player.interval).toBeNull() expect(window.clearInterval).toHaveBeenCalledWith 100
# expect(@player.player.interval).toBeNull()
# it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled() it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled()
# it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled() it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled()
# describe 'when the video is ended', ->
# beforeEach -> describe 'when the video is ended', ->
# spyOn @player.control, 'pause' beforeEach ->
# @player.caption.pause = jasmine.createSpy('VideoCaption.pause') spyOn @player.control, 'pause'
# @player.onStateChange data: YT.PlayerState.ENDED @player.caption.pause = jasmine.createSpy('VideoCaption.pause')
# @player.onStateChange data: YT.PlayerState.ENDED
# it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled() it 'pause the video control', ->
# expect(@player.control.pause).toHaveBeenCalled()
# it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled() it 'pause the video caption', ->
# expect(@player.caption.pause).toHaveBeenCalled()
# describe 'onSeek', ->
# beforeEach -> describe 'onSeek', ->
# @player = new VideoPlayer video: @video beforeEach ->
# spyOn window, 'clearInterval' @player = new VideoPlayer video: @video
# @player.player.interval = 100 spyOn window, 'clearInterval'
# spyOn @player, 'updatePlayTime' @player.player.interval = 100
# @player.onSeek {}, 60 spyOn @player, 'updatePlayTime'
# @player.onSeek {}, 60
# it 'seek the player', ->
# expect(@player.player.seekTo).toHaveBeenCalledWith 60, true it 'seek the player', ->
# expect(@player.player.seekTo).toHaveBeenCalledWith 60, true
# it 'call updatePlayTime on player', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith 60 it 'call updatePlayTime on player', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith 60
# describe 'when the player is playing', ->
# beforeEach -> describe 'when the player is playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING beforeEach ->
# @player.onSeek {}, 60 @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING
# @player.onSeek {}, 60
# it 'reset the update interval', ->
# expect(window.clearInterval).toHaveBeenCalledWith 100 it 'reset the update interval', ->
# expect(window.clearInterval).toHaveBeenCalledWith 100
# describe 'when the player is not playing', ->
# beforeEach -> describe 'when the player is not playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED beforeEach ->
# @player.onSeek {}, 60 @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED
# @player.onSeek {}, 60
# it 'set the current time', ->
# expect(@player.currentTime).toEqual 60 it 'set the current time', ->
# expect(@player.currentTime).toEqual 60
# describe 'onSpeedChange', ->
# beforeEach -> describe 'onSpeedChange', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player.currentTime = 60 @player = new VideoPlayer video: @video
# spyOn @player, 'updatePlayTime' @player.currentTime = 60
# spyOn(@video, 'setSpeed').andCallThrough() spyOn @player, 'updatePlayTime'
# spyOn(@video, 'setSpeed').andCallThrough()
# describe 'always', ->
# beforeEach -> describe 'always', ->
# @player.onSpeedChange {}, '0.75' beforeEach ->
# @player.onSpeedChange {}, '0.75'
# it 'convert the current time to the new speed', ->
# expect(@player.currentTime).toEqual '80.000' it 'convert the current time to the new speed', ->
# expect(@player.currentTime).toEqual '80.000'
# it 'set video speed to the new speed', ->
# expect(@video.setSpeed).toHaveBeenCalledWith '0.75' it 'set video speed to the new speed', ->
# expect(@video.setSpeed).toHaveBeenCalledWith '0.75'
# it 'tell video caption that the speed has changed', ->
# expect(@player.caption.currentSpeed).toEqual '0.75' it 'tell video caption that the speed has changed', ->
# expect(@player.caption.currentSpeed).toEqual '0.75'
# describe 'when the video is playing', ->
# beforeEach -> describe 'when the video is playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING beforeEach ->
# @player.onSpeedChange {}, '0.75' @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING
# @player.onSpeedChange {}, '0.75'
# it 'load the video', ->
# expect(@player.player.loadVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' it 'load the video', ->
# expect(@player.player.loadVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000'
# it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000'
# describe 'when the video is not playing', ->
# beforeEach -> describe 'when the video is not playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED beforeEach ->
# @player.onSpeedChange {}, '0.75' @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED
# @player.onSpeedChange {}, '0.75'
# it 'cue the video', ->
# expect(@player.player.cueVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000' it 'cue the video', ->
# expect(@player.player.cueVideoById).toHaveBeenCalledWith 'slowerSpeedYoutubeId', '80.000'
# it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000' it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith '80.000'
# describe 'onVolumeChange', ->
# beforeEach -> describe 'onVolumeChange', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player.onVolumeChange undefined, 60 @player = new VideoPlayer video: @video
# @player.onVolumeChange undefined, 60
# it 'set the volume on player', ->
# expect(@player.player.setVolume).toHaveBeenCalledWith 60 it 'set the volume on player', ->
# expect(@player.player.setVolume).toHaveBeenCalledWith 60
# describe 'update', ->
# beforeEach -> describe 'update', ->
# @player = new VideoPlayer video: @video beforeEach ->
# spyOn @player, 'updatePlayTime' @player = new VideoPlayer video: @video
# spyOn @player, 'updatePlayTime'
# describe 'when the current time is unavailable from the player', ->
# beforeEach -> describe 'when the current time is unavailable from the player', ->
# @player.player.getCurrentTime.andReturn undefined beforeEach ->
# @player.update() @player.player.getCurrentTime.andReturn undefined
# @player.update()
# it 'does not trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).not.toHaveBeenCalled() it 'does not trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).not.toHaveBeenCalled()
# describe 'when the current time is available from the player', ->
# beforeEach -> describe 'when the current time is available from the player', ->
# @player.player.getCurrentTime.andReturn 60 beforeEach ->
# @player.update() @player.player.getCurrentTime.andReturn 60
# @player.update()
# it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith(60) it 'trigger updatePlayTime event', ->
# expect(@player.updatePlayTime).toHaveBeenCalledWith(60)
# describe 'updatePlayTime', ->
# beforeEach -> describe 'updatePlayTime', ->
# @player = new VideoPlayer video: @video beforeEach ->
# spyOn(@video, 'getDuration').andReturn 1800 @player = new VideoPlayer video: @video
# @player.caption.updatePlayTime = jasmine.createSpy('VideoCaption.updatePlayTime') spyOn(@video, 'getDuration').andReturn 1800
# @player.progressSlider.updatePlayTime = jasmine.createSpy('VideoProgressSlider.updatePlayTime') @player.caption.updatePlayTime = jasmine.createSpy('VideoCaption.updatePlayTime')
# @player.updatePlayTime 60 @player.progressSlider.updatePlayTime = jasmine.createSpy('VideoProgressSlider.updatePlayTime')
# @player.updatePlayTime 60
# it 'update the video playback time', ->
# expect($('.vidtime')).toHaveHtml '1:00 / 30:00' it 'update the video playback time', ->
# expect($('.vidtime')).toHaveHtml '1:00 / 30:00'
# it 'update the playback time on caption', ->
# expect(@player.caption.updatePlayTime).toHaveBeenCalledWith 60 it 'update the playback time on caption', ->
# expect(@player.caption.updatePlayTime).toHaveBeenCalledWith 60
# it 'update the playback time on progress slider', ->
# expect(@player.progressSlider.updatePlayTime).toHaveBeenCalledWith 60, 1800 it 'update the playback time on progress slider', ->
# expect(@player.progressSlider.updatePlayTime).toHaveBeenCalledWith 60, 1800
# describe 'toggleFullScreen', ->
# beforeEach -> describe 'toggleFullScreen', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player.caption.resize = jasmine.createSpy('VideoCaption.resize') @player = new VideoPlayer video: @video
# @player.caption.resize = jasmine.createSpy('VideoCaption.resize')
# describe 'when the video player is not full screen', ->
# beforeEach -> describe 'when the video player is not full screen', ->
# @player.el.removeClass 'fullscreen' beforeEach ->
# @player.toggleFullScreen(jQuery.Event("click")) @player.el.removeClass 'fullscreen'
# @player.toggleFullScreen(jQuery.Event("click"))
# it 'replace the full screen button tooltip', ->
# expect($('.add-fullscreen')).toHaveAttr 'title', 'Exit fill browser' it 'replace the full screen button tooltip', ->
# expect($('.add-fullscreen')).toHaveAttr 'title', 'Exit fill browser'
# it 'add a new exit from fullscreen button', ->
# expect(@player.el).toContain 'a.exit' it 'add a new exit from fullscreen button', ->
# expect(@player.el).toContain 'a.exit'
# it 'add the fullscreen class', ->
# expect(@player.el).toHaveClass 'fullscreen' it 'add the fullscreen class', ->
# expect(@player.el).toHaveClass 'fullscreen'
# it 'tell VideoCaption to resize', ->
# expect(@player.caption.resize).toHaveBeenCalled() it 'tell VideoCaption to resize', ->
# expect(@player.caption.resize).toHaveBeenCalled()
# describe 'when the video player already full screen', ->
# beforeEach -> describe 'when the video player already full screen', ->
# @player.el.addClass 'fullscreen' beforeEach ->
# @player.toggleFullScreen(jQuery.Event("click")) @player.el.addClass 'fullscreen'
# @player.toggleFullScreen(jQuery.Event("click"))
# it 'replace the full screen button tooltip', ->
# expect($('.add-fullscreen')).toHaveAttr 'title', 'Fill browser' it 'replace the full screen button tooltip', ->
# expect($('.add-fullscreen')).toHaveAttr 'title', 'Fill browser'
# it 'remove exit full screen button', ->
# expect(@player.el).not.toContain 'a.exit' it 'remove exit full screen button', ->
# expect(@player.el).not.toContain 'a.exit'
# it 'remove the fullscreen class', ->
# expect(@player.el).not.toHaveClass 'fullscreen' it 'remove the fullscreen class', ->
# expect(@player.el).not.toHaveClass 'fullscreen'
# it 'tell VideoCaption to resize', ->
# expect(@player.caption.resize).toHaveBeenCalled() it 'tell VideoCaption to resize', ->
# expect(@player.caption.resize).toHaveBeenCalled()
# describe 'play', ->
# beforeEach -> describe 'play', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player = new VideoPlayer video: @video
# describe 'when the player is not ready', ->
# beforeEach -> describe 'when the player is not ready', ->
# @player.player.playVideo = undefined beforeEach ->
# @player.play() @player.player.playVideo = undefined
# @player.play()
# it 'does nothing', ->
# expect(@player.player.playVideo).toBeUndefined() it 'does nothing', ->
# expect(@player.player.playVideo).toBeUndefined()
# describe 'when the player is ready', ->
# beforeEach -> describe 'when the player is ready', ->
# @player.player.playVideo.andReturn true beforeEach ->
# @player.play() @player.player.playVideo.andReturn true
# @player.play()
# it 'delegate to the Youtube player', ->
# expect(@player.player.playVideo).toHaveBeenCalled() it 'delegate to the Youtube player', ->
# expect(@player.player.playVideo).toHaveBeenCalled()
# describe 'isPlaying', ->
# beforeEach -> describe 'isPlaying', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player = new VideoPlayer video: @video
# describe 'when the video is playing', ->
# beforeEach -> describe 'when the video is playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING beforeEach ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PLAYING
# it 'return true', ->
# expect(@player.isPlaying()).toBeTruthy() it 'return true', ->
# expect(@player.isPlaying()).toBeTruthy()
# describe 'when the video is not playing', ->
# beforeEach -> describe 'when the video is not playing', ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED beforeEach ->
# @player.player.getPlayerState.andReturn YT.PlayerState.PAUSED
# it 'return false', ->
# expect(@player.isPlaying()).toBeFalsy() it 'return false', ->
# expect(@player.isPlaying()).toBeFalsy()
# describe 'pause', ->
# beforeEach -> describe 'pause', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @player.pause() @player = new VideoPlayer video: @video
# @player.pause()
# it 'delegate to the Youtube player', ->
# expect(@player.player.pauseVideo).toHaveBeenCalled() it 'delegate to the Youtube player', ->
# expect(@player.player.pauseVideo).toHaveBeenCalled()
# describe 'duration', ->
# beforeEach -> describe 'duration', ->
# @player = new VideoPlayer video: @video beforeEach ->
# spyOn @video, 'getDuration' @player = new VideoPlayer video: @video
# @player.duration() spyOn @video, 'getDuration'
# @player.duration()
# it 'delegate to the video', ->
# expect(@video.getDuration).toHaveBeenCalled() it 'delegate to the video', ->
# expect(@video.getDuration).toHaveBeenCalled()
# describe 'currentSpeed', ->
# beforeEach -> describe 'currentSpeed', ->
# @player = new VideoPlayer video: @video beforeEach ->
# @video.speed = '3.0' @player = new VideoPlayer video: @video
# @video.speed = '3.0'
# it 'delegate to the video', ->
# expect(@player.currentSpeed()).toEqual '3.0' it 'delegate to the video', ->
# expect(@player.currentSpeed()).toEqual '3.0'
# describe 'volume', ->
# beforeEach -> describe 'volume', ->
# @player = new VideoPlayer @video beforeEach ->
# @player.player.getVolume.andReturn 42 @player = new VideoPlayer @video
# @player.player.getVolume.andReturn 42
# describe 'without value', ->
# it 'return current volume', -> describe 'without value', ->
# expect(@player.volume()).toEqual 42 it 'return current volume', ->
# expect(@player.volume()).toEqual 42
# describe 'with value', ->
# it 'set player volume', -> describe 'with value', ->
# @player.volume(60) it 'set player volume', ->
# expect(@player.player.setVolume).toHaveBeenCalledWith(60) @player.volume(60)
expect(@player.player.setVolume).toHaveBeenCalledWith(60)
#describe 'VideoProgressSlider', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoProgressSlider', ->
# jasmine.stubVideoPlayer @ beforeEach ->
# jasmine.stubVideoPlayer @
# describe 'constructor', ->
# describe 'on a non-touch based device', -> describe 'constructor', ->
# beforeEach -> describe 'on a non-touch based device', ->
# spyOn($.fn, 'slider').andCallThrough() beforeEach ->
# spyOn(window, 'onTouchBasedDevice').andReturn false spyOn($.fn, 'slider').andCallThrough()
# @slider = new VideoProgressSlider el: $('.slider') spyOn(window, 'onTouchBasedDevice').andReturn false
# @slider = new VideoProgressSlider el: $('.slider')
# it 'build the slider', ->
# expect(@slider.slider).toBe '.slider' it 'build the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith expect(@slider.slider).toBe '.slider'
# range: 'min' expect($.fn.slider).toHaveBeenCalledWith
# change: @slider.onChange range: 'min'
# slide: @slider.onSlide change: @slider.onChange
# stop: @slider.onStop slide: @slider.onSlide
# stop: @slider.onStop
# it 'build the seek handle', ->
# expect(@slider.handle).toBe '.slider .ui-slider-handle' it 'build the seek handle', ->
# expect($.fn.qtip).toHaveBeenCalledWith expect(@slider.handle).toBe '.slider .ui-slider-handle'
# content: "0:00" expect($.fn.qtip).toHaveBeenCalledWith
# position: content: "0:00"
# my: 'bottom center' position:
# at: 'top center' my: 'bottom center'
# container: @slider.handle at: 'top center'
# hide: container: @slider.handle
# delay: 700 hide:
# style: delay: 700
# classes: 'ui-tooltip-slider' style:
# widget: true classes: 'ui-tooltip-slider'
# widget: true
# describe 'on a touch-based device', ->
# beforeEach -> describe 'on a touch-based device', ->
# spyOn($.fn, 'slider').andCallThrough() beforeEach ->
# spyOn(window, 'onTouchBasedDevice').andReturn true spyOn($.fn, 'slider').andCallThrough()
# @slider = new VideoProgressSlider el: $('.slider') spyOn(window, 'onTouchBasedDevice').andReturn true
# @slider = new VideoProgressSlider el: $('.slider')
# it 'does not build the slider', ->
# expect(@slider.slider).toBeUndefined it 'does not build the slider', ->
# expect($.fn.slider).not.toHaveBeenCalled() expect(@slider.slider).toBeUndefined
# expect($.fn.slider).not.toHaveBeenCalled()
# describe 'play', ->
# beforeEach -> describe 'play', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# spyOn($.fn, 'slider').andCallThrough() @slider = new VideoProgressSlider el: $('.slider')
# spyOn($.fn, 'slider').andCallThrough()
# describe 'when the slider was already built', ->
# beforeEach -> describe 'when the slider was already built', ->
# @slider.play() beforeEach ->
# @slider.play()
# it 'does not build the slider', ->
# expect($.fn.slider).not.toHaveBeenCalled it 'does not build the slider', ->
# expect($.fn.slider).not.toHaveBeenCalled
# describe 'when the slider was not already built', ->
# beforeEach -> describe 'when the slider was not already built', ->
# @slider.slider = null beforeEach ->
# @slider.play() @slider.slider = null
# @slider.play()
# it 'build the slider', ->
# expect(@slider.slider).toBe '.slider' it 'build the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith expect(@slider.slider).toBe '.slider'
# range: 'min' expect($.fn.slider).toHaveBeenCalledWith
# change: @slider.onChange range: 'min'
# slide: @slider.onSlide change: @slider.onChange
# stop: @slider.onStop slide: @slider.onSlide
# stop: @slider.onStop
# it 'build the seek handle', ->
# expect(@slider.handle).toBe '.ui-slider-handle' it 'build the seek handle', ->
# expect($.fn.qtip).toHaveBeenCalledWith expect(@slider.handle).toBe '.ui-slider-handle'
# content: "0:00" expect($.fn.qtip).toHaveBeenCalledWith
# position: content: "0:00"
# my: 'bottom center' position:
# at: 'top center' my: 'bottom center'
# container: @slider.handle at: 'top center'
# hide: container: @slider.handle
# delay: 700 hide:
# style: delay: 700
# classes: 'ui-tooltip-slider' style:
# widget: true classes: 'ui-tooltip-slider'
# widget: true
# describe 'updatePlayTime', ->
# beforeEach -> describe 'updatePlayTime', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# spyOn($.fn, 'slider').andCallThrough() @slider = new VideoProgressSlider el: $('.slider')
# spyOn($.fn, 'slider').andCallThrough()
# describe 'when frozen', ->
# beforeEach -> describe 'when frozen', ->
# @slider.frozen = true beforeEach ->
# @slider.updatePlayTime 20, 120 @slider.frozen = true
# @slider.updatePlayTime 20, 120
# it 'does not update the slider', ->
# expect($.fn.slider).not.toHaveBeenCalled() it 'does not update the slider', ->
# expect($.fn.slider).not.toHaveBeenCalled()
# describe 'when not frozen', ->
# beforeEach -> describe 'when not frozen', ->
# @slider.frozen = false beforeEach ->
# @slider.updatePlayTime 20, 120 @slider.frozen = false
# @slider.updatePlayTime 20, 120
# it 'update the max value of the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith 'option', 'max', 120 it 'update the max value of the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith 'option', 'max', 120
# it 'update current value of the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith 'value', 20 it 'update current value of the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith 'value', 20
# describe 'onSlide', ->
# beforeEach -> describe 'onSlide', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# @time = null @slider = new VideoProgressSlider el: $('.slider')
# $(@slider).bind 'seek', (event, time) => @time = time @time = null
# spyOnEvent @slider, 'seek' $(@slider).bind 'seek', (event, time) => @time = time
# @slider.onSlide {}, value: 20 spyOnEvent @slider, 'seek'
# @slider.onSlide {}, value: 20
# it 'freeze the slider', ->
# expect(@slider.frozen).toBeTruthy() it 'freeze the slider', ->
# expect(@slider.frozen).toBeTruthy()
# it 'update the tooltip', ->
# expect($.fn.qtip).toHaveBeenCalled() it 'update the tooltip', ->
# expect($.fn.qtip).toHaveBeenCalled()
# it 'trigger seek event', ->
# expect('seek').toHaveBeenTriggeredOn @slider it 'trigger seek event', ->
# expect(@time).toEqual 20 expect('seek').toHaveBeenTriggeredOn @slider
# expect(@time).toEqual 20
# describe 'onChange', ->
# beforeEach -> describe 'onChange', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# @slider.onChange {}, value: 20 @slider = new VideoProgressSlider el: $('.slider')
# @slider.onChange {}, value: 20
# it 'update the tooltip', ->
# expect($.fn.qtip).toHaveBeenCalled() it 'update the tooltip', ->
# expect($.fn.qtip).toHaveBeenCalled()
# describe 'onStop', ->
# beforeEach -> describe 'onStop', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# @time = null @slider = new VideoProgressSlider el: $('.slider')
# $(@slider).bind 'seek', (event, time) => @time = time @time = null
# spyOnEvent @slider, 'seek' $(@slider).bind 'seek', (event, time) => @time = time
# spyOn(window, 'setTimeout') spyOnEvent @slider, 'seek'
# @slider.onStop {}, value: 20 spyOn(window, 'setTimeout')
# @slider.onStop {}, value: 20
# it 'freeze the slider', ->
# expect(@slider.frozen).toBeTruthy() it 'freeze the slider', ->
# expect(@slider.frozen).toBeTruthy()
# it 'trigger seek event', ->
# expect('seek').toHaveBeenTriggeredOn @slider it 'trigger seek event', ->
# expect(@time).toEqual 20 expect('seek').toHaveBeenTriggeredOn @slider
# expect(@time).toEqual 20
# it 'set timeout to unfreeze the slider', ->
# expect(window.setTimeout).toHaveBeenCalledWith jasmine.any(Function), 200 it 'set timeout to unfreeze the slider', ->
# window.setTimeout.mostRecentCall.args[0]() expect(window.setTimeout).toHaveBeenCalledWith jasmine.any(Function), 200
# expect(@slider.frozen).toBeFalsy() window.setTimeout.mostRecentCall.args[0]()
# expect(@slider.frozen).toBeFalsy()
# describe 'updateTooltip', ->
# beforeEach -> describe 'updateTooltip', ->
# @slider = new VideoProgressSlider el: $('.slider') beforeEach ->
# @slider.updateTooltip 90 @slider = new VideoProgressSlider el: $('.slider')
# @slider.updateTooltip 90
# it 'set the tooltip value', ->
# expect($.fn.qtip).toHaveBeenCalledWith 'option', 'content.text', '1:30' it 'set the tooltip value', ->
expect($.fn.qtip).toHaveBeenCalledWith 'option', 'content.text', '1:30'
#describe 'VideoSpeedControl', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoSpeedControl', ->
# jasmine.stubVideoPlayer @ beforeEach ->
# $('.speeds').remove() jasmine.stubVideoPlayer @
# $('.speeds').remove()
# describe 'constructor', ->
# describe 'always', -> describe 'constructor', ->
# beforeEach -> describe 'always', ->
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0' beforeEach ->
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
# it 'add the video speed control to player', ->
# expect($('.secondary-controls').html()).toContain ''' it 'add the video speed control to player', ->
# <div class="speeds"> expect($('.secondary-controls').html()).toContain '''
# <a href="#"> <div class="speeds">
# <h3>Speed</h3> <a href="#">
# <p class="active">1.0x</p> <h3>Speed</h3>
# </a> <p class="active">1.0x</p>
# <ol class="video_speeds"><li data-speed="1.0" class="active"><a href="#">1.0x</a></li><li data-speed="0.75"><a href="#">0.75x</a></li></ol> </a>
# </div> <ol class="video_speeds"><li data-speed="1.0" class="active"><a href="#">1.0x</a></li><li data-speed="0.75"><a href="#">0.75x</a></li></ol>
# ''' </div>
# '''
# it 'bind to change video speed link', ->
# expect($('.video_speeds a')).toHandleWith 'click', @speedControl.changeVideoSpeed it 'bind to change video speed link', ->
# expect($('.video_speeds a')).toHandleWith 'click', @speedControl.changeVideoSpeed
# describe 'when running on touch based device', ->
# beforeEach -> describe 'when running on touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn true beforeEach ->
# $('.speeds').removeClass 'open' spyOn(window, 'onTouchBasedDevice').andReturn true
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0' $('.speeds').removeClass 'open'
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
# it 'open the speed toggle on click', ->
# $('.speeds').click() it 'open the speed toggle on click', ->
# expect($('.speeds')).toHaveClass 'open' $('.speeds').click()
# $('.speeds').click() expect($('.speeds')).toHaveClass 'open'
# expect($('.speeds')).not.toHaveClass 'open' $('.speeds').click()
# expect($('.speeds')).not.toHaveClass 'open'
# describe 'when running on non-touch based device', ->
# beforeEach -> describe 'when running on non-touch based device', ->
# spyOn(window, 'onTouchBasedDevice').andReturn false beforeEach ->
# $('.speeds').removeClass 'open' spyOn(window, 'onTouchBasedDevice').andReturn false
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0' $('.speeds').removeClass 'open'
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
# it 'open the speed toggle on hover', ->
# $('.speeds').mouseenter() it 'open the speed toggle on hover', ->
# expect($('.speeds')).toHaveClass 'open' $('.speeds').mouseenter()
# $('.speeds').mouseleave() expect($('.speeds')).toHaveClass 'open'
# expect($('.speeds')).not.toHaveClass 'open' $('.speeds').mouseleave()
# expect($('.speeds')).not.toHaveClass 'open'
# it 'close the speed toggle on mouse out', ->
# $('.speeds').mouseenter().mouseleave() it 'close the speed toggle on mouse out', ->
# expect($('.speeds')).not.toHaveClass 'open' $('.speeds').mouseenter().mouseleave()
# expect($('.speeds')).not.toHaveClass 'open'
# it 'close the speed toggle on click', ->
# $('.speeds').mouseenter().click() it 'close the speed toggle on click', ->
# expect($('.speeds')).not.toHaveClass 'open' $('.speeds').mouseenter().click()
# expect($('.speeds')).not.toHaveClass 'open'
# describe 'changeVideoSpeed', ->
# beforeEach -> describe 'changeVideoSpeed', ->
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0' beforeEach ->
# @video.setSpeed '1.0' @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
# @video.setSpeed '1.0'
# describe 'when new speed is the same', ->
# beforeEach -> describe 'when new speed is the same', ->
# spyOnEvent @speedControl, 'speedChange' beforeEach ->
# $('li[data-speed="1.0"] a').click() spyOnEvent @speedControl, 'speedChange'
# $('li[data-speed="1.0"] a').click()
# it 'does not trigger speedChange event', ->
# expect('speedChange').not.toHaveBeenTriggeredOn @speedControl it 'does not trigger speedChange event', ->
# expect('speedChange').not.toHaveBeenTriggeredOn @speedControl
# describe 'when new speed is not the same', ->
# beforeEach -> describe 'when new speed is not the same', ->
# @newSpeed = null beforeEach ->
# $(@speedControl).bind 'speedChange', (event, newSpeed) => @newSpeed = newSpeed @newSpeed = null
# spyOnEvent @speedControl, 'speedChange' $(@speedControl).bind 'speedChange', (event, newSpeed) => @newSpeed = newSpeed
# $('li[data-speed="0.75"] a').click() spyOnEvent @speedControl, 'speedChange'
# $('li[data-speed="0.75"] a').click()
# it 'trigger speedChange event', ->
# expect('speedChange').toHaveBeenTriggeredOn @speedControl it 'trigger speedChange event', ->
# expect(@newSpeed).toEqual 0.75 expect('speedChange').toHaveBeenTriggeredOn @speedControl
# expect(@newSpeed).toEqual 0.75
# describe 'onSpeedChange', ->
# beforeEach -> describe 'onSpeedChange', ->
# @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0' beforeEach ->
# $('li[data-speed="1.0"] a').addClass 'active' @speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
# @speedControl.setSpeed '0.75' $('li[data-speed="1.0"] a').addClass 'active'
# @speedControl.setSpeed '0.75'
# it 'set the new speed as active', ->
# expect($('.video_speeds li[data-speed="1.0"]')).not.toHaveClass 'active' it 'set the new speed as active', ->
# expect($('.video_speeds li[data-speed="0.75"]')).toHaveClass 'active' expect($('.video_speeds li[data-speed="1.0"]')).not.toHaveClass 'active'
# expect($('.speeds p.active')).toHaveHtml '0.75x' expect($('.video_speeds li[data-speed="0.75"]')).toHaveClass 'active'
expect($('.speeds p.active')).toHaveHtml '0.75x'
#describe 'VideoVolumeControl', -> # TODO: figure out why failing
# beforeEach -> xdescribe 'VideoVolumeControl', ->
# jasmine.stubVideoPlayer @ beforeEach ->
# $('.volume').remove() jasmine.stubVideoPlayer @
# $('.volume').remove()
# describe 'constructor', ->
# beforeEach -> describe 'constructor', ->
# spyOn($.fn, 'slider') beforeEach ->
# @volumeControl = new VideoVolumeControl el: $('.secondary-controls') spyOn($.fn, 'slider')
# @volumeControl = new VideoVolumeControl el: $('.secondary-controls')
# it 'initialize currentVolume to 100', ->
# expect(@volumeControl.currentVolume).toEqual 100 it 'initialize currentVolume to 100', ->
# expect(@volumeControl.currentVolume).toEqual 100
# it 'render the volume control', ->
# expect($('.secondary-controls').html()).toContain """ it 'render the volume control', ->
# <div class="volume"> expect($('.secondary-controls').html()).toContain """
# <a href="#"></a> <div class="volume">
# <div class="volume-slider-container"> <a href="#"></a>
# <div class="volume-slider"></div> <div class="volume-slider-container">
# </div> <div class="volume-slider"></div>
# </div> </div>
# """ </div>
# """
# it 'create the slider', ->
# expect($.fn.slider).toHaveBeenCalledWith it 'create the slider', ->
# orientation: "vertical" expect($.fn.slider).toHaveBeenCalledWith
# range: "min" orientation: "vertical"
# min: 0 range: "min"
# max: 100 min: 0
# value: 100 max: 100
# change: @volumeControl.onChange value: 100
# slide: @volumeControl.onChange change: @volumeControl.onChange
# slide: @volumeControl.onChange
# it 'bind the volume control', ->
# expect($('.volume>a')).toHandleWith 'click', @volumeControl.toggleMute it 'bind the volume control', ->
# expect($('.volume>a')).toHandleWith 'click', @volumeControl.toggleMute
# expect($('.volume')).not.toHaveClass 'open'
# $('.volume').mouseenter() expect($('.volume')).not.toHaveClass 'open'
# expect($('.volume')).toHaveClass 'open' $('.volume').mouseenter()
# $('.volume').mouseleave() expect($('.volume')).toHaveClass 'open'
# expect($('.volume')).not.toHaveClass 'open' $('.volume').mouseleave()
# expect($('.volume')).not.toHaveClass 'open'
# describe 'onChange', ->
# beforeEach -> describe 'onChange', ->
# spyOnEvent @volumeControl, 'volumeChange' beforeEach ->
# @newVolume = undefined spyOnEvent @volumeControl, 'volumeChange'
# @volumeControl = new VideoVolumeControl el: $('.secondary-controls') @newVolume = undefined
# $(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume @volumeControl = new VideoVolumeControl el: $('.secondary-controls')
# $(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume
# describe 'when the new volume is more than 0', ->
# beforeEach -> describe 'when the new volume is more than 0', ->
# @volumeControl.onChange undefined, value: 60 beforeEach ->
# @volumeControl.onChange undefined, value: 60
# it 'set the player volume', ->
# expect(@newVolume).toEqual 60 it 'set the player volume', ->
# expect(@newVolume).toEqual 60
# it 'remote muted class', ->
# expect($('.volume')).not.toHaveClass 'muted' it 'remote muted class', ->
# expect($('.volume')).not.toHaveClass 'muted'
# describe 'when the new volume is 0', ->
# beforeEach -> describe 'when the new volume is 0', ->
# @volumeControl.onChange undefined, value: 0 beforeEach ->
# @volumeControl.onChange undefined, value: 0
# it 'set the player volume', ->
# expect(@newVolume).toEqual 0 it 'set the player volume', ->
# expect(@newVolume).toEqual 0
# it 'add muted class', ->
# expect($('.volume')).toHaveClass 'muted' it 'add muted class', ->
# expect($('.volume')).toHaveClass 'muted'
# describe 'toggleMute', ->
# beforeEach -> describe 'toggleMute', ->
# @newVolume = undefined beforeEach ->
# @volumeControl = new VideoVolumeControl el: $('.secondary-controls') @newVolume = undefined
# $(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume @volumeControl = new VideoVolumeControl el: $('.secondary-controls')
# $(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume
# describe 'when the current volume is more than 0', ->
# beforeEach -> describe 'when the current volume is more than 0', ->
# @volumeControl.currentVolume = 60 beforeEach ->
# @volumeControl.toggleMute() @volumeControl.currentVolume = 60
# @volumeControl.toggleMute()
# it 'save the previous volume', ->
# expect(@volumeControl.previousVolume).toEqual 60 it 'save the previous volume', ->
# expect(@volumeControl.previousVolume).toEqual 60
# it 'set the player volume', ->
# expect(@newVolume).toEqual 0 it 'set the player volume', ->
# expect(@newVolume).toEqual 0
# describe 'when the current volume is 0', ->
# beforeEach -> describe 'when the current volume is 0', ->
# @volumeControl.currentVolume = 0 beforeEach ->
# @volumeControl.previousVolume = 60 @volumeControl.currentVolume = 0
# @volumeControl.toggleMute() @volumeControl.previousVolume = 60
# @volumeControl.toggleMute()
# it 'set the player volume to previous volume', ->
# expect(@newVolume).toEqual 60 it 'set the player volume to previous volume', ->
expect(@newVolume).toEqual 60
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