Commit 7121db0a by polesye

BLD-353: Fix js unit tests.

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