Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions common/lib/xmodule/xmodule/js/fixtures/video.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<div class="course-content">
<div id="video_example" class="video">
<div class="tc-wrapper">
<article class="video-wrapper">
<section class="video-player">
<div id="example"></div>
</section>
<section class="video-controls"></section>
</article>
<div id="video_example">
<div id="example">
<div id="video_id" class="video"
data-streams="0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId"
data-show-captions="true"
data-start=""
data-end=""
data-caption-asset-path="/static/subs/">
<div class="tc-wrapper">
<article class="video-wrapper">
<section class="video-player">
<div id="id"></div>
</section>
<section class="video-controls"></section>
</article>
</div>
</div>
</div>
</div>
</div>
</div>
10 changes: 3 additions & 7 deletions common/lib/xmodule/xmodule/js/spec/helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jasmine.stubRequests = ->
spyOn($, 'ajax').andCallFake (settings) ->
if match = settings.url.match /youtube\.com\/.+\/videos\/(.+)\?v=2&alt=jsonc/
settings.success data: jasmine.stubbedMetadata[match[1]]
else if match = settings.url.match /static\/subs\/(.+)\.srt\.sjson/
else if match = settings.url.match /static(\/.*)?\/subs\/(.+)\.srt\.sjson/
settings.success jasmine.stubbedCaption
else if settings.url.match /.+\/problem_get$/
settings.success html: readFixtures('problem_content.html')
Expand All @@ -47,19 +47,15 @@ jasmine.stubYoutubePlayer = ->

jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) ->
enableParts = [enableParts] unless $.isArray(enableParts)

suite = context.suite
currentPartName = suite.description while suite = suite.parentSuite
enableParts.push currentPartName

for part in ['VideoCaption', 'VideoSpeedControl', 'VideoVolumeControl', 'VideoProgressSlider']
unless $.inArray(part, enableParts) >= 0
spyOn window, part

loadFixtures 'video.html'
jasmine.stubRequests()
YT.Player = undefined
context.video = new Video 'example', '.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId'
videosDefinition = '0.75:slowerSpeedYoutubeId,1.0:normalSpeedYoutubeId'
context.video = new Video '#example', videosDefinition
jasmine.stubYoutubePlayer()
if createPlayer
return new VideoPlayer(video: context.video)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# TODO: figure out why failing
xdescribe 'VideoCaption', ->
describe 'VideoCaption', ->

beforeEach ->
jasmine.stubVideoPlayer @
$('.subtitles').remove()
spyOn(VideoCaption.prototype, 'fetchCaption').andCallThrough()
spyOn($, 'ajaxWithPrefix').andCallThrough()
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false

afterEach ->
YT.Player = undefined
$.fn.scrollTo.reset()
$('.subtitles').remove()

describe 'constructor', ->
beforeEach ->
spyOn($, 'getWithPrefix').andCallThrough()

describe 'always', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

it 'set the youtube id', ->
expect(@caption.youtubeId).toEqual 'def456'
expect(@caption.youtubeId).toEqual 'normalSpeedYoutubeId'

it 'create the caption element', ->
expect($('.video')).toContain 'ol.subtitles'
Expand All @@ -26,7 +28,12 @@ xdescribe 'VideoCaption', ->
expect($('.video')).toContain 'a.hide-subtitles'

it 'fetch the caption', ->
expect($.getWithPrefix).toHaveBeenCalledWith @caption.captionURL(), jasmine.any(Function)
expect(@caption.loaded).toBeTruthy()
expect(@caption.fetchCaption).toHaveBeenCalled()
expect($.ajaxWithPrefix).toHaveBeenCalledWith
url: @caption.captionURL()
notifyOnError: false
success: jasmine.any(Function)

it 'bind window resize event', ->
expect($(window)).toHandleWith 'resize', @caption.resize
Expand All @@ -42,17 +49,17 @@ xdescribe 'VideoCaption', ->
expect($('.subtitles')).toHandleWith 'DOMMouseScroll', @caption.onMovement

describe 'when on a non touch-based device', ->

beforeEach ->
spyOn(window, 'onTouchBasedDevice').andReturn false
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

it 'render the caption', ->
expect($('.subtitles').html()).toMatch new RegExp('''
<li data-index="0" data-start="0">Caption at 0</li>
<li data-index="1" data-start="10000">Caption at 10000</li>
<li data-index="2" data-start="20000">Caption at 20000</li>
<li data-index="3" data-start="30000">Caption at 30000</li>
'''.replace(/\n/g, ''))
captionsData = jasmine.stubbedCaption
$('.subtitles li[data-index]').each (index, link) =>
expect($(link)).toHaveData 'index', index
expect($(link)).toHaveData 'start', captionsData.start[index]
expect($(link)).toHaveText captionsData.text[index]

it 'add a padding element to caption', ->
expect($('.subtitles li:first')).toBe '.spacing'
Expand All @@ -66,9 +73,11 @@ xdescribe 'VideoCaption', ->
expect(@caption.rendered).toBeTruthy()

describe 'when on a touch-based device', ->

beforeEach ->
spyOn(window, 'onTouchBasedDevice').andReturn true
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
window.onTouchBasedDevice.andReturn true
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

it 'show explaination message', ->
expect($('.subtitles li')).toHaveHtml "Caption will be displayed when you start playing the video."
Expand All @@ -77,19 +86,23 @@ xdescribe 'VideoCaption', ->
expect(@caption.rendered).toBeFalsy()

describe 'mouse movement', ->

beforeEach ->
spyOn(window, 'setTimeout').andReturn 100
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
window.setTimeout.andReturn(100)
spyOn window, 'clearTimeout'
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'

describe 'when cursor is outside of the caption box', ->

beforeEach ->
$(window).trigger jQuery.Event 'mousemove'

it 'does not set freezing timeout', ->
expect(@caption.frozen).toBeFalsy()

describe 'when cursor is in the caption box', ->

beforeEach ->
$('.subtitles').trigger jQuery.Event 'mouseenter'

Expand Down Expand Up @@ -143,8 +156,10 @@ xdescribe 'VideoCaption', ->
expect($.fn.scrollTo).not.toHaveBeenCalled()

describe 'search', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

it 'return a correct caption index', ->
expect(@caption.search(0)).toEqual 0
Expand All @@ -157,17 +172,17 @@ xdescribe 'VideoCaption', ->
describe 'play', ->
describe 'when the caption was not rendered', ->
beforeEach ->
spyOn(window, 'onTouchBasedDevice').andReturn true
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
window.onTouchBasedDevice.andReturn true
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
@caption.play()

it 'render the caption', ->
expect($('.subtitles').html()).toMatch new RegExp(
'''<li data-index="0" data-start="0">Caption at 0</li>''' +
'''<li data-index="1" data-start="10000">Caption at 10000</li>''' +
'''<li data-index="2" data-start="20000">Caption at 20000</li>''' +
'''<li data-index="3" data-start="30000">Caption at 30000</li>'''
)
captionsData = jasmine.stubbedCaption
$('.subtitles li[data-index]').each (index, link) =>
expect($(link)).toHaveData 'index', index
expect($(link)).toHaveData 'start', captionsData.start[index]
expect($(link)).toHaveText captionsData.text[index]

it 'add a padding element to caption', ->
expect($('.subtitles li:first')).toBe '.spacing'
Expand All @@ -185,16 +200,19 @@ xdescribe 'VideoCaption', ->

describe 'pause', ->
beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
@caption.playing = true
@caption.pause()

it 'set playing to false', ->
expect(@caption.playing).toBeFalsy()

describe 'updatePlayTime', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

describe 'when the video speed is 1.0x', ->
beforeEach ->
Expand Down Expand Up @@ -240,26 +258,29 @@ xdescribe 'VideoCaption', ->
expect($('.subtitles li[data-index=1]')).toHaveClass 'current'

describe 'resize', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
$('.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()
expect(parseInt($('.subtitles').css('maxHeight'))).toBeCloseTo $('.video-wrapper').height(), 2

it 'set the height of caption spacing', ->
expect(parseInt($('.subtitles .spacing:first').css('height'))).toEqual(
$('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):first').height() / 2)
expect(parseInt($('.subtitles .spacing:last').css('height'))).toEqual(
$('.video-wrapper').height() / 2 - $('.subtitles li:not(.spacing):last').height() / 2)
expect(Math.abs(parseInt($('.subtitles .spacing:first').css('height')) - @caption.topSpacingHeight())).toBeLessThan 1
expect(Math.abs(parseInt($('.subtitles .spacing:last').css('height')) - @caption.bottomSpacingHeight())).toBeLessThan 1


it 'scroll caption to new position', ->
expect($.fn.scrollTo).toHaveBeenCalled()

describe 'scrollCaption', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption

describe 'when frozen', ->
beforeEach ->
Expand Down Expand Up @@ -291,30 +312,33 @@ xdescribe 'VideoCaption', ->
offset: - ($('.video-wrapper').height() / 2 - $('.subtitles .current:first').height() / 2)

describe 'seekPlayer', ->

beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
@time = null
$(@caption).bind 'seek', (event, time) => @time = time

describe 'when the video speed is 1.0x', ->
beforeEach ->
@caption.currentSpeed = '1.0'
$('.subtitles li[data-start="30000"]').click()
$('.subtitles li[data-start="30000"]').trigger('click')

it 'trigger seek event with the correct time', ->
expect(@time).toEqual 30.000

describe 'when the video speed is not 1.0x', ->
beforeEach ->
@caption.currentSpeed = '0.75'
$('.subtitles li[data-start="30000"]').click()
$('.subtitles li[data-start="30000"]').trigger('click')

it 'trigger seek event with the correct time', ->
expect(@time).toEqual 40.000

describe 'toggle', ->
beforeEach ->
@caption = new VideoCaption el: $('.video'), youtubeId: 'def456', currentSpeed: '1.0'
@player = jasmine.stubVideoPlayer @
@caption = @player.caption
$('.subtitles li[data-index=1]').addClass 'current'

describe 'when the caption is visible', ->
Expand All @@ -325,7 +349,6 @@ xdescribe 'VideoCaption', ->
it 'hide the caption', ->
expect(@caption.el).toHaveClass 'closed'


describe 'when the caption is hidden', ->
beforeEach ->
@caption.el.addClass 'closed'
Expand Down
Loading