From 7121db0a094848064d8b55d4c961565478dbb306 Mon Sep 17 00:00:00 2001 From: polesye Date: Wed, 9 Oct 2013 15:12:57 +0300 Subject: [PATCH 1/6] BLD-353: Fix js unit tests. --- .../js/spec/video/video_caption_spec.js | 66 ++++++++++--------- .../spec/video/video_progress_slider_spec.js | 6 +- .../spec/video/video_quality_control_spec.js | 23 +++---- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js index 061576efd23a..f995717d4d3d 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js @@ -1,6 +1,7 @@ (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,33 +757,41 @@ }); }); - 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) { - subDataLiIdx__0 = $('.subtitles li[data-index=0]'); + waitsFor(function () { + return videoCaption.captions.length; + }, "Captions are not loaded.", WAIT_TIMEOUT); - 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); - }); + runs(expectations); + }, + initializeClick = 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'); + 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 () { - expect(videoCaption.seekPlayer).toHaveBeenCalled(); + it('calls seekPlayer', function () { + assertCaptions(function() { + initializeClick(); + expect(videoCaption.seekPlayer).toHaveBeenCalled(); + }); }); }); }); diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_progress_slider_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_progress_slider_spec.js index 30a873f34000..423f87c7e2e9 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_progress_slider_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_progress_slider_spec.js @@ -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(); diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_quality_control_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_quality_control_spec.js index 01f7a5b97971..48f46a4ac21d 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_quality_control_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_quality_control_spec.js @@ -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( - 'HD off' - ); + 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); }); }); }); From e95ee9948bd87981dc8d6579ecfec34959d123a8 Mon Sep 17 00:00:00 2001 From: polesye Date: Wed, 9 Oct 2013 16:53:26 +0300 Subject: [PATCH 2/6] Add acceptance test instead of broken js unit test. --- .../contentstore/features/video.feature | 8 ++++ cms/djangoapps/contentstore/features/video.py | 23 +++++++++++ .../js/spec/video/video_caption_spec.js | 38 ------------------- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/cms/djangoapps/contentstore/features/video.feature b/cms/djangoapps/contentstore/features/video.feature index a47b2313c610..8486f6ec827e 100644 --- a/cms/djangoapps/contentstore/features/video.feature +++ b/cms/djangoapps/contentstore/features/video.feature @@ -69,3 +69,11 @@ Feature: CMS.Video Component # Then Captions become "invisible" after 3 seconds # And I hover over button "volume" # 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" diff --git a/cms/djangoapps/contentstore/features/video.py b/cms/djangoapps/contentstore/features/video.py index 80963ab55645..a95191ec6daa 100644 --- a/cms/djangoapps/contentstore/features/video.py +++ b/cms/djangoapps/contentstore/features/video.py @@ -3,6 +3,7 @@ from lettuce import world, step from xmodule.modulestore import Location from contentstore.utils import get_modulestore +from selenium.webdriver.common.keys import Keys BUTTONS = { 'CC': '.hide-subtitles', @@ -154,3 +155,25 @@ def check_captions_visibility_state(_step, visibility_state, timeout): assert world.css_visible('.subtitles') else: 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()) + diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js index f995717d4d3d..d8b704b043bd 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js @@ -756,44 +756,6 @@ expect(videoCaption.autoScrolling).toBe(true); }); }); - - describe('when enter key is pressed on a caption', function () { - - 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(); - videoCaption.isMouseFocus = false; - subDataLiIdx__0.trigger(jQuery.Event('focus')); - e = jQuery.Event('keydown'); - e.which = 13; // ENTER key - subDataLiIdx__0.trigger(e); - }; - - it('shows an outline around it' , function () { - assertCaptions(function() { - var subDataLiIdx__0 = $('.subtitles li[data-index=0]'); - initializeClick(); - expect(subDataLiIdx__0).toHaveClass('focused'); - }); - }); - - it('calls seekPlayer', function () { - assertCaptions(function() { - initializeClick(); - expect(videoCaption.seekPlayer).toHaveBeenCalled(); - }); - }); - }); }); }); From c85bbabb9352abab6ac187b53a47dbc3d078d0c6 Mon Sep 17 00:00:00 2001 From: polesye Date: Thu, 10 Oct 2013 08:55:49 +0300 Subject: [PATCH 3/6] Fix timeout. --- common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js index d8b704b043bd..02fddb76db5a 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_caption_spec.js @@ -1,7 +1,6 @@ (function () { describe('VideoCaption', function () { - var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD, - WAIT_TIMEOUT = 1000; + var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD; function initialize() { loadFixtures('video_all.html'); From 322b17ee0b8c9d2e5b8ad28804ac9b3cdd785700 Mon Sep 17 00:00:00 2001 From: polesye Date: Wed, 16 Oct 2013 15:30:52 +0300 Subject: [PATCH 4/6] Uncomment acceptance tests. --- .../contentstore/features/video.feature | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/cms/djangoapps/contentstore/features/video.feature b/cms/djangoapps/contentstore/features/video.feature index 8486f6ec827e..51806a4ba8b2 100644 --- a/cms/djangoapps/contentstore/features/video.feature +++ b/cms/djangoapps/contentstore/features/video.feature @@ -15,11 +15,11 @@ Feature: CMS.Video Component # 3 # Sauce Labs cannot delete cookies - # @skip_sauce - #Scenario: Captions are hidden correctly - # Given I have created a Video component with subtitles - # And I have hidden captions - # Then when I view the video it does not show the captions + @skip_sauce + Scenario: Captions are hidden correctly + Given I have created a Video component with subtitles + And I have hidden captions + Then when I view the video it does not show the captions # 4 # Sauce Labs cannot delete cookies @@ -43,37 +43,37 @@ Feature: CMS.Video Component Then the correct Youtube video is shown # 7 - # Scenario: Closed captions become visible when the mouse hovers over CC button - # Given I have created a Video component with subtitles - # And Make sure captions are closed - # Then Captions become "invisible" after 3 seconds - # And I hover over button "CC" - # Then Captions become "visible" - # And I hover over button "volume" - # Then Captions become "invisible" after 3 seconds + Scenario: Closed captions become visible when the mouse hovers over CC button + Given I have created a Video component with subtitles + And Make sure captions are closed + Then Captions become "invisible" after 3 seconds + And I hover over button "CC" + Then Captions become "visible" + And I hover over button "volume" + Then Captions become "invisible" after 3 seconds # 8 - #Scenario: Open captions never become invisible - # Given I have created a Video component with subtitles - # And Make sure captions are open - # Then Captions are "visible" - # And I hover over button "CC" - # Then Captions are "visible" - # And I hover over button "volume" - # Then Captions are "visible" + Scenario: Open captions never become invisible + Given I have created a Video component with subtitles + And Make sure captions are open + Then Captions are "visible" + And I hover over button "CC" + Then Captions are "visible" + And I hover over button "volume" + Then Captions are "visible" # 9 - #Scenario: Closed captions are invisible when mouse doesn't hover on CC button - # Given I have created a Video component with subtitles - # And Make sure captions are closed - # Then Captions become "invisible" after 3 seconds - # And I hover over button "volume" - # Then Captions are "invisible" + Scenario: Closed captions are invisible when mouse doesn't hover on CC button + Given I have created a Video component with subtitles + And Make sure captions are closed + Then Captions become "invisible" after 3 seconds + And I hover over button "volume" + 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" + 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" From 32ca9887600ffcd604249f0063198bcb6c89c610 Mon Sep 17 00:00:00 2001 From: polesye Date: Wed, 16 Oct 2013 16:15:09 +0300 Subject: [PATCH 5/6] Fix video voulme test. --- .../lib/xmodule/xmodule/js/spec/video/video_player_spec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js index 3f5e1831ac6c..988d5bdaecc5 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js @@ -701,8 +701,13 @@ }); it('set the player volume', function() { + var expectedValue = 60, + realValue; + player.setVolume(60); - expect(player.getVolume()).toEqual(0.6); + realValue = Math.round(player.getVolume()*100); + + expect(realValue).toEqual(expectedValue); }); }); }); From eaf5eb29450ce37147d3208aa6b380866a3ad631 Mon Sep 17 00:00:00 2001 From: polesye Date: Fri, 18 Oct 2013 19:58:18 +0300 Subject: [PATCH 6/6] Enable acceptance test. --- .../contentstore/features/video-editor.feature | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cms/djangoapps/contentstore/features/video-editor.feature b/cms/djangoapps/contentstore/features/video-editor.feature index c281ca453e81..d5b4a2a03b4e 100644 --- a/cms/djangoapps/contentstore/features/video-editor.feature +++ b/cms/djangoapps/contentstore/features/video-editor.feature @@ -15,17 +15,12 @@ Feature: CMS.Video Component Editor Then I can modify the display name 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 - # @skip_sauce - #Scenario: Captions are hidden when "show captions" is false - # Given I have created a Video component with subtitles - # And I have set "show captions" to False - # Then when I view the video it does not show the captions + @skip_sauce + Scenario: Captions are hidden when "show captions" is false + Given I have created a Video component with subtitles + And I have set "show captions" to False + Then when I view the video it does not show the captions # Sauce Labs cannot delete cookies @skip_sauce