Commit 7121db0a by polesye

BLD-353: Fix js unit tests.

parent 79f11de6
(function () { (function () {
describe('VideoCaption', function () { describe('VideoCaption', function () {
var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD; var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD,
WAIT_TIMEOUT = 1000;
function initialize() { function initialize() {
loadFixtures('video_all.html'); loadFixtures('video_all.html');
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
} }
return false; return false;
}, 'Expect captions to be loaded.', 1000); }, 'Expect captions to be loaded.', WAIT_TIMEOUT);
runs(function () { runs(function () {
expect($.ajaxWithPrefix).toHaveBeenCalledWith({ expect($.ajaxWithPrefix).toHaveBeenCalledWith({
...@@ -469,9 +470,7 @@ ...@@ -469,9 +470,7 @@
}); });
describe('set the height of caption container', function () { describe('set the height of caption container', function () {
// Temporarily disabled due to intermittent failures it('when CC button is enabled', function () {
// with error "Expected 745 to be close to 805, 2." in Firefox
xit('when CC button is enabled', function () {
var realHeight = parseInt( var realHeight = parseInt(
$('.subtitles').css('maxHeight'), 10 $('.subtitles').css('maxHeight'), 10
), ),
...@@ -576,12 +575,7 @@ ...@@ -576,12 +575,7 @@
$('.subtitles li[data-start="14910"]').trigger('click'); $('.subtitles li[data-start="14910"]').trigger('click');
}); });
// Temporarily disabled due to intermittent failures it('trigger seek event with the correct time', function () {
// Fails with error: "InvalidStateError: An attempt was made to
// use an object that is not, or is no longer, usable
// Expected 0 to equal 14.91."
// on Firefox
xit('trigger seek event with the correct time', function () {
expect(videoPlayer.currentTime).toEqual(14.91); expect(videoPlayer.currentTime).toEqual(14.91);
}); });
}); });
...@@ -763,33 +757,41 @@ ...@@ -763,33 +757,41 @@
}); });
}); });
xdescribe('when enter key is pressed on a caption', function () { describe('when enter key is pressed on a caption', function () {
var subDataLiIdx__0;
beforeEach(function () { var assertCaptions = function (expectations) {
var e;
subDataLiIdx__0 = $('.subtitles li[data-index=0]'); waitsFor(function () {
return videoCaption.captions.length;
}, "Captions are not loaded.", WAIT_TIMEOUT);
spyOn(videoCaption, 'seekPlayer').andCallThrough(); runs(expectations);
videoCaption.isMouseFocus = false; },
subDataLiIdx__0.trigger(jQuery.Event('focus')); initializeClick = function () {
e = jQuery.Event('keydown'); var e,
e.which = 13; // ENTER key subDataLiIdx__0 = $('.subtitles li[data-index=0]');
subDataLiIdx__0.trigger(e);
}); spyOn(videoCaption, 'seekPlayer').andCallThrough();
videoCaption.isMouseFocus = false;
subDataLiIdx__0.trigger(jQuery.Event('focus'));
e = jQuery.Event('keydown');
e.which = 13; // ENTER key
subDataLiIdx__0.trigger(e);
};
// Temporarily disabled due to intermittent failures. it('shows an outline around it' , function () {
// assertCaptions(function() {
// Fails with error: "InvalidStateError: InvalidStateError: An var subDataLiIdx__0 = $('.subtitles li[data-index=0]');
// attempt was made to use an object that is not, or is no initializeClick();
// longer, usable". expect(subDataLiIdx__0).toHaveClass('focused');
xit('shows an outline around it', function () { });
expect(subDataLiIdx__0).toHaveClass('focused');
}); });
xit('calls seekPlayer', function () { it('calls seekPlayer', function () {
expect(videoCaption.seekPlayer).toHaveBeenCalled(); assertCaptions(function() {
initializeClick();
expect(videoCaption.seekPlayer).toHaveBeenCalled();
});
}); });
}); });
}); });
......
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
// function might (and probably will) fail. // 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);
initialize(); initialize();
...@@ -180,9 +180,7 @@ ...@@ -180,9 +180,7 @@
expect(videoPlayer.currentTime).toEqual(20); expect(videoPlayer.currentTime).toEqual(20);
}); });
// Temporarily disabled due to intermittent failures it('set timeout to unfreeze the slider', function() {
// Fails with error: " Expected true to be falsy."
xit('set timeout to unfreeze the slider', function() {
expect(window.setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 200); expect(window.setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 200);
window.setTimeout.mostRecentCall.args[0](); window.setTimeout.mostRecentCall.args[0]();
expect(videoProgressSlider.frozen).toBeFalsy(); expect(videoProgressSlider.frozen).toBeFalsy();
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
beforeEach(function() { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false); window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice')
.andReturn(false);
}); });
afterEach(function() { afterEach(function() {
...@@ -20,7 +22,8 @@ ...@@ -20,7 +22,8 @@
}); });
describe('constructor', function() { describe('constructor', function() {
var oldYT = window.YT; var oldYT = window.YT,
SELECTOR = 'a.quality_control';
beforeEach(function() { beforeEach(function() {
window.YT = { window.YT = {
...@@ -37,21 +40,13 @@ ...@@ -37,21 +40,13 @@
}); });
it('render the quality control', function() { it('render the quality control', function() {
expect(videoControl.secondaryControlsEl.html()) var container = videoControl.secondaryControlsEl;
.toContain( expect(container).toContain(SELECTOR);
'<a ' +
'href="#" ' +
'class="quality_control" ' +
'title="HD off" ' +
'role="button" ' +
'aria-disabled="false"' +
'>HD off</a>'
);
}); });
it('bind the quality control', function() { it('bind the quality control', function() {
expect($('.quality_control')) var handler = videoQualityControl.toggleQuality;
.toHandleWith('click', videoQualityControl.toggleQuality); expect($(SELECTOR)).toHandleWith('click', handler);
}); });
}); });
}); });
......
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