Commit 9f871e53 by Valera Rozuvan

Updated code fomat in test Jasmine.

parent 6713d6c7
(function() { (function () {
describe('VideoCaption', function() { describe('VideoCaption', function () {
var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD; var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD;
function initialize() { function initialize() {
...@@ -11,36 +11,37 @@ ...@@ -11,36 +11,37 @@
videoControl = state.videoControl; videoControl = state.videoControl;
} }
beforeEach(function() { beforeEach(function () {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
.andReturn(false);
initialize(); initialize();
}); });
afterEach(function() { afterEach(function () {
YT.Player = void 0; YT.Player = undefined;
$.fn.scrollTo.reset(); $.fn.scrollTo.reset();
$('.subtitles').remove(); $('.subtitles').remove();
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function() { describe('constructor', function () {
describe('always', function() { describe('always', function () {
beforeEach(function() { beforeEach(function () {
spyOn($, 'ajaxWithPrefix').andCallThrough(); spyOn($, 'ajaxWithPrefix').andCallThrough();
initialize(); initialize();
}); });
it('create the caption element', function() { it('create the caption element', function () {
expect($('.video')).toContain('ol.subtitles'); expect($('.video')).toContain('ol.subtitles');
}); });
it('add caption control to video player', function() { it('add caption control to video player', function () {
expect($('.video')).toContain('a.hide-subtitles'); expect($('.video')).toContain('a.hide-subtitles');
}); });
it('fetch the caption', function() { it('fetch the caption', function () {
waitsFor(function () { waitsFor(function () {
if (videoCaption.loaded === true) { if (videoCaption.loaded === true) {
return true; return true;
...@@ -54,83 +55,124 @@ ...@@ -54,83 +55,124 @@
url: videoCaption.captionURL(), url: videoCaption.captionURL(),
notifyOnError: false, notifyOnError: false,
success: jasmine.any(Function), success: jasmine.any(Function),
error: jasmine.any(Function), error: jasmine.any(Function)
}); });
}); });
}); });
it('bind window resize event', function() { it('bind window resize event', function () {
expect($(window)).toHandleWith('resize', videoCaption.resize); expect($(window)).toHandleWith(
'resize', videoCaption.resize
);
}); });
it('bind the hide caption button', function() { it('bind the hide caption button', function () {
expect($('.hide-subtitles')).toHandleWith('click', videoCaption.toggle); expect($('.hide-subtitles')).toHandleWith(
'click', videoCaption.toggle
);
}); });
it('bind the mouse movement', function() { it('bind the mouse movement', function () {
expect($('.subtitles')).toHandleWith('mouseover', videoCaption.onMouseEnter); expect($('.subtitles')).toHandleWith(
expect($('.subtitles')).toHandleWith('mouseout', videoCaption.onMouseLeave); 'mouseover', videoCaption.onMouseEnter
expect($('.subtitles')).toHandleWith('mousemove', videoCaption.onMovement); );
expect($('.subtitles')).toHandleWith('mousewheel', videoCaption.onMovement); expect($('.subtitles')).toHandleWith(
expect($('.subtitles')).toHandleWith('DOMMouseScroll', videoCaption.onMovement); 'mouseout', videoCaption.onMouseLeave
);
expect($('.subtitles')).toHandleWith(
'mousemove', videoCaption.onMovement
);
expect($('.subtitles')).toHandleWith(
'mousewheel', videoCaption.onMovement
);
expect($('.subtitles')).toHandleWith(
'DOMMouseScroll', videoCaption.onMovement
);
}); });
it('bind the scroll', function() { it('bind the scroll', function () {
expect($('.subtitles')).toHandleWith('scroll', videoCaption.autoShowCaptions); expect($('.subtitles'))
expect($('.subtitles')).toHandleWith('scroll', videoControl.showControls); .toHandleWith('scroll', videoCaption.autoShowCaptions);
expect($('.subtitles'))
.toHandleWith('scroll', videoControl.showControls);
}); });
}); });
describe('when on a non touch-based device', function() { describe('when on a non touch-based device', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
}); });
it('render the caption', function() { it('render the caption', function () {
var captionsData; var captionsData;
captionsData = jasmine.stubbedCaption; captionsData = jasmine.stubbedCaption;
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(
function (index, link) {
expect($(link)).toHaveData('index', index); expect($(link)).toHaveData('index', index);
expect($(link)).toHaveData('start', captionsData.start[index]); expect($(link)).toHaveData(
'start', captionsData.start[index]
);
expect($(link)).toHaveAttr('tabindex', 0); expect($(link)).toHaveAttr('tabindex', 0);
expect($(link)).toHaveText(captionsData.text[index]); expect($(link)).toHaveText(captionsData.text[index]);
}); });
}); });
it('add a padding element to caption', function() { it('add a padding element to caption', function () {
expect($('.subtitles li:first').hasClass('spacing')).toBe(true); expect($('.subtitles li:first').hasClass('spacing'))
expect($('.subtitles li:last').hasClass('spacing')).toBe(true); .toBe(true);
expect($('.subtitles li:last').hasClass('spacing'))
.toBe(true);
}); });
it('bind all the caption link', function() { it('bind all the caption link', function () {
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(
expect($(link)).toHandleWith('mouseover', videoCaption.captionMouseOverOut); function (index, link) {
expect($(link)).toHandleWith('mouseout', videoCaption.captionMouseOverOut);
expect($(link)).toHandleWith('mousedown', videoCaption.captionMouseDown); expect($(link)).toHandleWith(
expect($(link)).toHandleWith('click', videoCaption.captionClick); 'mouseover', videoCaption.captionMouseOverOut
expect($(link)).toHandleWith('focus', videoCaption.captionFocus); );
expect($(link)).toHandleWith('blur', videoCaption.captionBlur); expect($(link)).toHandleWith(
expect($(link)).toHandleWith('keydown', videoCaption.captionKeyDown); 'mouseout', videoCaption.captionMouseOverOut
);
expect($(link)).toHandleWith(
'mousedown', videoCaption.captionMouseDown
);
expect($(link)).toHandleWith(
'click', videoCaption.captionClick
);
expect($(link)).toHandleWith(
'focus', videoCaption.captionFocus
);
expect($(link)).toHandleWith(
'blur', videoCaption.captionBlur
);
expect($(link)).toHandleWith(
'keydown', videoCaption.captionKeyDown
);
}); });
}); });
it('set rendered to true', function() { it('set rendered to true', function () {
expect(videoCaption.rendered).toBeTruthy(); expect(videoCaption.rendered).toBeTruthy();
}); });
}); });
describe('when on a touch-based device', function() { describe('when on a touch-based device', function () {
beforeEach(function() { beforeEach(function () {
window.onTouchBasedDevice.andReturn(true); window.onTouchBasedDevice.andReturn(true);
initialize(); initialize();
}); });
it('show explaination message', function() { it('show explaination message', function () {
expect($('.subtitles li')).toHaveHtml("Caption will be displayed when you start playing the video."); expect($('.subtitles li')).toHaveHtml(
'Caption will be displayed when you start playing ' +
'the video.'
);
}); });
it('does not set rendered to true', function() { it('does not set rendered to true', function () {
expect(videoCaption.rendered).toBeFalsy(); expect(videoCaption.rendered).toBeFalsy();
}); });
}); });
...@@ -152,115 +194,123 @@ ...@@ -152,115 +194,123 @@
}); });
}); });
describe('mouse movement', function() { describe('mouse movement', function () {
// We will store default window.setTimeout() function here. // We will store default window.setTimeout() function here.
var oldSetTimeout = null; var oldSetTimeout = null;
beforeEach(function() { beforeEach(function () {
// Store original window.setTimeout() function. If we do not do this, then // Store original window.setTimeout() function. If we do not do
// all other tests that rely on code which uses window.setTimeout() // this, then all other tests that rely on code which uses
// function might (and probably will) fail. // window.setTimeout() function might (and probably will) fail.
oldSetTimeout = window.setTimeout; oldSetTimeout = window.setTimeout;
// Redefine window.setTimeout() function as a spy. // Redefine window.setTimeout() function as a spy.
window.setTimeout = jasmine.createSpy().andCallFake(function(callback, timeout) { return 5; }) window.setTimeout = jasmine.createSpy().andCallFake(
function (callback, timeout) {
return 5;
}
);
window.setTimeout.andReturn(100); window.setTimeout.andReturn(100);
spyOn(window, 'clearTimeout'); spyOn(window, 'clearTimeout');
}); });
afterEach(function () { afterEach(function () {
// Reset the default window.setTimeout() function. If we do not do this, // Reset the default window.setTimeout() function. If we do not
// then all other tests that rely on code which uses window.setTimeout() // do this, then all other tests that rely on code which uses
// function might (and probably will) fail. // window.setTimeout() function might (and probably will) fail.
window.setTimeout = oldSetTimeout; window.setTimeout = oldSetTimeout;
}); });
describe('when cursor is outside of the caption box', function() { describe('when cursor is outside of the caption box', function () {
beforeEach(function() { beforeEach(function () {
$(window).trigger(jQuery.Event('mousemove')); $(window).trigger(jQuery.Event('mousemove'));
}); });
it('does not set freezing timeout', function() { it('does not set freezing timeout', function () {
expect(videoCaption.frozen).toBeFalsy(); expect(videoCaption.frozen).toBeFalsy();
}); });
}); });
describe('when cursor is in the caption box', function() { describe('when cursor is in the caption box', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles').trigger(jQuery.Event('mouseenter')); $('.subtitles').trigger(jQuery.Event('mouseenter'));
}); });
it('set the freezing timeout', function() { it('set the freezing timeout', function () {
expect(videoCaption.frozen).toEqual(100); expect(videoCaption.frozen).toEqual(100);
}); });
describe('when the cursor is moving', function() { describe('when the cursor is moving', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles').trigger(jQuery.Event('mousemove')); $('.subtitles').trigger(jQuery.Event('mousemove'));
}); });
it('reset the freezing timeout', function() { it('reset the freezing timeout', function () {
expect(window.clearTimeout).toHaveBeenCalledWith(100); expect(window.clearTimeout).toHaveBeenCalledWith(100);
}); });
}); });
describe('when the mouse is scrolling', function() { describe('when the mouse is scrolling', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles').trigger(jQuery.Event('mousewheel')); $('.subtitles').trigger(jQuery.Event('mousewheel'));
}); });
it('reset the freezing timeout', function() { it('reset the freezing timeout', function () {
expect(window.clearTimeout).toHaveBeenCalledWith(100); expect(window.clearTimeout).toHaveBeenCalledWith(100);
}); });
}); });
}); });
describe('when cursor is moving out of the caption box', function() { describe(
beforeEach(function() { 'when cursor is moving out of the caption box',
function () {
beforeEach(function () {
videoCaption.frozen = 100; videoCaption.frozen = 100;
$.fn.scrollTo.reset(); $.fn.scrollTo.reset();
}); });
describe('always', function() { describe('always', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles').trigger(jQuery.Event('mouseout')); $('.subtitles').trigger(jQuery.Event('mouseout'));
}); });
it('reset the freezing timeout', function() { it('reset the freezing timeout', function () {
expect(window.clearTimeout).toHaveBeenCalledWith(100); expect(window.clearTimeout).toHaveBeenCalledWith(100);
}); });
it('unfreeze the caption', function() { it('unfreeze the caption', function () {
expect(videoCaption.frozen).toBeNull(); expect(videoCaption.frozen).toBeNull();
}); });
}); });
describe('when the player is playing', function() { describe('when the player is playing', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.playing = true; videoCaption.playing = true;
$('.subtitles li[data-index]:first').addClass('current'); $('.subtitles li[data-index]:first')
.addClass('current');
$('.subtitles').trigger(jQuery.Event('mouseout')); $('.subtitles').trigger(jQuery.Event('mouseout'));
}); });
it('scroll the caption', function() { it('scroll the caption', function () {
expect($.fn.scrollTo).toHaveBeenCalled(); expect($.fn.scrollTo).toHaveBeenCalled();
}); });
}); });
describe('when the player is not playing', function() { describe('when the player is not playing', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.playing = false; videoCaption.playing = false;
$('.subtitles').trigger(jQuery.Event('mouseout')); $('.subtitles').trigger(jQuery.Event('mouseout'));
}); });
it('does not scroll the caption', function() { it('does not scroll the caption', function () {
expect($.fn.scrollTo).not.toHaveBeenCalled(); expect($.fn.scrollTo).not.toHaveBeenCalled();
}); });
}); });
}); });
}); });
describe('search', function() { describe('search', function () {
it('return a correct caption index', function() { it('return a correct caption index', function () {
expect(videoCaption.search(0)).toEqual(-1); expect(videoCaption.search(0)).toEqual(-1);
expect(videoCaption.search(3120)).toEqual(1); expect(videoCaption.search(3120)).toEqual(1);
expect(videoCaption.search(6270)).toEqual(2); expect(videoCaption.search(6270)).toEqual(2);
...@@ -270,151 +320,178 @@ ...@@ -270,151 +320,178 @@
}); });
}); });
describe('play', function() { describe('play', function () {
describe('when the caption was not rendered', function() { describe('when the caption was not rendered', function () {
beforeEach(function() { beforeEach(function () {
window.onTouchBasedDevice.andReturn(true); window.onTouchBasedDevice.andReturn(true);
initialize(); initialize();
videoCaption.play(); videoCaption.play();
}); });
it('render the caption', function() { it('render the caption', function () {
var captionsData; var captionsData;
captionsData = jasmine.stubbedCaption; captionsData = jasmine.stubbedCaption;
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(
function (index, link) {
expect($(link)).toHaveData('index', index); expect($(link)).toHaveData('index', index);
expect($(link)).toHaveData('start', captionsData.start[index]); expect($(link)).toHaveData(
'start', captionsData.start[index]
);
expect($(link)).toHaveAttr('tabindex', 0); expect($(link)).toHaveAttr('tabindex', 0);
expect($(link)).toHaveText(captionsData.text[index]); expect($(link)).toHaveText(captionsData.text[index]);
}); });
}); });
it('add a padding element to caption', function() { it('add a padding element to caption', function () {
expect($('.subtitles li:first')).toBe('.spacing'); expect($('.subtitles li:first')).toBe('.spacing');
expect($('.subtitles li:last')).toBe('.spacing'); expect($('.subtitles li:last')).toBe('.spacing');
}); });
it('bind all the caption link', function() { it('bind all the caption link', function () {
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(
expect($(link)).toHandleWith('mouseover', videoCaption.captionMouseOverOut); function (index, link) {
expect($(link)).toHandleWith('mouseout', videoCaption.captionMouseOverOut);
expect($(link)).toHandleWith('mousedown', videoCaption.captionMouseDown); expect($(link)).toHandleWith(
expect($(link)).toHandleWith('click', videoCaption.captionClick); 'mouseover', videoCaption.captionMouseOverOut
expect($(link)).toHandleWith('focus', videoCaption.captionFocus); );
expect($(link)).toHandleWith('blur', videoCaption.captionBlur); expect($(link)).toHandleWith(
expect($(link)).toHandleWith('keydown', videoCaption.captionKeyDown); 'mouseout', videoCaption.captionMouseOverOut
}); );
}); expect($(link)).toHandleWith(
'mousedown', videoCaption.captionMouseDown
it('set rendered to true', function() { );
expect($(link)).toHandleWith(
'click', videoCaption.captionClick
);
expect($(link)).toHandleWith(
'focus', videoCaption.captionFocus
);
expect($(link)).toHandleWith(
'blur', videoCaption.captionBlur
);
expect($(link)).toHandleWith(
'keydown', videoCaption.captionKeyDown
);
});
});
it('set rendered to true', function () {
expect(videoCaption.rendered).toBeTruthy(); expect(videoCaption.rendered).toBeTruthy();
}); });
it('set playing to true', function() { it('set playing to true', function () {
expect(videoCaption.playing).toBeTruthy(); expect(videoCaption.playing).toBeTruthy();
}); });
}); });
}); });
describe('pause', function() { describe('pause', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.playing = true; videoCaption.playing = true;
videoCaption.pause(); videoCaption.pause();
}); });
it('set playing to false', function() { it('set playing to false', function () {
expect(videoCaption.playing).toBeFalsy(); expect(videoCaption.playing).toBeFalsy();
}); });
}); });
describe('updatePlayTime', function() { describe('updatePlayTime', function () {
describe('when the video speed is 1.0x', function() { describe('when the video speed is 1.0x', function () {
beforeEach(function() { beforeEach(function () {
videoSpeedControl.currentSpeed = '1.0'; videoSpeedControl.currentSpeed = '1.0';
videoCaption.updatePlayTime(25.000); videoCaption.updatePlayTime(25.000);
}); });
it('search the caption based on time', function() { it('search the caption based on time', function () {
expect(videoCaption.currentIndex).toEqual(5); expect(videoCaption.currentIndex).toEqual(5);
}); });
}); });
describe('when the video speed is not 1.0x', function() { describe('when the video speed is not 1.0x', function () {
beforeEach(function() { beforeEach(function () {
videoSpeedControl.currentSpeed = '0.75'; videoSpeedControl.currentSpeed = '0.75';
videoCaption.updatePlayTime(25.000); videoCaption.updatePlayTime(25.000);
}); });
it('search the caption based on 1.0x speed', function() { it('search the caption based on 1.0x speed', function () {
expect(videoCaption.currentIndex).toEqual(5); expect(videoCaption.currentIndex).toEqual(5);
}); });
}); });
describe('when the index is not the same', function() { describe('when the index is not the same', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.currentIndex = 1; videoCaption.currentIndex = 1;
$('.subtitles li[data-index=5]').addClass('current'); $('.subtitles li[data-index=5]').addClass('current');
videoCaption.updatePlayTime(25.000); videoCaption.updatePlayTime(25.000);
}); });
it('deactivate the previous caption', function() { it('deactivate the previous caption', function () {
expect($('.subtitles li[data-index=1]')).not.toHaveClass('current'); expect($('.subtitles li[data-index=1]'))
.not.toHaveClass('current');
}); });
it('activate new caption', function() { it('activate new caption', function () {
expect($('.subtitles li[data-index=5]')).toHaveClass('current'); expect($('.subtitles li[data-index=5]'))
.toHaveClass('current');
}); });
it('save new index', function() { it('save new index', function () {
expect(videoCaption.currentIndex).toEqual(5); expect(videoCaption.currentIndex).toEqual(5);
}); });
it('scroll caption to new position', function() { it('scroll caption to new position', function () {
expect($.fn.scrollTo).toHaveBeenCalled(); expect($.fn.scrollTo).toHaveBeenCalled();
}); });
}); });
describe('when the index is the same', function() { describe('when the index is the same', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.currentIndex = 1; videoCaption.currentIndex = 1;
$('.subtitles li[data-index=3]').addClass('current'); $('.subtitles li[data-index=3]').addClass('current');
videoCaption.updatePlayTime(15.000); videoCaption.updatePlayTime(15.000);
}); });
it('does not change current subtitle', function() { it('does not change current subtitle', function () {
expect($('.subtitles li[data-index=3]')).toHaveClass('current'); expect($('.subtitles li[data-index=3]'))
.toHaveClass('current');
}); });
}); });
}); });
describe('resize', function() { describe('resize', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
$('.subtitles li[data-index=1]').addClass('current'); $('.subtitles li[data-index=1]').addClass('current');
videoCaption.resize(); videoCaption.resize();
}); });
describe('set the height of caption container', function(){ describe('set the height of caption container', function () {
// Temporarily disabled due to intermittent failures // Temporarily disabled due to intermittent failures
// with error "Expected 745 to be close to 805, 2." in Firefox // with error "Expected 745 to be close to 805, 2." in Firefox
xit('when CC button is enabled', function() { xit('when CC button is enabled', function () {
var realHeight = parseInt($('.subtitles').css('maxHeight'), 10), var realHeight = parseInt(
$('.subtitles').css('maxHeight'), 10
),
shouldBeHeight = $('.video-wrapper').height(); shouldBeHeight = $('.video-wrapper').height();
// Because of some problems with rounding on different enviroments: // Because of some problems with rounding on different
// Linux * Mac * FF * Chrome // environments: Linux * Mac * FF * Chrome
expect(realHeight).toBeCloseTo(shouldBeHeight, 2); expect(realHeight).toBeCloseTo(shouldBeHeight, 2);
}); });
it('when CC button is disabled ', function() { it('when CC button is disabled ', function () {
var realHeight, videoWrapperHeight, progressSliderHeight, var realHeight, videoWrapperHeight, progressSliderHeight,
controlHeight, shouldBeHeight; controlHeight, shouldBeHeight;
state.captionsHidden = true; state.captionsHidden = true;
videoCaption.setSubtitlesHeight(); videoCaption.setSubtitlesHeight();
realHeight = parseInt($('.subtitles').css('maxHeight'), 10); realHeight = parseInt(
$('.subtitles').css('maxHeight'), 10
);
videoWrapperHeight = $('.video-wrapper').height(); videoWrapperHeight = $('.video-wrapper').height();
progressSliderHeight = videoControl.sliderEl.height(); progressSliderHeight = videoControl.sliderEl.height();
controlHeight = videoControl.el.height(); controlHeight = videoControl.el.height();
...@@ -426,67 +503,75 @@ ...@@ -426,67 +503,75 @@
}); });
}); });
it('set the height of caption spacing', function() { it('set the height of caption spacing', function () {
var firstSpacing, lastSpacing; var firstSpacing, lastSpacing;
firstSpacing = Math.abs(parseInt($('.subtitles .spacing:first').css('height'), 10));
lastSpacing = Math.abs(parseInt($('.subtitles .spacing:last').css('height'), 10)); firstSpacing = Math.abs(parseInt(
expect(firstSpacing - videoCaption.topSpacingHeight()).toBeLessThan(1); $('.subtitles .spacing:first').css('height'), 10
expect(lastSpacing - videoCaption.bottomSpacingHeight()).toBeLessThan(1); ));
lastSpacing = Math.abs(parseInt(
$('.subtitles .spacing:last').css('height'), 10
));
expect(firstSpacing - videoCaption.topSpacingHeight())
.toBeLessThan(1);
expect(lastSpacing - videoCaption.bottomSpacingHeight())
.toBeLessThan(1);
}); });
it('scroll caption to new position', function() { it('scroll caption to new position', function () {
expect($.fn.scrollTo).toHaveBeenCalled(); expect($.fn.scrollTo).toHaveBeenCalled();
}); });
}); });
describe('scrollCaption', function() { describe('scrollCaption', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
}); });
describe('when frozen', function() { describe('when frozen', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.frozen = true; videoCaption.frozen = true;
$('.subtitles li[data-index=1]').addClass('current'); $('.subtitles li[data-index=1]').addClass('current');
videoCaption.scrollCaption(); videoCaption.scrollCaption();
}); });
it('does not scroll the caption', function() { it('does not scroll the caption', function () {
expect($.fn.scrollTo).not.toHaveBeenCalled(); expect($.fn.scrollTo).not.toHaveBeenCalled();
}); });
}); });
describe('when not frozen', function() { describe('when not frozen', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.frozen = false; videoCaption.frozen = false;
}); });
describe('when there is no current caption', function() { describe('when there is no current caption', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.scrollCaption(); videoCaption.scrollCaption();
}); });
it('does not scroll the caption', function() { it('does not scroll the caption', function () {
expect($.fn.scrollTo).not.toHaveBeenCalled(); expect($.fn.scrollTo).not.toHaveBeenCalled();
}); });
}); });
describe('when there is a current caption', function() { describe('when there is a current caption', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles li[data-index=1]').addClass('current'); $('.subtitles li[data-index=1]').addClass('current');
videoCaption.scrollCaption(); videoCaption.scrollCaption();
}); });
it('scroll to current caption', function() { it('scroll to current caption', function () {
expect($.fn.scrollTo).toHaveBeenCalled(); expect($.fn.scrollTo).toHaveBeenCalled();
}); });
}); });
}); });
}); });
describe('seekPlayer', function() { describe('seekPlayer', function () {
describe('when the video speed is 1.0x', function() { describe('when the video speed is 1.0x', function () {
beforeEach(function() { beforeEach(function () {
videoSpeedControl.currentSpeed = '1.0'; videoSpeedControl.currentSpeed = '1.0';
$('.subtitles li[data-start="14910"]').trigger('click'); $('.subtitles li[data-start="14910"]').trigger('click');
}); });
...@@ -496,24 +581,26 @@ ...@@ -496,24 +581,26 @@
// use an object that is not, or is no longer, usable // use an object that is not, or is no longer, usable
// Expected 0 to equal 14.91." // Expected 0 to equal 14.91."
// on Firefox // on Firefox
xit('trigger seek event with the correct time', function() { xit('trigger seek event with the correct time', function () {
expect(videoPlayer.currentTime).toEqual(14.91); expect(videoPlayer.currentTime).toEqual(14.91);
}); });
}); });
describe('when the video speed is not 1.0x', function() { describe('when the video speed is not 1.0x', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
videoSpeedControl.currentSpeed = '0.75'; videoSpeedControl.currentSpeed = '0.75';
$('.subtitles li[data-start="14910"]').trigger('click'); $('.subtitles li[data-start="14910"]').trigger('click');
}); });
it('trigger seek event with the correct time', function() { it('trigger seek event with the correct time', function () {
expect(videoPlayer.currentTime).toEqual(14.91); expect(videoPlayer.currentTime).toEqual(14.91);
}); });
}); });
describe('when the player type is Flash at speed 0.75x', function () { describe('when the player type is Flash at speed 0.75x',
function () {
beforeEach(function () { beforeEach(function () {
initialize(); initialize();
videoSpeedControl.currentSpeed = '0.75'; videoSpeedControl.currentSpeed = '0.75';
...@@ -527,143 +614,181 @@ ...@@ -527,143 +614,181 @@
}); });
}); });
describe('toggle', function() { describe('toggle', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
spyOn(videoPlayer, 'log'); spyOn(videoPlayer, 'log');
$('.subtitles li[data-index=1]').addClass('current'); $('.subtitles li[data-index=1]').addClass('current');
}); });
describe('when the caption is visible', function() { describe('when the caption is visible', function () {
beforeEach(function() { beforeEach(function () {
state.el.removeClass('closed'); state.el.removeClass('closed');
videoCaption.toggle(jQuery.Event('click')); videoCaption.toggle(jQuery.Event('click'));
}); });
it('log the hide_transcript event', function() { it('log the hide_transcript event', function () {
expect(videoPlayer.log).toHaveBeenCalledWith('hide_transcript', { expect(videoPlayer.log).toHaveBeenCalledWith(
'hide_transcript',
{
currentTime: videoPlayer.currentTime currentTime: videoPlayer.currentTime
}); }
);
}); });
it('hide the caption', function() { it('hide the caption', function () {
expect(state.el).toHaveClass('closed'); expect(state.el).toHaveClass('closed');
}); });
}); });
describe('when the caption is hidden', function() { describe('when the caption is hidden', function () {
beforeEach(function() { beforeEach(function () {
state.el.addClass('closed'); state.el.addClass('closed');
videoCaption.toggle(jQuery.Event('click')); videoCaption.toggle(jQuery.Event('click'));
}); });
it('log the show_transcript event', function() { it('log the show_transcript event', function () {
expect(videoPlayer.log).toHaveBeenCalledWith('show_transcript', { expect(videoPlayer.log).toHaveBeenCalledWith(
'show_transcript',
{
currentTime: videoPlayer.currentTime currentTime: videoPlayer.currentTime
}); }
);
}); });
it('show the caption', function() { it('show the caption', function () {
expect(state.el).not.toHaveClass('closed'); expect(state.el).not.toHaveClass('closed');
}); });
it('scroll the caption', function() { it('scroll the caption', function () {
expect($.fn.scrollTo).toHaveBeenCalled(); expect($.fn.scrollTo).toHaveBeenCalled();
}); });
}); });
}); });
describe('caption accessibility', function() { describe('caption accessibility', function () {
beforeEach(function() { beforeEach(function () {
initialize(); initialize();
}); });
describe('when getting focus through TAB key', function() { describe('when getting focus through TAB key', function () {
beforeEach(function() { beforeEach(function () {
videoCaption.isMouseFocus = false; videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus')); $('.subtitles li[data-index=0]').trigger(
jQuery.Event('focus')
);
}); });
it('shows an outline around the caption', function() { it('shows an outline around the caption', function () {
expect($('.subtitles li[data-index=0]')).toHaveClass('focused'); expect($('.subtitles li[data-index=0]'))
.toHaveClass('focused');
}); });
it('has automatic scrolling disabled', function() { it('has automatic scrolling disabled', function () {
expect(videoCaption.autoScrolling).toBe(false); expect(videoCaption.autoScrolling).toBe(false);
}); });
}); });
describe('when loosing focus through TAB key', function() { describe('when loosing focus through TAB key', function () {
beforeEach(function() { beforeEach(function () {
$('.subtitles li[data-index=0]').trigger(jQuery.Event('blur')); $('.subtitles li[data-index=0]').trigger(
jQuery.Event('blur')
);
}); });
it('does not show an outline around the caption', function() { it('does not show an outline around the caption', function () {
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused'); expect($('.subtitles li[data-index=0]'))
.not.toHaveClass('focused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function () {
expect(videoCaption.autoScrolling).toBe(true); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
describe('when same caption gets the focus through mouse after having focus through TAB key', function() { describe(
beforeEach(function() { 'when same caption gets the focus through mouse after ' +
'having focus through TAB key',
function () {
beforeEach(function () {
videoCaption.isMouseFocus = false; videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus')); $('.subtitles li[data-index=0]')
$('.subtitles li[data-index=0]').trigger(jQuery.Event('mousedown')); .trigger(jQuery.Event('focus'));
$('.subtitles li[data-index=0]')
.trigger(jQuery.Event('mousedown'));
}); });
it('does not show an outline around it', function() { it('does not show an outline around it', function () {
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused'); expect($('.subtitles li[data-index=0]'))
.not.toHaveClass('focused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function () {
expect(videoCaption.autoScrolling).toBe(true); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
describe('when a second caption gets focus through mouse after first had focus through TAB key', function() { describe(
beforeEach(function() { 'when a second caption gets focus through mouse after ' +
'first had focus through TAB key',
function () {
var subDataLiIdx__0, subDataLiIdx__1;
beforeEach(function () {
subDataLiIdx__0 = $('.subtitles li[data-index=0]');
subDataLiIdx__1 = $('.subtitles li[data-index=1]');
videoCaption.isMouseFocus = false; videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
$('.subtitles li[data-index=0]').trigger(jQuery.Event('blur')); subDataLiIdx__0.trigger(jQuery.Event('focus'));
subDataLiIdx__0.trigger(jQuery.Event('blur'));
videoCaption.isMouseFocus = true; videoCaption.isMouseFocus = true;
$('.subtitles li[data-index=1]').trigger(jQuery.Event('mousedown'));
subDataLiIdx__1.trigger(jQuery.Event('mousedown'));
}); });
it('does not show an outline around the first', function() { it('does not show an outline around the first', function () {
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused'); expect(subDataLiIdx__0).not.toHaveClass('focused');
}); });
it('does not show an outline around the second', function() { it('does not show an outline around the second', function () {
expect($('.subtitles li[data-index=1]')).not.toHaveClass('focused'); expect(subDataLiIdx__1).not.toHaveClass('focused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function () {
expect(videoCaption.autoScrolling).toBe(true); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
xdescribe('when enter key is pressed on a caption', function() { xdescribe('when enter key is pressed on a caption', function () {
beforeEach(function() { var subDataLiIdx__0;
beforeEach(function () {
var e; var e;
subDataLiIdx__0 = $('.subtitles li[data-index=0]');
spyOn(videoCaption, 'seekPlayer').andCallThrough(); spyOn(videoCaption, 'seekPlayer').andCallThrough();
videoCaption.isMouseFocus = false; videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus')); subDataLiIdx__0.trigger(jQuery.Event('focus'));
e = jQuery.Event('keydown'); e = jQuery.Event('keydown');
e.which = 13; // ENTER key e.which = 13; // ENTER key
$('.subtitles li[data-index=0]').trigger(e); subDataLiIdx__0.trigger(e);
}); });
// Temporarily disabled due to intermittent failures // Temporarily disabled due to intermittent failures.
// Fails with error: "InvalidStateError: InvalidStateError: An attempt //
// was made to use an object that is not, or is no longer, usable" // Fails with error: "InvalidStateError: InvalidStateError: An
xit('shows an outline around it', function() { // attempt was made to use an object that is not, or is no
expect($('.subtitles li[data-index=0]')).toHaveClass('focused'); // longer, usable".
xit('shows an outline around it', function () {
expect(subDataLiIdx__0).toHaveClass('focused');
}); });
xit('calls seekPlayer', function() { xit('calls seekPlayer', function () {
expect(videoCaption.seekPlayer).toHaveBeenCalled(); expect(videoCaption.seekPlayer).toHaveBeenCalled();
}); });
}); });
......
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