Commit 70e5e80e by polesye

Merge pull request #1339 from edx/anton/fix-video-js-unit-tests

Fix broken tests for video player
parents d15bfb67 eaf5eb29
...@@ -15,17 +15,12 @@ Feature: CMS.Video Component Editor ...@@ -15,17 +15,12 @@ Feature: CMS.Video Component Editor
Then I can modify the display name Then I can modify the display name
And my video display name change is persisted on save And my video display name change is persisted on save
# Disabling this 10/7/13 due to nondeterministic behavior
# in master. The failure seems to occur when YouTube does
# not respond quickly enough, so that the video player
# doesn't load.
#
# Sauce Labs cannot delete cookies # Sauce Labs cannot delete cookies
# @skip_sauce @skip_sauce
#Scenario: Captions are hidden when "show captions" is false Scenario: Captions are hidden when "show captions" is false
# Given I have created a Video component with subtitles Given I have created a Video component with subtitles
# And I have set "show captions" to False And I have set "show captions" to False
# Then when I view the video it does not show the captions Then when I view the video it does not show the captions
# Sauce Labs cannot delete cookies # Sauce Labs cannot delete cookies
@skip_sauce @skip_sauce
......
...@@ -15,11 +15,11 @@ Feature: CMS.Video Component ...@@ -15,11 +15,11 @@ Feature: CMS.Video Component
# 3 # 3
# Sauce Labs cannot delete cookies # Sauce Labs cannot delete cookies
# @skip_sauce @skip_sauce
#Scenario: Captions are hidden correctly Scenario: Captions are hidden correctly
# Given I have created a Video component with subtitles Given I have created a Video component with subtitles
# And I have hidden captions And I have hidden captions
# Then when I view the video it does not show the captions Then when I view the video it does not show the captions
# 4 # 4
# Sauce Labs cannot delete cookies # Sauce Labs cannot delete cookies
...@@ -43,29 +43,37 @@ Feature: CMS.Video Component ...@@ -43,29 +43,37 @@ Feature: CMS.Video Component
Then the correct Youtube video is shown Then the correct Youtube video is shown
# 7 # 7
# Scenario: Closed captions become visible when the mouse hovers over CC button Scenario: Closed captions become visible when the mouse hovers over CC button
# Given I have created a Video component with subtitles Given I have created a Video component with subtitles
# And Make sure captions are closed And Make sure captions are closed
# Then Captions become "invisible" after 3 seconds Then Captions become "invisible" after 3 seconds
# And I hover over button "CC" And I hover over button "CC"
# Then Captions become "visible" Then Captions become "visible"
# And I hover over button "volume" And I hover over button "volume"
# Then Captions become "invisible" after 3 seconds Then Captions become "invisible" after 3 seconds
# 8 # 8
#Scenario: Open captions never become invisible Scenario: Open captions never become invisible
# Given I have created a Video component with subtitles Given I have created a Video component with subtitles
# And Make sure captions are open And Make sure captions are open
# Then Captions are "visible" Then Captions are "visible"
# And I hover over button "CC" And I hover over button "CC"
# Then Captions are "visible" Then Captions are "visible"
# And I hover over button "volume" And I hover over button "volume"
# Then Captions are "visible" Then Captions are "visible"
# 9 # 9
#Scenario: Closed captions are invisible when mouse doesn't hover on CC button Scenario: Closed captions are invisible when mouse doesn't hover on CC button
# Given I have created a Video component with subtitles Given I have created a Video component with subtitles
# And Make sure captions are closed And Make sure captions are closed
# Then Captions become "invisible" after 3 seconds Then Captions become "invisible" after 3 seconds
# And I hover over button "volume" And I hover over button "volume"
# Then Captions are "invisible" Then Captions are "invisible"
# 10
Scenario: When enter key is pressed on a caption shows an outline around it
Given I have created a Video component with subtitles
And Make sure captions are opened
Then I focus on caption line with data-index 0
Then I press "enter" button on caption line with data-index 0
And I see caption line with data-index 0 has class "focused"
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from lettuce import world, step from lettuce import world, step
from xmodule.modulestore import Location from xmodule.modulestore import Location
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
from selenium.webdriver.common.keys import Keys
BUTTONS = { BUTTONS = {
'CC': '.hide-subtitles', 'CC': '.hide-subtitles',
...@@ -154,3 +155,25 @@ def check_captions_visibility_state(_step, visibility_state, timeout): ...@@ -154,3 +155,25 @@ def check_captions_visibility_state(_step, visibility_state, timeout):
assert world.css_visible('.subtitles') assert world.css_visible('.subtitles')
else: else:
assert not world.css_visible('.subtitles') assert not world.css_visible('.subtitles')
def find_caption_line_by_data_index(index):
SELECTOR = ".subtitles > li[data-index='{index}']".format(index=index)
return world.css_find(SELECTOR).first
@step('I focus on caption line with data-index (\d+)$')
def focus_on_caption_line(_step, index):
find_caption_line_by_data_index(int(index.strip()))._element.send_keys(Keys.TAB)
@step('I press "enter" button on caption line with data-index (\d+)$')
def focus_on_caption_line(_step, index):
find_caption_line_by_data_index(int(index.strip()))._element.send_keys(Keys.ENTER)
@step('I see caption line with data-index (\d+) has class "([^"]*)"$')
def caption_line_has_class(_step, index, className):
SELECTOR = ".subtitles > li[data-index='{index}']".format(index=int(index.strip()))
world.css_has_class(SELECTOR, className.strip())
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,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 +469,7 @@ ...@@ -469,9 +469,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 +574,7 @@ ...@@ -576,12 +574,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);
}); });
}); });
...@@ -762,36 +755,6 @@ ...@@ -762,36 +755,6 @@
expect(videoCaption.autoScrolling).toBe(true); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
xdescribe('when enter key is pressed on a caption', function () {
var subDataLiIdx__0;
beforeEach(function () {
var e;
subDataLiIdx__0 = $('.subtitles li[data-index=0]');
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.
//
// 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 () {
expect(subDataLiIdx__0).toHaveClass('focused');
});
xit('calls seekPlayer', function () {
expect(videoCaption.seekPlayer).toHaveBeenCalled();
});
});
}); });
}); });
......
...@@ -701,8 +701,13 @@ ...@@ -701,8 +701,13 @@
}); });
it('set the player volume', function() { it('set the player volume', function() {
var expectedValue = 60,
realValue;
player.setVolume(60); player.setVolume(60);
expect(player.getVolume()).toEqual(0.6); realValue = Math.round(player.getVolume()*100);
expect(realValue).toEqual(expectedValue);
}); });
}); });
}); });
......
...@@ -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