'));
- });
-
- describe('when there is an exception', function() {
- beforeEach(function() {
- const error = new Error();
- error.restart = true;
- this.stubbedJax.root.toMathML.and.throwError(error);
- this.problem.updateMathML(this.stubbedJax, $('#input_example_1').get(0));
- });
-
- it('should queue up the exception', function() {
- expect(MathJax.Callback.After).toHaveBeenCalledWith([this.problem.refreshMath, this.stubbedJax], true);
- });
- });
- });
-
- describe('refreshAnswers', function() {
- beforeEach(function() {
- this.problem = new Problem($('.xblock-student_view'));
- this.problem.el.html(`\
-
-
-
-\
-`
- );
- this.stubSchematic = { update_value: jasmine.createSpy('schematic') };
- this.stubCodeMirror = { save: jasmine.createSpy('CodeMirror') };
- $('input.schematic').get(0).schematic = this.stubSchematic;
- $('textarea.CodeMirror').get(0).CodeMirror = this.stubCodeMirror;
- });
-
- it('update each schematic', function() {
- this.problem.refreshAnswers();
- expect(this.stubSchematic.update_value).toHaveBeenCalled();
- });
-
- it('update each code block', function() {
- this.problem.refreshAnswers();
- expect(this.stubCodeMirror.save).toHaveBeenCalled();
- });
- });
-
- describe('multiple JsInput in single problem', function() {
- const jsinput_html = readFixtures('jsinput_problem.html');
-
- beforeEach(function() {
- this.problem = new Problem($('.xblock-student_view'));
- this.problem.render(jsinput_html);
- });
-
- it('submit_save_waitfor should return false', function() {
- $(this.problem.inputs[0]).data('waitfor', function() {});
- expect(this.problem.submit_save_waitfor()).toEqual(false);
- });
- });
-
- describe('Submitting an xqueue-graded problem', function() {
- const matlabinput_html = readFixtures('matlabinput_problem.html');
-
- beforeEach(function() {
- spyOn($, 'postWithPrefix').and.callFake((url, callback) => callback({html: matlabinput_html}));
- jasmine.clock().install();
- this.problem = new Problem($('.xblock-student_view'));
- spyOn(this.problem, 'poll').and.callThrough();
- this.problem.render(matlabinput_html);
- });
-
- afterEach(() => jasmine.clock().uninstall());
-
- it('check that we stop polling after a fixed amount of time', function() {
- expect(this.problem.poll).not.toHaveBeenCalled();
- jasmine.clock().tick(1);
- const time_steps = [1000, 2000, 4000, 8000, 16000, 32000];
- let num_calls = 1;
- for (let time_step of Array.from(time_steps)) {
- (time_step => {
- jasmine.clock().tick(time_step);
- expect(this.problem.poll.calls.count()).toEqual(num_calls);
- num_calls += 1;
- })(time_step);
- }
-
- // jump the next step and verify that we are not still continuing to poll
- jasmine.clock().tick(64000);
- expect(this.problem.poll.calls.count()).toEqual(6);
-
- expect($('.notification-gentle-alert .notification-message').text()).toEqual("The grading process is still running. Refresh the page to see updates.");
- });
- });
-
- describe('codeinput problem', function() {
- const codeinputProblemHtml = readFixtures('codeinput_problem.html');
-
- beforeEach(function() {
- spyOn($, 'postWithPrefix').and.callFake((url, callback) => callback({html: codeinputProblemHtml}));
- this.problem = new Problem($('.xblock-student_view'));
- this.problem.render(codeinputProblemHtml);
- });
-
- it('has rendered with correct a11y info', function() {
- const CodeMirrorTextArea = $('textarea')[1];
- const CodeMirrorTextAreaId = 'cm-textarea-101';
-
- // verify that question label has correct `for` attribute value
- expect($('.problem-group-label').attr('for')).toEqual(CodeMirrorTextAreaId);
-
- // verify that codemirror textarea has correct `id` attribute value
- expect($(CodeMirrorTextArea).attr('id')).toEqual(CodeMirrorTextAreaId);
-
- // verify that codemirror textarea has correct `aria-describedby` attribute value
- expect($(CodeMirrorTextArea).attr('aria-describedby')).toEqual('cm-editor-exit-message-101 status_101');
- });
- });
-
-
- describe('show answer button', function() {
-
- const radioButtonProblemHtml = readFixtures('radiobutton_problem.html');
- const checkboxProblemHtml = readFixtures('checkbox_problem.html');
-
- beforeEach(function() {
- this.problem = new Problem($('.xblock-student_view'));
-
- this.checkAssertionsAfterClickingAnotherOption = () => {
- // verify that 'show answer button is no longer disabled'
- expect(this.problem.el.find('.show').attr('disabled')).not.toEqual('disabled');
-
- // verify that displayed answer disappears
- expect(this.problem.el.find('div.choicegroup')).not.toHaveClass('choicegroup_correct');
-
- // verify that radio/checkbox label has no span having class '.status.correct'
- expect(this.problem.el.find('div.choicegroup')).not.toHaveAttr('span.status.correct');
- };
- });
-
- it('should become enabled after a radiobutton is selected', function() {
- $('#input_example_1').replaceWith(radioButtonProblemHtml);
- // assume that 'ShowAnswer' button is clicked,
- // clicking make it disabled.
- this.problem.el.find('.show').attr('disabled', 'disabled');
- // bind click event to input fields
- this.problem.submitAnswersAndSubmitButton(true);
- // selects option 2
- $('#input_1_1_2').attr('checked', true).trigger('click');
- this.checkAssertionsAfterClickingAnotherOption();
- });
-
- it('should become enabled after a checkbox is selected', function() {
- $('#input_example_1').replaceWith(checkboxProblemHtml);
- this.problem.el.find('.show').attr('disabled', 'disabled');
- this.problem.submitAnswersAndSubmitButton(true);
- $('#input_1_1_2').click();
- this.checkAssertionsAfterClickingAnotherOption();
- });
- });
-});
diff --git a/xmodule/js/spec/capa/imageinput_spec.js b/xmodule/js/spec/capa/imageinput_spec.js
deleted file mode 100644
index 133424caeaef..000000000000
--- a/xmodule/js/spec/capa/imageinput_spec.js
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * "Beware of bugs in the above code; I have only proved it correct, not tried
- * it."
- *
- * ~ Donald Knuth
- */
-
-// eslint-disable-next-line no-shadow-restricted-names
-(function($, ImageInput, undefined) {
- describe('ImageInput', function() {
- var state;
-
- beforeEach(function() {
- var $el;
-
- loadFixtures('imageinput.html');
- $el = $('#imageinput_12345');
-
- $el.append(createTestImage('cross_12345', 300, 400, 'red'));
-
- state = new ImageInput('12345');
- });
-
- it('initialization', function() {
- // Check that object's properties are present, and that the DOM
- // elements they reference exist.
- expect(state.el).toBeDefined();
- expect(state.el).toExist();
-
- expect(state.crossEl).toBeDefined();
- expect(state.crossEl).toExist();
-
- expect(state.inputEl).toBeDefined();
- expect(state.inputEl).toExist();
-
- expect(state.el).toHandle('click');
- });
-
- it('cross becomes visible after first click', function() {
- expect(state.crossEl.css('visibility')).toBe('hidden');
-
- state.el.click();
-
- expect(state.crossEl.css('visibility')).toBe('visible');
- });
-
- it('coordinates are updated [offsetX is set]', function() {
- var event, posX, posY, cssLeft, cssTop;
-
- // Set up of 'click' event.
- event = jQuery.Event(
- 'click',
- {offsetX: 35.3, offsetY: 42.7}
- );
-
- // Calculating the expected coordinates.
- posX = event.offsetX;
- posY = event.offsetY;
-
- // Triggering 'click' event.
- jQuery(state.el).trigger(event);
-
- // Getting actual (new) coordinates, and testing them against the
- // expected.
- cssLeft = stripPx(state.crossEl.css('left'));
- cssTop = stripPx(state.crossEl.css('top'));
-
- expect(cssLeft).toBeCloseTo(posX - 15, 1);
- expect(cssTop).toBeCloseTo(posY - 15, 1);
- expect(state.inputEl.val()).toBe(
- '[' + Math.round(posX) + ',' + Math.round(posY) + ']'
- );
- });
-
- it('coordinates are updated [offsetX is NOT set]', function() {
- var offset = state.el.offset(),
- event, posX, posY, cssLeft, cssTop;
-
- // Set up of 'click' event.
- event = jQuery.Event(
- 'click',
- {
- offsetX: undefined,
- offsetY: undefined,
- pageX: 35.3,
- pageY: 42.7
- }
- );
-
- // Calculating the expected coordinates.
- posX = event.pageX - offset.left;
- posY = event.pageY - offset.top;
-
- // Triggering 'click' event.
- jQuery(state.el).trigger(event);
-
- // Getting actual (new) coordinates, and testing them against the
- // expected.
- cssLeft = stripPx(state.crossEl.css('left'));
- cssTop = stripPx(state.crossEl.css('top'));
-
- expect(cssLeft).toBeCloseTo(posX - 15, 1);
- expect(cssTop).toBeCloseTo(posY - 15, 1);
- expect(state.inputEl.val()).toBe(
- '[' + Math.round(posX) + ',' + Math.round(posY) + ']'
- );
- });
- });
-
- // Instead of storing an image, and then including it in the template via
- // the tag, we will generate one on the fly.
- //
- // Create a simple image from a canvas. The canvas is filled by a colored
- // rectangle.
- function createTestImage(id, width, height, fillStyle) {
- var canvas, ctx, img;
-
- canvas = document.createElement('canvas');
- canvas.width = width;
- canvas.height = height;
-
- ctx = canvas.getContext('2d');
- ctx.fillStyle = fillStyle;
- ctx.fillRect(0, 0, width, height);
-
- img = document.createElement('img');
- img.src = canvas.toDataURL('image/png');
- img.id = id;
-
- return img;
- }
-
- // Strip the trailing 'px' substring from a CSS string containing the
- // `left` and `top` properties of an element's style.
- function stripPx(str) {
- return str.substring(0, str.length - 2);
- }
-}).call(this, window.jQuery, window.ImageInput);
diff --git a/xmodule/js/spec/video/async_process_spec.js b/xmodule/js/spec/video/async_process_spec.js
deleted file mode 100644
index b74579db3914..000000000000
--- a/xmodule/js/spec/video/async_process_spec.js
+++ /dev/null
@@ -1,81 +0,0 @@
-(function(require) {
- require(
- ['video/00_async_process.js'],
- function(AsyncProcess) {
- var getArrayNthLength = function(n, multiplier) {
- var result = [],
- mul = multiplier || 1;
-
- for (var i = 0; i < n; i++) {
- result[i] = i * mul;
- }
-
- return result;
- },
- items = getArrayNthLength(1000);
-
- describe('AsyncProcess', function() {
- it('Array is processed successfully', function(done) {
- var processedArray,
- expectedArray = getArrayNthLength(1000, 2),
- process = function(item) {
- return 2 * item;
- };
-
- AsyncProcess.array(items, process).done(function(result) {
- processedArray = result;
- });
-
- jasmine.waitUntil(function() {
- return processedArray;
- }).then(function() {
- expect(processedArray).toEqual(expectedArray);
- }).always(done);
- });
-
- it('If non-array is passed, error callback is called', function(done) {
- var isError,
- process = function() {};
-
- AsyncProcess.array('string', process).fail(function() {
- isError = true;
- });
-
- jasmine.waitUntil(function() {
- return isError;
- }).then(function() {
- expect(isError).toBeTruthy();
- }).always(done);
- });
-
- it('If an empty array is passed, returns initial array', function(done) {
- var processedArray,
- process = function() {};
-
- AsyncProcess.array([], process).done(function(result) {
- processedArray = result;
- });
-
- jasmine.waitUntil(function() {
- return processedArray;
- }).then(function() {
- expect(processedArray).toEqual([]);
- }).always(done);
- });
-
- it('If no process function passed, returns initial array', function(done) {
- var processedArray;
-
- AsyncProcess.array(items).done(function(result) {
- processedArray = result;
- });
-
- jasmine.waitUntil(function() {
- return processedArray;
- }).then(function() {
- expect(processedArray).toEqual(items);
- }).always(done);
- });
- });
- });
-}(require));
diff --git a/xmodule/js/spec/video/completion_spec.js b/xmodule/js/spec/video/completion_spec.js
deleted file mode 100644
index 350d97f54d9c..000000000000
--- a/xmodule/js/spec/video/completion_spec.js
+++ /dev/null
@@ -1,89 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoPlayer completion', function() {
- var state, oldOTBD, completionAjaxCall;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- state = jasmine.initializePlayer({
- recordedYoutubeIsAvailable: true,
- completionEnabled: true,
- publishCompletionUrl: 'https://example.com/publish_completion_url'
- });
- state.completionHandler.completeAfterTime = 20;
-
- completionAjaxCall = {
- url: state.config.publishCompletionUrl,
- type: 'POST',
- contentType: 'application/json',
- dataType: 'json',
- data: JSON.stringify({completion: 1.0}),
- success: jasmine.any(Function),
- error: jasmine.any(Function)
- };
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- });
-
- it('calls the completion api when marking an object complete', function() {
- spyOnEvent(state.el, 'complete');
- state.completionHandler.markCompletion(Date.now());
- expect($.ajax).toHaveBeenCalledWith(completionAjaxCall);
- expect('complete').toHaveBeenTriggeredOn(state.el);
- expect(state.completionHandler.isComplete).toEqual(true);
- });
-
- it('calls the completion api on the LMS when the time updates', function() {
- spyOn(state.completionHandler, 'markCompletion').and.callThrough();
- state.el.trigger('timeupdate', 24.0);
- expect(state.completionHandler.markCompletion).toHaveBeenCalled();
- state.completionHandler.markCompletion.calls.reset();
- // But the handler is not called again after the block is completed.
- state.el.trigger('timeupdate', 30.0);
- expect(state.completionHandler.markCompletion).not.toHaveBeenCalled();
- });
-
- it('does not call the completion api on the LMS when the video is loaded but not seen', function() {
- spyOn(window, 'VerticalStudentView').and.callThrough();
- // The VerticalStudentView object is created to kick off the function that checks if
- // each vertical is completable by viewing, and, if so, sends an ajax call to mark completion
- // eslint-disable-next-line no-new
- new window.VerticalStudentView(null, '#video_example');
- expect(window.VerticalStudentView).toHaveBeenCalled();
- expect($.ajax).not.toHaveBeenCalledWith(completionAjaxCall);
- });
-
- it('calls the completion api on the LMS when the video ends', function() {
- spyOn(state.completionHandler, 'markCompletion').and.callThrough();
- state.el.trigger('ended');
- expect(state.completionHandler.markCompletion).toHaveBeenCalled();
- });
-
- it('calls the completion api if the video is age restricted', function() {
- spyOn(state, 'youtubeId').and.returnValue('fakeYouTubeID');
- spyOn(state.completionHandler, 'markCompletion').and.callThrough();
- state.metadata = {fakeYouTubeID: {contentRating: {}}};
-
- // Check metadata once with no content rating and it should not be marked complete
- state.el.trigger('metadata_received');
- expect(state.completionHandler.markCompletion).not.toHaveBeenCalled();
-
- // But with age restricted rating, it will be completed immediately
- state.metadata.fakeYouTubeID.contentRating.ytRating = 'ytAgeRestricted';
- state.el.trigger('metadata_received');
- expect(state.completionHandler.markCompletion).toHaveBeenCalled();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/events_spec.js b/xmodule/js/spec/video/events_spec.js
deleted file mode 100644
index 40566a77a443..000000000000
--- a/xmodule/js/spec/video/events_spec.js
+++ /dev/null
@@ -1,104 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('VideoPlayer Events', function() {
- var state, oldOTBD;
-
- describe('HTML5', function() {
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it('initialize', function(done) {
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-initialized');
- }).then(function() {
- expect('initialize').not.toHaveBeenTriggeredOn('.video');
- }).always(done);
- });
-
- it('ready', function(done) {
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-initialized');
- }).then(function() {
- expect('ready').not.toHaveBeenTriggeredOn('.video');
- }).always(done);
- });
-
- it('play', function() {
- state.videoPlayer.play();
- expect('play').not.toHaveBeenTriggeredOn('.video');
- });
-
- it('pause', function() {
- state.videoPlayer.play();
- state.videoPlayer.pause();
- expect('pause').not.toHaveBeenTriggeredOn('.video');
- });
-
- it('volumechange', function() {
- state.videoPlayer.onVolumeChange(60);
-
- expect('volumechange').not.toHaveBeenTriggeredOn('.video');
- });
-
- it('speedchange', function() {
- state.videoPlayer.onSpeedChange('2.0');
-
- expect('speedchange').not.toHaveBeenTriggeredOn('.video');
- });
-
- it('seek', function() {
- state.videoPlayer.onCaptionSeek({
- time: 1,
- type: 'any'
- });
-
- expect('seek').not.toHaveBeenTriggeredOn('.video');
- });
-
- it('ended', function() {
- state.videoPlayer.onEnded();
-
- expect('ended').not.toHaveBeenTriggeredOn('.video');
- });
- });
-
- describe('YouTube', function() {
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- state = jasmine.initializePlayerYouTube();
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it('qualitychange', function() {
- state.videoPlayer.onPlaybackQualityChange();
-
- expect('qualitychange').not.toHaveBeenTriggeredOn('.video');
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/general_spec.js b/xmodule/js/spec/video/general_spec.js
deleted file mode 100644
index 4f9fb277631e..000000000000
--- a/xmodule/js/spec/video/general_spec.js
+++ /dev/null
@@ -1,239 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('Video', function() {
- afterEach(function() {
- $('source').remove();
- window.VideoState = {};
- window.VideoState.id = {};
- window.YT = jasmine.YT;
- });
-
- describe('constructor', function() {
- describe('YT', function() {
- var state;
-
- beforeEach(function() {
- loadFixtures('video.html');
- $.cookie.and.returnValue('0.50');
- });
-
- describe('by default', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube('video_html5.html');
- });
-
- afterEach(function() {
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it('check videoType', function() {
- expect(state.videoType).toEqual('youtube');
- });
-
- it('set the elements', function() {
- expect(state.el).toEqual($('#video_id'));
- });
-
- it('parse the videos', function() {
- expect(state.videos).toEqual({
- '0.50': '7tqY6eQzVhE',
- '1.0': 'cogebirgzzM',
- '1.50': 'abcdefghijkl'
- });
- });
-
- it('parse available video speeds', function() {
- expect(state.speeds).toEqual(['0.50', '1.0', '1.50']);
- });
-
- it('set current video speed via cookie', function() {
- expect(state.speed).toEqual('1.50');
- });
- });
- });
-
- describe('HTML5', function() {
- var state;
-
- beforeEach(function() {
- $.cookie.and.returnValue('0.75');
- state = jasmine.initializePlayer('video_html5.html');
- });
-
- afterEach(function() {
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- describe('by default', function() {
- it('check videoType', function() {
- expect(state.videoType).toEqual('html5');
- });
-
- it('set the elements', function() {
- expect(state.el).toEqual($('#video_id'));
- });
-
- it('doesn\'t have `videos` dictionary', function() {
- expect(state.videos).toBeUndefined();
- });
-
- it('parse available video speeds', function() {
- var speeds = jasmine.stubbedHtml5Speeds;
-
- expect(state.speeds).toEqual(speeds);
- });
-
- it('set current video speed via cookie', function() {
- expect(state.speed).toEqual(1.5);
- });
- });
-
- // Note that the loading of stand alone HTML5 player API is
- // handled by Require JS. When state.videoPlayer is created,
- // the stand alone HTML5 player object is already loaded, so no
- // further testing in that case is required.
- describe('HTML5 API is available', function() {
- it('create the Video Player', function() {
- expect(state.videoPlayer.player).not.toBeUndefined();
- });
- });
- });
- });
-
- describe('YouTube API is not loaded', function() {
- var state;
- beforeEach(function() {
- window.YT = undefined;
- state = jasmine.initializePlayerYouTube();
- });
-
- afterEach(function() {
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it('callback, to be called after YouTube API loads, exists and is called', function(done) {
- window.YT = jasmine.YT;
- // Call the callback that must be called when YouTube API is
- // loaded. By specification.
- window.onYouTubeIframeAPIReady();
- jasmine.waitUntil(function() {
- return state.youtubeApiAvailable === true;
- }).done(function() {
- // If YouTube API is not loaded, then the code will should create
- // a global callback that will be called by API once it is loaded.
- expect(window.onYouTubeIframeAPIReady).not.toBeUndefined();
- }).always(done);
- });
- });
-
- describe('checking start and end times', function() {
- var state;
- var miniTestSuite = [
- {
- itDescription: 'both times are proper',
- data: {start: 12, end: 24},
- expectData: {start: 12, end: 24}
- },
- {
- itDescription: 'start time is invalid',
- data: {start: '', end: 24},
- expectData: {start: 0, end: 24}
- },
- {
- itDescription: 'end time is invalid',
- data: {start: 12, end: ''},
- expectData: {start: 12, end: null}
- },
- {
- itDescription: 'start time is less than 0',
- data: {start: -12, end: 24},
- expectData: {start: 0, end: 24}
- },
- {
- itDescription: 'start time is greater than end time',
- data: {start: 42, end: 24},
- expectData: {start: 42, end: null}
- }
- ];
-
- afterEach(function() {
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- $.each(miniTestSuite, function(index, test) {
- itFabrique(test.itDescription, test.data, test.expectData);
- });
-
- // eslint-disable-next-line no-useless-return
- return;
-
- function itFabrique(itDescription, data, expectData) {
- it(itDescription, function() {
- state = jasmine.initializePlayer('video.html', {
- start: data.start,
- end: data.end
- });
-
- expect(state.config.startTime).toBe(expectData.start);
- expect(state.config.endTime).toBe(expectData.end);
- });
- }
- });
-
- // Disabled 11/25/13 due to flakiness in master
- xdescribe('multiple YT on page', function() {
- var state1, state2, state3;
-
- beforeEach(function() {
- loadFixtures('video_yt_multiple.html');
-
- spyOn($, 'ajaxWithPrefix');
-
- $.ajax.calls.length = 0;
- $.ajaxWithPrefix.calls.length = 0;
-
- // Because several other tests have run, the variable
- // that stores the value of the first ajax request must be
- // cleared so that we test a pristine state of the video
- // module.
- Video.clearYoutubeXhr();
-
- state1 = new Video('#example1');
- state2 = new Video('#example2');
- state3 = new Video('#example3');
- });
-
- it(
- 'check for YT availability is performed only once',
- function() {
- var numAjaxCalls = 0;
-
- // Total ajax calls made.
- numAjaxCalls = $.ajax.calls.length;
-
- // Subtract ajax calls to get captions via
- // state.videoCaption.fetchCaption() function.
- numAjaxCalls -= $.ajaxWithPrefix.calls.length;
-
- // Subtract ajax calls to get metadata for each video via
- // state.getVideoMetadata() function.
- numAjaxCalls -= 3;
-
- // Subtract ajax calls to log event 'pause_video' via
- // state.videoPlayer.log() function.
- numAjaxCalls -= 3;
-
- // This should leave just one call. It was made to check
- // for YT availability. This is done in state.initialize()
- // function. SPecifically, with the statement
- //
- // this.youtubeXhr = this.getVideoMetadata();
- expect(numAjaxCalls).toBe(1);
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/html5_video_spec.js b/xmodule/js/spec/video/html5_video_spec.js
deleted file mode 100644
index f7ff17c05349..000000000000
--- a/xmodule/js/spec/video/html5_video_spec.js
+++ /dev/null
@@ -1,384 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('Video HTML5Video', function() {
- var STATUS = window.STATUS;
- var state,
- oldOTBD,
- playbackRates = [0.75, 1.0, 1.25, 1.5, 2.0],
- describeInfo,
- POSTER_URL = '/media/video-images/poster.png';
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
-
- state = jasmine.initializePlayer('video_html5.html');
- });
-
- afterEach(function() {
- state.storage.clear();
- state.videoPlayer.destroy();
- $.fn.scrollTo.calls.reset();
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- });
-
- describeInfo = new jasmine.DescribeInfo('on non-Touch devices ', function() {
- beforeEach(function() {
- state.videoPlayer.player.config.events.onReady = jasmine.createSpy('onReady');
- });
-
- describe('events:', function() {
- beforeEach(function() {
- spyOn(state.videoPlayer.player, 'callStateChangeCallback').and.callThrough();
- });
-
- describe('[click]', function() {
- describe('when player is paused', function() {
- beforeEach(function() {
- spyOn(state.videoPlayer.player.video, 'play').and.callThrough();
- state.videoPlayer.player.playerState = STATUS.PAUSED;
- $(state.videoPlayer.player.videoEl).trigger('click');
- });
-
- it('native play event was called', function() {
- expect(state.videoPlayer.player.video.play).toHaveBeenCalled();
- });
-
- it('player state was changed', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).always(done);
- });
- });
-
- describe('[player is playing]', function() {
- beforeEach(function() {
- spyOn(state.videoPlayer.player.video, 'pause').and.callThrough();
- state.videoPlayer.player.playerState = STATUS.PLAYING;
- $(state.videoPlayer.player.videoEl).trigger('click');
- });
-
- it('native event was called', function() {
- expect(state.videoPlayer.player.video.pause).toHaveBeenCalled();
- });
-
- it('player state was changed', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PLAYING;
- }).then(function() {
- expect(state.videoPlayer.player.getPlayerState())
- .toBe(STATUS.PAUSED);
- }).always(done);
- });
-
- it('callback was not called', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PLAYING;
- }).then(function() {
- expect(state.videoPlayer.player.callStateChangeCallback)
- .not.toHaveBeenCalled();
- }).always(done);
- });
- });
- });
-
- describe('[play]', function() {
- beforeEach(function() {
- spyOn(state.videoPlayer.player.video, 'play').and.callThrough();
- state.videoPlayer.player.playerState = STATUS.PAUSED;
- state.videoPlayer.player.playVideo();
- });
-
- it('native event was called', function() {
- expect(state.videoPlayer.player.video.play).toHaveBeenCalled();
- });
-
- it('player state was changed', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PAUSED;
- }).then(function() {
- expect([STATUS.BUFFERING, STATUS.PLAYING]).toContain(
- state.videoPlayer.player.getPlayerState()
- );
- }).always(done);
- });
-
- it('callback was called', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PAUSED;
- }).then(function() {
- expect(state.videoPlayer.player.callStateChangeCallback)
- .toHaveBeenCalled();
- }).always(done);
- });
- });
-
- describe('[pause]', function() {
- beforeEach(function(done) {
- spyOn(state.videoPlayer.player.video, 'pause').and.callThrough();
- state.videoPlayer.player.playerState = STATUS.UNSTARTED;
- state.videoPlayer.player.playVideo();
-
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.UNSTARTED;
- }).done(done);
-
- state.videoPlayer.player.pauseVideo();
- });
-
- it('native event was called', function() {
- expect(state.videoPlayer.player.video.pause).toHaveBeenCalled();
- });
-
- it('player state was changed', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PLAYING;
- }).then(function() {
- expect(state.videoPlayer.player.getPlayerState())
- .toBe(STATUS.PAUSED);
- }).always(done);
- });
-
- it('callback was called', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.PLAYING;
- }).then(function() {
- expect(state.videoPlayer.player.callStateChangeCallback)
- .toHaveBeenCalled();
- }).always(done);
- });
- });
-
- describe('[loadedmetadata]', function() {
- it(
- 'player state was changed, start/end was defined, '
- + 'onReady called', function(done) {
- jasmine.fireEvent(state.videoPlayer.player.video, 'loadedmetadata');
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.UNSTARTED;
- }).then(function() {
- expect(state.videoPlayer.player.getPlayerState())
- .toBe(STATUS.PAUSED);
- expect(state.videoPlayer.player.video.currentTime).toBe(0);
- expect(state.videoPlayer.player.config.events.onReady)
- .toHaveBeenCalled();
- }).always(done);
- });
- });
-
- describe('[ended]', function() {
- beforeEach(function(done) {
- state.videoPlayer.player.playVideo();
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.UNSTARTED;
- }).done(done);
- });
-
- it('player state was changed', function() {
- jasmine.fireEvent(state.videoPlayer.player.video, 'ended');
- expect(state.videoPlayer.player.getPlayerState()).toBe(STATUS.ENDED);
- });
-
- it('callback was called', function() {
- jasmine.fireEvent(state.videoPlayer.player.video, 'ended');
- expect(state.videoPlayer.player.callStateChangeCallback)
- .toHaveBeenCalled();
- });
- });
- });
-
- describe('methods', function() {
- var volume, seek, duration, playbackRate;
-
- beforeEach(function() {
- volume = state.videoPlayer.player.video.volume;
- });
-
- it('pauseVideo', function() {
- spyOn(state.videoPlayer.player.video, 'pause').and.callThrough();
- state.videoPlayer.player.pauseVideo();
- expect(state.videoPlayer.player.video.pause).toHaveBeenCalled();
- });
-
- describe('seekTo', function() {
- it('set new correct value', function(done) {
- state.videoPlayer.player.playVideo();
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).then(function() {
- state.videoPlayer.player.seekTo(2);
- expect(state.videoPlayer.player.getCurrentTime()).toBe(2);
- }).done(done);
- });
-
- it('set new incorrect values', function() {
- // eslint-disable-next-line no-shadow
- var seek = state.videoPlayer.player.video.currentTime;
- state.videoPlayer.player.seekTo(-50);
- expect(state.videoPlayer.player.getCurrentTime()).toBe(seek);
- state.videoPlayer.player.seekTo('5');
- expect(state.videoPlayer.player.getCurrentTime()).toBe(seek);
- state.videoPlayer.player.seekTo(500000);
- expect(state.videoPlayer.player.getCurrentTime()).toBe(seek);
- });
- });
-
- describe('setVolume', function() {
- it('set new correct value', function() {
- state.videoPlayer.player.setVolume(50);
- expect(state.videoPlayer.player.getVolume()).toBe(50 * 0.01);
- });
-
- it('set new incorrect values', function() {
- state.videoPlayer.player.setVolume(-50);
- expect(state.videoPlayer.player.getVolume()).toBe(volume);
- state.videoPlayer.player.setVolume('5');
- expect(state.videoPlayer.player.getVolume()).toBe(volume);
- state.videoPlayer.player.setVolume(500000);
- expect(state.videoPlayer.player.getVolume()).toBe(volume);
- });
- });
-
- it('getCurrentTime', function(done) {
- state.videoPlayer.player.playVideo();
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).then(function() {
- state.videoPlayer.player.video.currentTime = 3;
- expect(state.videoPlayer.player.getCurrentTime())
- .toBe(state.videoPlayer.player.video.currentTime);
- }).done(done);
- });
-
- it('playVideo', function() {
- spyOn(state.videoPlayer.player.video, 'play').and.callThrough();
- state.videoPlayer.player.playVideo();
- expect(state.videoPlayer.player.video.play).toHaveBeenCalled();
- });
-
- it('getPlayerState', function() {
- state.videoPlayer.player.playerState = STATUS.PLAYING;
- expect(state.videoPlayer.player.getPlayerState()).toBe(STATUS.PLAYING);
- state.videoPlayer.player.playerState = STATUS.ENDED;
- expect(state.videoPlayer.player.getPlayerState()).toBe(STATUS.ENDED);
- });
-
- it('getVolume', function() {
- // eslint-disable-next-line no-multi-assign
- volume = state.videoPlayer.player.video.volume = 0.5;
- expect(state.videoPlayer.player.getVolume()).toBe(volume);
- });
-
- it('getDuration', function(done) {
- state.videoPlayer.player.playVideo();
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).then(function() {
- duration = state.videoPlayer.player.video.duration;
- expect(state.videoPlayer.player.getDuration()).toBe(duration);
- }).always(done);
- });
-
- describe('setPlaybackRate', function() {
- it('set a slow value', function() {
- playbackRate = 0.75;
- state.videoPlayer.player.setPlaybackRate(playbackRate);
- expect(state.videoPlayer.player.video.playbackRate).toBe(playbackRate);
- });
-
- it('set a fast value', function() {
- playbackRate = 2.0;
- state.videoPlayer.player.setPlaybackRate(playbackRate);
- expect(state.videoPlayer.player.video.playbackRate).toBe(playbackRate);
- });
-
- it('set NaN value', function() {
- var oldPlaybackRate = state.videoPlayer.player.video.playbackRate;
-
- // When we try setting the playback rate to some
- // non-numerical value, nothing should happen.
- playbackRate = NaN;
- state.videoPlayer.player.setPlaybackRate(playbackRate);
- expect(state.videoPlayer.player.video.playbackRate)
- .toBe(oldPlaybackRate);
- });
- });
-
- it('getAvailablePlaybackRates', function() {
- expect(state.videoPlayer.player.getAvailablePlaybackRates())
- .toEqual(playbackRates);
- });
-
- it('_getLogs', function(done) {
- state.videoPlayer.player.playVideo();
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).then(function() {
- var logs = state.videoPlayer.player._getLogs();
- expect(logs).toEqual(jasmine.any(Array));
- expect(logs.length).toBeGreaterThan(0);
- }).done(done);
- });
- });
-
- describe('poster', function() {
- it('has url in player config', function() {
- expect(state.videoPlayer.player.config.poster).toEqual(POSTER_URL);
- expect(state.videoPlayer.player.videoEl).toHaveAttrs({
- poster: POSTER_URL
- });
- });
- });
- });
-
- describe('non-hls encoding', function() {
- beforeEach(function(done) {
- state = jasmine.initializePlayer('video_html5.html');
- done();
- });
- jasmine.getEnv().describe(describeInfo.description, describeInfo.specDefinitions);
- });
-
- describe('hls encoding', function() {
- beforeEach(function(done) {
- state = jasmine.initializeHLSPlayer();
- done();
- });
- jasmine.getEnv().describe(describeInfo.description, describeInfo.specDefinitions);
- });
-
- it('does not show poster for html5 video if url is not present', function() {
- state = jasmine.initializePlayer(
- 'video_html5.html',
- {
- poster: null
- }
- );
- expect(state.videoPlayer.player.config.poster).toEqual(null);
- expect(state.videoPlayer.player.videoEl).not.toHaveAttr('poster');
- });
-
- it('does not show poster for hls video if url is not present', function() {
- state = jasmine.initializePlayer(
- 'video_hls.html',
- {
- poster: null
- }
- );
- expect(state.videoPlayer.player.config.poster).toEqual(null);
- expect(state.videoPlayer.player.videoEl).not.toHaveAttr('poster');
- });
-
- it('native controls are used on iPhone', function() {
- window.onTouchBasedDevice.and.returnValue(['iPhone']);
-
- state = jasmine.initializePlayer('video_html5.html');
-
- state.videoPlayer.player.config.events.onReady = jasmine.createSpy('onReady');
-
- expect($('video')).toHaveAttr('controls');
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/initialize_spec.js b/xmodule/js/spec/video/initialize_spec.js
deleted file mode 100644
index 0ce88aa2758a..000000000000
--- a/xmodule/js/spec/video/initialize_spec.js
+++ /dev/null
@@ -1,330 +0,0 @@
-(function(require) {
- 'use strict';
-
- require(
- ['video/01_initialize.js'],
- function(Initialize) {
- describe('Initialize', function() {
- var state = {};
-
- afterEach(function() {
- state = {};
- });
-
- describe('getCurrentLanguage', function() {
- var msg;
-
- beforeEach(function() {
- state.config = {};
- state.config.transcriptLanguages = {
- de: 'German',
- en: 'English',
- uk: 'Ukrainian'
- };
- });
-
- it('returns current language', function() {
- var expected;
-
- state.lang = 'de';
- expected = Initialize.prototype.getCurrentLanguage.call(state);
- expect(expected).toBe('de');
- });
-
- msg = 'returns `en`, if language isn\'t available for the video';
- it(msg, function() {
- var expected;
-
- state.lang = 'zh';
- expected = Initialize.prototype.getCurrentLanguage.call(state);
- expect(expected).toBe('en');
- });
-
- msg = 'returns any available language, if current and `en` '
- + 'languages aren\'t available for the video';
- it(msg, function() {
- var expected;
-
- state.lang = 'zh';
- state.config.transcriptLanguages = {
- de: 'German',
- uk: 'Ukrainian'
- };
- expected = Initialize.prototype.getCurrentLanguage.call(state);
- expect(expected).toBe('uk');
- });
-
- it('returns `null`, if transcript unavailable', function() {
- var expected;
-
- state.lang = 'zh';
- state.config.transcriptLanguages = {};
- expected = Initialize.prototype.getCurrentLanguage.call(state);
- expect(expected).toBeNull();
- });
- });
-
- describe('getDuration', function() {
- beforeEach(function() {
- state = {
- speed: '1.50',
- metadata: {
- testId: {
- duration: 'PT6M40S'
- },
- videoId: {
- duration: 'PT1M40S'
- }
- },
- videos: {
- '1.0': 'testId',
- '1.50': 'videoId'
- },
- youtubeId: Initialize.prototype.youtubeId,
- isFlashMode: jasmine.createSpy().and.returnValue(false)
- };
- });
-
- it('returns duration for the 1.0 speed if speed is not 1.0', function() {
- var expected;
-
- state.speed = '1.50';
- expected = Initialize.prototype.getDuration.call(state);
-
- expect(expected).toEqual(400);
- });
-
- describe('Flash mode', function() {
- it('returns duration for current video', function() {
- var expected;
-
- state.isFlashMode.and.returnValue(true);
- expected = Initialize.prototype.getDuration.call(state);
-
- expect(expected).toEqual(100);
- });
-
- it('returns duration for the 1.0 speed as a fall-back', function() {
- var expected;
-
- state.isFlashMode.and.returnValue(true);
- state.speed = '2.0';
- expected = Initialize.prototype.getDuration.call(state);
-
- expect(expected).toEqual(400);
- });
- });
- });
-
- describe('youtubeId', function() {
- beforeEach(function() {
- state = {
- speed: '1.50',
- videos: {
- '0.50': '7tqY6eQzVhE',
- '1.0': 'cogebirgzzM',
- '1.50': 'abcdefghijkl'
- },
- isFlashMode: jasmine.createSpy().and.returnValue(false)
- };
- });
-
- describe('with speed', function() {
- it('return the video id for given speed', function() {
- $.each(state.videos, function(speed, videoId) {
- var expected = Initialize.prototype.youtubeId.call(
- state, speed
- );
-
- expect(videoId).toBe(expected);
- });
- });
- });
-
- describe('without speed for flash mode', function() {
- it('return the video id for current speed', function() {
- var expected;
-
- state.isFlashMode.and.returnValue(true);
- expected = Initialize.prototype.youtubeId.call(state);
-
- expect(expected).toEqual('abcdefghijkl');
- });
- });
-
- describe('without speed for youtube html5 mode', function() {
- it('return the video id for 1.0x speed', function() {
- var expected = Initialize.prototype.youtubeId.call(state);
-
- expect(expected).toEqual('cogebirgzzM');
- });
- });
-
- describe('speed is absent in the list of video speeds', function() {
- it('return the video id for 1.0x speed', function() {
- var expected = Initialize.prototype.youtubeId.call(state, '0.0');
-
- expect(expected).toEqual('cogebirgzzM');
- });
- });
- });
-
- describe('setSpeed', function() {
- describe('YT', function() {
- beforeEach(function() {
- state = {
- speeds: ['0.25', '0.50', '1.0', '1.50', '2.0'],
- storage: jasmine.createSpyObj('storage', ['setItem'])
- };
- });
-
- it('check mapping', function() {
- var map = {
- 0.75: '0.50',
- 1.25: '1.50'
- };
-
- $.each(map, function(key, expected) {
- Initialize.prototype.setSpeed.call(state, key);
- expect(state.speed).toBe(parseFloat(expected));
- });
- });
- });
-
- describe('HTML5', function() {
- beforeEach(function() {
- state = {
- speeds: ['0.75', '1.0', '1.25', '1.50', '2.0'],
- storage: jasmine.createSpyObj('storage', ['setItem'])
- };
- });
-
- describe('when 0.75 speed is available', function() {
- beforeEach(function() {
- Initialize.prototype.setSpeed.call(state, '0.75');
- });
-
- it('set new speed', function() {
- expect(state.speed).toEqual(0.75);
- });
- });
-
- describe('when 2.0 speed is available', function() {
- beforeEach(function() {
- Initialize.prototype.setSpeed.call(state, '2.0');
- });
-
- it('set new speed', function() {
- expect(state.speed).toEqual(2.0);
- });
- });
-
- describe('when new speed is not available', function() {
- beforeEach(function() {
- Initialize.prototype.setSpeed.call(state, '1.75');
- });
-
- it('set speed to 1.0x', function() {
- expect(state.speed).toEqual(1);
- });
- });
-
- it('check mapping', function() {
- var map = {
- 0.25: '0.75',
- '0.50': '0.75'
- };
-
- $.each(map, function(key, expected) {
- Initialize.prototype.setSpeed.call(state, key);
- expect(state.speed).toBe(parseFloat(expected));
- });
- });
- });
- });
-
- describe('setPlayerMode', function() {
- beforeEach(function() {
- state = {
- currentPlayerMode: 'flash'
- };
- });
-
- it('updates player mode', function() {
- var setPlayerMode = Initialize.prototype.setPlayerMode;
-
- setPlayerMode.call(state, 'html5');
- expect(state.currentPlayerMode).toBe('html5');
- setPlayerMode.call(state, 'flash');
- expect(state.currentPlayerMode).toBe('flash');
- });
-
- it('sets default mode if passed is not supported', function() {
- var setPlayerMode = Initialize.prototype.setPlayerMode;
-
- setPlayerMode.call(state, '77html77');
- expect(state.currentPlayerMode).toBe('html5');
- });
- });
-
- describe('getPlayerMode', function() {
- beforeEach(function() {
- state = {
- currentPlayerMode: 'flash'
- };
- });
-
- it('returns current player mode', function() {
- var getPlayerMode = Initialize.prototype.getPlayerMode,
- actual = getPlayerMode.call(state);
-
- expect(actual).toBe(state.currentPlayerMode);
- });
- });
-
- describe('isFlashMode', function() {
- it('returns `true` if player in `flash` mode', function() {
- var testState = {
- getPlayerMode: jasmine.createSpy().and.returnValue('flash')
- },
- isFlashMode = Initialize.prototype.isFlashMode,
- actual = isFlashMode.call(testState);
-
- expect(actual).toBeTruthy();
- });
-
- it('returns `false` if player is not in `flash` mode', function() {
- var testState = {
- getPlayerMode: jasmine.createSpy().and.returnValue('html5')
- },
- isFlashMode = Initialize.prototype.isFlashMode,
- actual = isFlashMode.call(testState);
-
- expect(actual).toBeFalsy();
- });
- });
-
- describe('isHtml5Mode', function() {
- it('returns `true` if player in `html5` mode', function() {
- var testState = {
- getPlayerMode: jasmine.createSpy().and.returnValue('html5')
- },
- isHtml5Mode = Initialize.prototype.isHtml5Mode,
- actual = isHtml5Mode.call(testState);
-
- expect(actual).toBeTruthy();
- });
-
- it('returns `false` if player is not in `html5` mode', function() {
- var testState = {
- getPlayerMode: jasmine.createSpy().and.returnValue('flash')
- },
- isHtml5Mode = Initialize.prototype.isHtml5Mode,
- actual = isHtml5Mode.call(testState);
-
- expect(actual).toBeFalsy();
- });
- });
- });
- });
-}(require));
diff --git a/xmodule/js/spec/video/iterator_spec.js b/xmodule/js/spec/video/iterator_spec.js
deleted file mode 100644
index 231daddff878..000000000000
--- a/xmodule/js/spec/video/iterator_spec.js
+++ /dev/null
@@ -1,105 +0,0 @@
-(function(require) {
- 'use strict';
-
- require(
- ['video/00_iterator.js'],
- function(Iterator) {
- describe('Iterator', function() {
- var list = ['a', 'b', 'c', 'd', 'e'],
- iterator;
-
- beforeEach(function() {
- iterator = new Iterator(list);
- });
-
- it('size contains correct list length', function() {
- expect(iterator.size).toBe(list.length);
- expect(iterator.lastIndex).toBe(list.length - 1);
- });
-
- describe('next', function() {
- describe('with passed `index`', function() {
- it('returns next item in the list', function() {
- expect(iterator.next(2)).toBe('d');
- expect(iterator.next(0)).toBe('b');
- });
-
- it('returns first item if index equal last item', function() {
- expect(iterator.next(4)).toBe('a');
- });
-
- it('returns next item if index is not valid', function() {
- expect(iterator.next(-4)).toBe('b'); // index < 0
- expect(iterator.next(100)).toBe('c'); // index > size
- expect(iterator.next('99')).toBe('d'); // incorrect Type
- });
- });
-
- describe('without passed `index`', function() {
- it('returns next item in the list', function() {
- expect(iterator.next()).toBe('b');
- expect(iterator.next()).toBe('c');
- });
-
- it('returns first item if index equal last item', function() {
- expect(iterator.next()).toBe('b');
- expect(iterator.next()).toBe('c');
- expect(iterator.next()).toBe('d');
- expect(iterator.next()).toBe('e');
- expect(iterator.next()).toBe('a');
- });
- });
- });
-
- describe('prev', function() {
- describe('with passed `index`', function() {
- it('returns previous item in the list', function() {
- expect(iterator.prev(3)).toBe('c');
- expect(iterator.prev(1)).toBe('a');
- });
-
- it('returns last item if index equal first item', function() {
- expect(iterator.prev(0)).toBe('e');
- });
-
- it('returns previous item if index is not valid', function() {
- expect(iterator.prev(-4)).toBe('e'); // index < 0
- expect(iterator.prev(100)).toBe('d'); // index > size
- expect(iterator.prev('99')).toBe('c'); // incorrect Type
- });
- });
-
- describe('without passed `index`', function() {
- it('returns previous item in the list', function() {
- expect(iterator.prev()).toBe('e');
- expect(iterator.prev()).toBe('d');
- });
-
- it('returns last item if index equal first item', function() {
- expect(iterator.prev()).toBe('e');
- });
- });
- });
-
- it('returns last item in the list', function() {
- expect(iterator.last()).toBe('e');
- });
-
- it('returns first item in the list', function() {
- expect(iterator.first()).toBe('a');
- });
-
- it('isEnd works correctly', function() {
- expect(iterator.isEnd()).toBeFalsy();
- iterator.next(); // => index 1
- expect(iterator.isEnd()).toBeFalsy();
- iterator.next(); // => index 2
- expect(iterator.isEnd()).toBeFalsy();
- iterator.next(); // => index 3
- expect(iterator.isEnd()).toBeFalsy();
- iterator.next(); // => index 4 == last
- expect(iterator.isEnd()).toBeTruthy();
- });
- });
- });
-}(require));
diff --git a/xmodule/js/spec/video/resizer_spec.js b/xmodule/js/spec/video/resizer_spec.js
deleted file mode 100644
index 583b5e7bb308..000000000000
--- a/xmodule/js/spec/video/resizer_spec.js
+++ /dev/null
@@ -1,270 +0,0 @@
-(function(require) {
- 'use strict';
-
- require(
- ['video/00_resizer.js', 'underscore'],
- function(Resizer, _) {
- describe('Resizer', function() {
- var html = [
- '',
- '
',
- 'Content',
- '
',
- '
'
- ].join(''),
- config, $container, $element;
-
- beforeEach(function() {
- setFixtures(html);
-
- $container = $('.rszr-wrapper');
- $element = $('.rszr-el');
- config = {
- container: $container,
- element: $element
- };
-
- spyOn(console, 'log');
- });
-
- it('When Initialize without required parameters, log message is shown',
- function() {
- // eslint-disable-next-line no-new
- new Resizer({ });
- expect(console.log).toHaveBeenCalled();
- }
- );
-
- it('`alignByWidthOnly` works correctly', function() {
- var resizer = new Resizer(config).alignByWidthOnly(),
- expectedWidth = $container.width(),
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
-
- it('`alignByHeightOnly` works correctly', function() {
- var resizer = new Resizer(config).alignByHeightOnly(),
- expectedHeight = $container.height(),
- realHeight = $element.height();
-
- expect(realHeight).toBe(expectedHeight);
- });
-
- it('`align` works correctly', function() {
- var resizer = new Resizer(config).align(),
- expectedHeight = $container.height(),
- realHeight = $element.height(),
- expectedWidth = 50,
- realWidth;
-
- // containerRatio >= elementRatio
- expect(realHeight).toBe(expectedHeight);
-
- // containerRatio < elementRatio
- $container.width(expectedWidth);
- resizer.align();
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
-
- it('`setMode` works correctly', function() {
- var resizer = new Resizer(config).setMode('height'),
- expectedHeight = $container.height(),
- realHeight = $element.height(),
- expectedWidth = 50,
- realWidth;
-
- // containerRatio >= elementRatio
- expect(realHeight).toBe(expectedHeight);
-
- // containerRatio < elementRatio
- $container.width(expectedWidth);
- resizer.setMode('width');
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
-
- it('`setElement` works correctly', function() {
- var $newElement,
- expectedHeight;
-
- $container.append('');
- $newElement = $('#Another-el');
- expectedHeight = $container.height();
-
- new Resizer(config).setElement($newElement).alignByHeightOnly();
- expect($element.height()).not.toBe(expectedHeight);
- expect($newElement.height()).toBe(expectedHeight);
- });
-
- describe('Callbacks', function() {
- var resizer,
- spiesList = [];
-
- beforeEach(function() {
- var spiesCount = _.range(3);
-
- spiesList = $.map(spiesCount, function() {
- return jasmine.createSpy();
- });
-
- resizer = new Resizer(config);
- });
-
- it('callbacks are called', function() {
- $.each(spiesList, function(index, spy) {
- resizer.callbacks.add(spy);
- });
-
- resizer.align();
-
- $.each(spiesList, function(index, spy) {
- expect(spy).toHaveBeenCalled();
- });
- });
-
- it('callback called just once', function() {
- resizer.callbacks.once(spiesList[0]);
-
- resizer
- .align()
- .alignByHeightOnly();
-
- expect(spiesList[0].calls.count()).toEqual(1);
- });
-
- it('all callbacks are removed', function() {
- $.each(spiesList, function(index, spy) {
- resizer.callbacks.add(spy);
- });
-
- resizer.callbacks.removeAll();
- resizer.align();
-
- $.each(spiesList, function(index, spy) {
- expect(spy).not.toHaveBeenCalled();
- });
- });
-
- it('specific callback is removed', function() {
- $.each(spiesList, function(index, spy) {
- resizer.callbacks.add(spy);
- });
-
- resizer.callbacks.remove(spiesList[1]);
- resizer.align();
-
- expect(spiesList[1]).not.toHaveBeenCalled();
- });
-
- it(
- 'Error message is shown when wrong argument type is passed',
- function() {
- var methods = ['add', 'once'],
- errorMessage = '[Video info]: TypeError: Argument is not a function.',
- arg = {};
-
- spyOn(console, 'error');
-
- $.each(methods, function(index, methodName) {
- resizer.callbacks[methodName](arg);
- expect(console.error).toHaveBeenCalledWith(errorMessage);
- // reset spy
- console.log.calls.reset();
- });
- });
- });
-
- describe('Delta', function() {
- var resizer;
-
- beforeEach(function() {
- resizer = new Resizer(config);
- });
-
- it('adding delta align correctly by height', function() {
- var delta = 100,
- expectedHeight = $container.height() + delta,
- realHeight;
-
- resizer
- .delta.add(delta, 'height')
- .setMode('height');
-
- realHeight = $element.height();
-
- expect(realHeight).toBe(expectedHeight);
- });
-
- it('adding delta align correctly by width', function() {
- var delta = 100,
- expectedWidth = $container.width() + delta,
- realWidth;
-
- resizer
- .delta.add(delta, 'width')
- .setMode('width');
-
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
-
- it('substract delta align correctly by height', function() {
- var delta = 100,
- expectedHeight = $container.height() - delta,
- realHeight;
-
- resizer
- .delta.substract(delta, 'height')
- .setMode('height');
-
- realHeight = $element.height();
-
- expect(realHeight).toBe(expectedHeight);
- });
-
- it('substract delta align correctly by width', function() {
- var delta = 100,
- expectedWidth = $container.width() - delta,
- realWidth;
-
- resizer
- .delta.substract(delta, 'width')
- .setMode('width');
-
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
-
- it('reset delta', function() {
- var delta = 100,
- expectedWidth = $container.width(),
- realWidth;
-
- resizer
- .delta.substract(delta, 'width')
- .delta.reset()
- .setMode('width');
-
- realWidth = $element.width();
-
- expect(realWidth).toBe(expectedWidth);
- });
- });
- });
- });
-}(require));
diff --git a/xmodule/js/spec/video/sjson_spec.js b/xmodule/js/spec/video/sjson_spec.js
deleted file mode 100644
index bbcd8878d999..000000000000
--- a/xmodule/js/spec/video/sjson_spec.js
+++ /dev/null
@@ -1,67 +0,0 @@
-(function(require) {
- require(
- ['video/00_sjson.js'],
- function(Sjson) {
- describe('Sjson', function() {
- var data = jasmine.stubbedCaption,
- sjson;
- var videoStops = [0, 3120, 6270, 8490, 21620, 24920];
- var OUT_OF_BOUNDS_STOP = 10024920;
-
- beforeEach(function() {
- sjson = new Sjson(data);
- });
-
- it('returns captions', function() {
- expect(sjson.getCaptions()).toEqual(data.text);
- });
-
- it('returns start times', function() {
- expect(sjson.getStartTimes()).toEqual(data.start);
- });
-
- it('returns correct length', function() {
- expect(sjson.getSize()).toEqual(data.text.length);
- });
-
- it('search returns a correct caption index', function() {
- expect(sjson.search(videoStops[0])).toEqual(0);
- expect(sjson.search(videoStops[1])).toEqual(1);
- expect(sjson.search(videoStops[2])).toEqual(2);
- expect(sjson.search(videoStops[3])).toEqual(2);
- expect(sjson.search(videoStops[4])).toEqual(4);
- expect(sjson.search(videoStops[5])).toEqual(5);
- });
-
- it('search returns the last entry for a value outside the bounds of the array', function() {
- expect(sjson.search(OUT_OF_BOUNDS_STOP)).toEqual(sjson.getCaptions().length - 1);
- });
-
- it('search returns the first entry for a negative index in the array', function() {
- expect(sjson.search(-1)).toEqual(0);
- });
-
- it('search only searches through a subrange of times if start / end times are specified', function() {
- var start = videoStops[2] - 100;
- var end = videoStops[5] - 100;
- var results = sjson.filter(start, end);
- var expectedLength = results.captions.length - 1;
-
- expect(sjson.search(videoStops[0], start, end)).toEqual(0);
- expect(sjson.search(videoStops[1], start, end)).toEqual(0);
- expect(sjson.search(videoStops[2], start, end)).toEqual(0);
- expect(sjson.search(videoStops[3], start, end)).toEqual(0);
- expect(sjson.search(OUT_OF_BOUNDS_STOP, start, end)).toEqual(expectedLength);
- });
-
- it('filters results correctly given a start and end time', function() {
- var start = videoStops[1] - 100;
- var end = videoStops[4] - 100;
- var results = sjson.filter(start, end);
-
- expect(results.start.length).toEqual(3);
- expect(results.captions.length).toEqual(3);
- });
- });
- });
-}(require));
diff --git a/xmodule/js/spec/video/social_share_spec.js b/xmodule/js/spec/video/social_share_spec.js
deleted file mode 100644
index b0f218b0e4bb..000000000000
--- a/xmodule/js/spec/video/social_share_spec.js
+++ /dev/null
@@ -1,44 +0,0 @@
-(function() {
- // eslint-disable-next-line lines-around-directive
- 'use strict';
-
- describe('VideoSocialSharingHandler', function() {
- var state;
-
- beforeEach(function() {
- state = jasmine.initializePlayer('video_all.html');
- window.analytics = jasmine.createSpyObj('analytics', ['track']);
- });
-
- afterAll(() => delete window.analytics);
-
- describe('clicking social share fires an analytics event', function() {
- const testCases = [
- // eslint-disable-next-line object-curly-spacing
- { source: 'twitter' },
- // eslint-disable-next-line object-curly-spacing
- { source: 'facebook' },
- // eslint-disable-next-line object-curly-spacing
- { source: 'linkedin' },
- ];
- // eslint-disable-next-line object-curly-spacing
- _.each(testCases, ({ source }) => {
- it(source, () => {
- var siteShareButton = $(`.social-share-link[data-source="${source}"]`);
- expect(siteShareButton.length).toEqual(1);
-
- siteShareButton.trigger('click');
-
- expect(window.analytics.track).toHaveBeenCalledWith(
- 'edx.social.video.share_button.clicked',
- {
- source: source,
- video_block_id: 'block-v1:coursekey+type@video+block@000000000000000000',
- course_id: 'course-v1:someOrg+thisCOurse+runAway',
- }
- );
- });
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_autoadvance_spec.js b/xmodule/js/spec/video/video_autoadvance_spec.js
deleted file mode 100644
index 88a59be0e544..000000000000
--- a/xmodule/js/spec/video/video_autoadvance_spec.js
+++ /dev/null
@@ -1,110 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoAutoAdvance', function() {
- var state, oldOTBD;
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- jasmine.clock().install();
- });
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
-
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- window.onTouchBasedDevice = oldOTBD;
- jasmine.clock().uninstall();
- });
- describe('when auto-advance feature is unset (default behaviour)', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer('video.html');
- appendLoadFixtures('sequence.html');
- });
- it('no auto-advance button is shown', function() {
- var $button = $('.control.auto-advance');
- expect($button).not.toExist();
- });
- it('when video ends, it will not auto-advance to next unit', function() {
- var $nextButton = $('.sequence-nav-button.button-next').first();
- expect($nextButton).toExist();
-
- // not auto-clicked yet
- spyOnEvent($nextButton, 'click');
- expect('click').not.toHaveBeenTriggeredOn($nextButton);
-
- state.el.trigger('ended');
- jasmine.clock().tick(2);
-
- // still not auto-clicked
- expect('click').not.toHaveBeenTriggeredOn($nextButton);
- });
- });
- describe('when auto-advance feature is set', function() {
- describe('and auto-advance is enabled', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer('video_autoadvance.html');
- appendLoadFixtures('sequence.html');
- });
- it('an active auto-advance button is shown', function() {
- var $button = $('.control.auto-advance');
- expect($button).toExist();
- expect($button).toHaveClass('active');
- });
- it('when button is clicked, it will deactivate auto-advance', function() {
- var $button = $('.control.auto-advance');
- $button.click();
- expect($button).not.toHaveClass('active');
- });
- it('when video ends, it will auto-advance to next unit', function() {
- var $nextButton = $('.sequence-nav-button.button-next').first();
- expect($nextButton).toExist();
-
- // not auto-clicked yet
- spyOnEvent($nextButton, 'click');
- expect('click').not.toHaveBeenTriggeredOn($nextButton);
-
- state.el.trigger('ended');
- jasmine.clock().tick(2);
-
- // now it was auto-clicked
- expect('click').toHaveBeenTriggeredOn($nextButton);
- });
- });
-
- describe('when auto-advance is disabled', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer('video_autoadvance_disabled.html');
- appendLoadFixtures('sequence.html');
- });
- it('an inactive auto-advance button is shown', function() {
- var $button = $('.control.auto-advance');
- expect($button).toExist();
- expect($button).not.toHaveClass('active');
- });
- it('when the button is clicked, it will activate auto-advance', function() {
- var $button = $('.control.auto-advance');
- $button.click();
- expect($button).toHaveClass('active');
- });
- it('when video ends, it will not auto-advance to next unit', function() {
- var $nextButton = $('.sequence-nav-button.button-next').first();
- expect($nextButton).toExist();
-
- // not auto-clicked yet
- spyOnEvent($nextButton, 'click');
- expect('click').not.toHaveBeenTriggeredOn($nextButton);
-
- state.el.trigger('ended');
- jasmine.clock().tick(2);
-
- // still not auto-clicked
- expect('click').not.toHaveBeenTriggeredOn($nextButton);
- });
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_bumper_spec.js b/xmodule/js/spec/video/video_bumper_spec.js
deleted file mode 100644
index 5a0d0945bad0..000000000000
--- a/xmodule/js/spec/video/video_bumper_spec.js
+++ /dev/null
@@ -1,108 +0,0 @@
-(function(WAIT_TIMEOUT) {
- 'use strict';
-
- describe('VideoBumper', function() {
- var state, oldOTBD, waitForPlaying;
-
- // eslint-disable-next-line no-shadow
- waitForPlaying = function(state, done) {
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-playing');
- }).done(done);
- };
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- state = jasmine.initializePlayer('video_with_bumper.html');
- $('.poster .btn-play').click();
- jasmine.clock().install();
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- if (state.bumperState && state.bumperState.videoPlayer) {
- state.bumperState.videoPlayer.destroy();
- }
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- window.onTouchBasedDevice = oldOTBD;
- jasmine.clock().uninstall();
- });
-
- it('can render the bumper video', function() {
- expect($('.is-bumper')).toExist();
- });
-
- it('can show the main video on error', function(done) {
- state.el.triggerHandler('error');
- jasmine.clock().tick(20);
- expect($('.is-bumper')).not.toExist();
- waitForPlaying(state, done);
- });
-
- it('can show the main video once bumper ends', function(done) {
- state.el.trigger('ended');
- jasmine.clock().tick(20);
- expect($('.is-bumper')).not.toExist();
- waitForPlaying(state, done);
- });
-
- it('can show the main video on skip', function(done) {
- state.bumperState.videoBumper.skip();
- jasmine.clock().tick(20);
- expect($('.is-bumper')).not.toExist();
- waitForPlaying(state, done);
- });
-
- it('can stop the bumper video playing if it is too long', function(done) {
- state.el.trigger('timeupdate', [state.bumperState.videoBumper.maxBumperDuration + 1]);
- jasmine.clock().tick(20);
- expect($('.is-bumper')).not.toExist();
- waitForPlaying(state, done);
- });
-
- it('can save appropriate states correctly on ended', function() {
- var saveState = jasmine.createSpy('saveState');
- state.bumperState.videoSaveStatePlugin.saveState = saveState;
- state.el.trigger('ended');
- jasmine.clock().tick(20);
- expect(saveState).toHaveBeenCalledWith(true, {bumper_last_view_date: true});
- });
-
- it('can save appropriate states correctly on skip', function() {
- var saveState = jasmine.createSpy('saveState');
- state.bumperState.videoSaveStatePlugin.saveState = saveState;
- state.bumperState.videoBumper.skip();
- expect(state.storage.getItem('isBumperShown')).toBeTruthy();
- jasmine.clock().tick(20);
- expect(saveState).toHaveBeenCalledWith(true, {bumper_last_view_date: true});
- });
-
- it('can save appropriate states correctly on error', function() {
- var saveState = jasmine.createSpy('saveState');
- state.bumperState.videoSaveStatePlugin.saveState = saveState;
- state.el.triggerHandler('error');
- expect(state.storage.getItem('isBumperShown')).toBeTruthy();
- jasmine.clock().tick(20);
- expect(saveState).toHaveBeenCalledWith(true, {bumper_last_view_date: true});
- });
-
- it('can save appropriate states correctly on skip and do not show again', function() {
- var saveState = jasmine.createSpy('saveState');
- state.bumperState.videoSaveStatePlugin.saveState = saveState;
- state.bumperState.videoBumper.skipAndDoNotShowAgain();
- expect(state.storage.getItem('isBumperShown')).toBeTruthy();
- jasmine.clock().tick(20);
- expect(saveState).toHaveBeenCalledWith(true, {bumper_last_view_date: true, bumper_do_not_show_again: true});
- });
-
- it('can destroy itself', function() {
- state.bumperState.videoBumper.destroy();
- expect(state.videoBumper).toBeUndefined();
- });
- });
-}).call(this, window.WAIT_TIMEOUT);
diff --git a/xmodule/js/spec/video/video_caption_spec.js b/xmodule/js/spec/video/video_caption_spec.js
deleted file mode 100644
index 58fcc1cce99d..000000000000
--- a/xmodule/js/spec/video/video_caption_spec.js
+++ /dev/null
@@ -1,1331 +0,0 @@
-/* global _, WAIT_TIMEOUT */
-
-(function() {
- 'use strict';
-
- describe('VideoCaption', function() {
- var state, oldOTBD;
- var parseIntAttribute = function(element, attrName) {
- return parseInt(element.attr(attrName), 10);
- };
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- $.fn.scrollTo.calls.reset();
- });
-
- afterEach(function() {
- // `source` tags should be removed to avoid memory leak bug that we
- // had before. Removing of `source` tag, not `video` tag, stops
- // loading video source and clears the memory.
- $('source').remove();
- $.fn.scrollTo.calls.reset();
- state.storage.clear();
- state.videoPlayer.destroy();
-
- window.onTouchBasedDevice = oldOTBD;
- });
-
- describe('constructor', function() {
- describe('always', function() {
- beforeEach(function() {
- spyOn($, 'ajaxWithPrefix').and.callThrough();
- });
-
- it('create the transcript element', function() {
- state = jasmine.initializePlayer();
- expect($('.video')).toContainElement('.subtitles');
- });
-
- it('has appropriate lang attributes', function() {
- state = jasmine.initializePlayer();
-
- $('.video .toggle-captions').trigger('click');
-
- expect($('.video .subtitles-menu')).toHaveAttrs({
- lang: 'en'
- });
- expect($('.video .closed-captions')).toHaveAttrs({
- lang: 'en'
- });
- });
-
- it('add transcript control to video player', function() {
- state = jasmine.initializePlayer();
- expect($('.video')).toContainElement('.toggle-transcript');
- });
-
- it('add ARIA attributes to transcript control', function() {
- var $captionControl;
- state = jasmine.initializePlayer();
- $captionControl = $('.toggle-transcript');
- expect($captionControl).toHaveAttrs({
- 'aria-disabled': 'false',
- 'aria-label': 'Turn off transcripts'
- });
- $captionControl.click();
- expect($captionControl).toHaveAttrs({
- 'aria-disabled': 'false',
- 'aria-label': 'Turn on transcripts'
- });
- });
-
- it('adds the captioning control to the video player', function() {
- state = jasmine.initializePlayer();
- expect($('.video')).toContainElement('.toggle-captions');
- expect($('.video')).toContainElement('.closed-captions');
- });
-
- it('add ARIA attributes to caption control', function() {
- var $toggleCaption;
- state = jasmine.initializePlayer();
- $toggleCaption = $('.toggle-captions');
- expect($toggleCaption).toHaveAttrs({
- 'aria-disabled': 'false',
- 'aria-label': 'Turn on closed captioning'
- });
- $toggleCaption.click();
- expect($toggleCaption).toHaveAttrs({
- 'aria-disabled': 'false',
- 'aria-label': 'Hide closed captions'
- });
- });
-
- it('adds "closed" class to the main element if transcript setting is off', function() {
- // No cookie, showCaptions setting is off: hide transcripts panel.
- $.cookie.and.returnValue(null);
- state = jasmine.initializePlayer('video_all.html', {showCaptions: false});
- expect(state.el).toHaveClass('closed');
-
- // No cookie, showCaptions setting is on: show transcripts panel.
- $.cookie.and.returnValue(null);
- state = jasmine.initializePlayer('video_all.html', {showCaptions: true});
- expect(state.el).not.toHaveClass('closed');
-
- // Cookie preference is on, showCaptions setting is off: hide transcripts panel.
- $.cookie.and.returnValue('true');
- state = jasmine.initializePlayer('video_all.html', {showCaptions: false});
- expect(state.el).toHaveClass('closed');
-
- // Cookie preference is on, showCaptions setting is on: show transcripts panel.
- $.cookie.and.returnValue('true');
- state = jasmine.initializePlayer('video_all.html', {showCaptions: true});
- expect(state.el).not.toHaveClass('closed');
-
- // Cookie preference is off, showCaptions setting is off: hide transcripts panel.
- $.cookie.and.returnValue('false');
- state = jasmine.initializePlayer('video_all.html', {showCaptions: false});
- expect(state.el).toHaveClass('closed');
-
- // Cookie preference is off, showCaptions setting is on: hide transcripts panel.
- $.cookie.and.returnValue('false');
- state = jasmine.initializePlayer('video_all.html', {showCaptions: true});
- expect(state.el).toHaveClass('closed');
- });
-
- it('fetch the transcript in HTML5 mode', function(done) {
- var transcriptURL = '/transcript/translation/en',
- transcriptCall;
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.loaded;
- }).then(function() {
- expect($.ajaxWithPrefix).toHaveBeenCalledWith({
- url: transcriptURL,
- notifyOnError: false,
- // eslint-disable-next-line no-void
- data: void 0,
- success: jasmine.any(Function),
- error: jasmine.any(Function)
- });
- transcriptCall = $.ajaxWithPrefix.calls.all().find(function(call) {
- return call.args[0].url === transcriptURL;
- });
- expect(transcriptCall.args[0].data).toBeUndefined();
- }).always(done);
- });
-
- it('fetch the transcript in Flash mode', function(done) {
- state = jasmine.initializePlayerYouTube();
- spyOn(state, 'isFlashMode').and.returnValue(true);
- state.videoCaption.fetchCaption();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.loaded;
- }).then(function() {
- expect($.ajaxWithPrefix).toHaveBeenCalledWith({
- url: '/transcript/translation/en',
- notifyOnError: false,
- data: jasmine.any(Object),
- success: jasmine.any(Function),
- error: jasmine.any(Function)
- });
- expect($.ajaxWithPrefix.calls.mostRecent().args[0].data)
- .toEqual({
- videoId: 'cogebirgzzM'
- });
- }).always(done);
- });
-
- it('fetch the transcript in Youtube mode', function(done) {
- state = jasmine.initializePlayerYouTube();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.loaded;
- }).then(function() {
- expect($.ajaxWithPrefix).toHaveBeenCalledWith({
- url: '/transcript/translation/en',
- notifyOnError: false,
- data: jasmine.any(Object),
- success: jasmine.any(Function),
- error: jasmine.any(Function)
- });
- expect($.ajaxWithPrefix.calls.mostRecent().args[0].data)
- .toEqual({
- videoId: 'cogebirgzzM'
- });
- }).always(done);
- });
-
- it('bind the mouse movement', function() {
- state = jasmine.initializePlayer();
- expect($('.subtitles-menu')).toHandle('mouseover');
- expect($('.subtitles-menu')).toHandle('mouseout');
- expect($('.subtitles-menu')).toHandle('mousemove');
- expect($('.subtitles-menu')).toHandle('mousewheel');
- expect($('.subtitles-menu')).toHandle('DOMMouseScroll');
- });
-
- it('bind the scroll', function() {
- state = jasmine.initializePlayer();
- expect($('.subtitles-menu'))
- .toHandleWith('scroll', state.videoControl.showControls);
- });
- });
-
- it('can destroy itself', function() {
- var plugin;
- spyOn($, 'ajaxWithPrefix');
- state = jasmine.initializePlayer();
- plugin = state.videoCaption;
-
- spyOn($.fn, 'off').and.callThrough();
- state.videoCaption.destroy();
-
- expect(state.videoCaption).toBeUndefined();
- expect($.fn.off).toHaveBeenCalledWith({
- 'caption:fetch': plugin.fetchCaption,
- 'caption:resize': plugin.onResize,
- 'caption:update': plugin.onCaptionUpdate,
- ended: plugin.pause,
- fullscreen: plugin.onResize,
- pause: plugin.pause,
- play: plugin.play,
- destroy: plugin.destroy
- });
- });
-
- describe('renderCaptions', function() {
- describe('is rendered', function() {
- var KEY = $.ui.keyCode,
-
- keyPressEvent = function(key) {
- return $.Event('keydown', {keyCode: key});
- };
-
- it('toggles the captions on control click', function() {
- state = jasmine.initializePlayer();
-
- $('.toggle-captions').click();
- expect($('.toggle-captions')).toHaveClass('is-active');
- expect($('.closed-captions')).toHaveClass('is-visible');
-
- $('.toggle-captions').click();
- expect($('.toggle-captions')).not.toHaveClass('is-active');
- expect($('.closed-captions')).not.toHaveClass('is-visible');
- });
-
- it('toggles the captions on keypress ENTER', function() {
- state = jasmine.initializePlayer();
-
- $('.toggle-captions').focus().trigger(keyPressEvent(KEY.ENTER));
- expect($('.toggle-captions')).toHaveClass('is-active');
- expect($('.closed-captions')).toHaveClass('is-visible');
-
- $('.toggle-captions').focus().trigger(keyPressEvent(KEY.ENTER));
- expect($('.toggle-captions')).not.toHaveClass('is-active');
- expect($('.closed-captions')).not.toHaveClass('is-visible');
- });
-
- it('toggles the captions on keypress SPACE', function() {
- state = jasmine.initializePlayer();
-
- $('.toggle-captions').focus().trigger(keyPressEvent(KEY.SPACE));
- expect($('.toggle-captions')).toHaveClass('is-active');
- expect($('.closed-captions')).toHaveClass('is-visible');
-
- $('.toggle-captions').focus().trigger(keyPressEvent(KEY.SPACE));
- expect($('.toggle-captions')).not.toHaveClass('is-active');
- expect($('.closed-captions')).not.toHaveClass('is-visible');
- });
- });
- });
-
- describe('renderLanguageMenu', function() {
- describe('is rendered', function() {
- var KEY = $.ui.keyCode,
-
- keyPressEvent = function(key) {
- return $.Event('keydown', {keyCode: key});
- };
-
- it('if languages more than 1', function() {
- var transcripts, langCodes, langLabels;
- state = jasmine.initializePlayer();
- transcripts = state.config.transcriptLanguages;
- langCodes = _.keys(transcripts);
- langLabels = _.values(transcripts);
-
- expect($('.langs-list')).toExist();
- expect($('.langs-list')).toHandle('click');
-
- $('.langs-list li').each(function() {
- var code = $(this).data('lang-code'),
- link = $(this).find('.control'),
- label = link.text();
-
- expect(code).toBeInArray(langCodes);
- expect(label).toBeInArray(langLabels);
- });
- });
-
- it('when clicking on link with new language', function() {
- var Caption, $link;
- state = jasmine.initializePlayer();
- Caption = state.videoCaption;
- $link = $('.langs-list li[data-lang-code="de"] .control-lang');
-
- spyOn(Caption, 'fetchCaption');
- spyOn(state.storage, 'setItem');
-
- state.lang = 'en';
- $link.trigger('click');
-
- expect(Caption.fetchCaption).toHaveBeenCalled();
- expect(state.lang).toBe('de');
- expect(state.storage.setItem)
- .toHaveBeenCalledWith('language', 'de');
- expect($('.langs-list li.is-active').length).toBe(1);
- expect($('.subtitles .subtitles-menu')).toHaveAttrs({
- lang: 'de'
- });
- expect($('.closed-captions')).toHaveAttrs({
- lang: 'de'
- });
- expect($link).toHaveAttr('aria-pressed', 'true');
- });
-
- it('when clicking on link with current language', function() {
- var Caption, $link;
-
- state = jasmine.initializePlayer();
- Caption = state.videoCaption;
- $link = $('.langs-list li[data-lang-code="en"] .control-lang');
-
- spyOn(Caption, 'fetchCaption');
- spyOn(state.storage, 'setItem');
-
- state.lang = 'en';
- $link.trigger('click');
-
- expect(Caption.fetchCaption).not.toHaveBeenCalled();
- expect(state.lang).toBe('en');
- expect(state.storage.setItem)
- .not.toHaveBeenCalledWith('language', 'en');
- expect($('.langs-list li.is-active').length).toBe(1);
- expect($link).toHaveAttr('aria-pressed', 'true');
- });
-
- it('open the language toggle on hover', function() {
- state = jasmine.initializePlayer();
- $('.lang').mouseenter();
- expect($('.lang')).toHaveClass('is-opened');
- $('.lang').mouseleave();
- expect($('.lang')).not.toHaveClass('is-opened');
- });
-
- it('opens the language menu on arrow up', function() {
- state = jasmine.initializePlayer();
- $('.language-menu').focus();
- $('.language-menu').trigger(keyPressEvent(KEY.UP));
- expect($('.lang')).toHaveClass('is-opened');
- expect($('.langs-list')
- .find('li')
- .last()
- .find('.control-lang'))
- .toBeFocused();
- });
-
- it('closes the language menu on ESC', function() {
- state = jasmine.initializePlayer();
- $('.language-menu').trigger(keyPressEvent(KEY.UP));
- expect($('.lang')).toHaveClass('is-opened');
- $('.language-menu').trigger(keyPressEvent(KEY.ESCAPE));
- expect($('.lang')).not.toHaveClass('is-opened');
- expect($('.language-menu')).toBeFocused();
- });
- });
-
- describe('is not rendered', function() {
- it('if just 1 language', function() {
- state = jasmine.initializePlayer(null, {
- transcriptLanguages: {en: 'English'}
- });
-
- expect($('.langs-list')).not.toExist();
- expect($('.lang')).not.toHandle('mouseenter');
- expect($('.lang')).not.toHandle('mouseleave');
- });
- });
- });
-
- describe('when on a non touch-based device', function() {
- beforeEach(function(done) {
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(done);
- });
-
- it('render the transcript', function() {
- var captionsData = jasmine.stubbedCaption,
- $items = $('.subtitles li span[data-index]');
-
- _.each(captionsData.text, function(text, index) {
- var item = $items.eq(index);
-
- expect(parseIntAttribute(item, 'data-index')).toEqual(index);
- expect(parseIntAttribute(item, 'data-start')).toEqual(captionsData.start[index]);
- expect(item.attr('tabindex')).toEqual('0');
- expect(item.text().trim()).toEqual(captionsData.text[index]);
- });
- });
-
- it('add a padding element to transcript', function() {
- expect($('.subtitles li:first').hasClass('spacing'))
- .toBe(true);
- expect($('.subtitles li:last').hasClass('spacing'))
- .toBe(true);
- });
-
- it('bind all the transcript link', function() {
- var handlerList = ['captionMouseOverOut', 'captionClick',
- 'captionMouseDown', 'captionFocus', 'captionBlur',
- 'captionKeyDown'
- ];
-
- $.each(handlerList, function(index, handler) {
- spyOn(state.videoCaption, handler);
- });
- $('.subtitles li span[data-index]').each(
- function(index, link) {
- $(link).trigger('mouseover');
- expect(state.videoCaption.captionMouseOverOut).toHaveBeenCalled();
-
- state.videoCaption.captionMouseOverOut.calls.reset();
- $(link).trigger('mouseout');
- expect(state.videoCaption.captionMouseOverOut).toHaveBeenCalled();
-
- $(this).click();
- expect(state.videoCaption.captionClick).toHaveBeenCalled();
-
- $(this).trigger('mousedown');
- expect(state.videoCaption.captionMouseDown).toHaveBeenCalled();
-
- $(this).trigger('focus');
- expect(state.videoCaption.captionFocus).toHaveBeenCalled();
-
- $(this).trigger('blur');
- expect(state.videoCaption.captionBlur).toHaveBeenCalled();
-
- $(this).trigger('keydown');
- expect(state.videoCaption.captionKeyDown).toHaveBeenCalled();
- });
- });
-
- it('set rendered to true', function(done) {
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(function() {
- expect(state.videoCaption.rendered).toBeTruthy();
- }).always(done);
- });
- });
-
- describe('when on a touch-based device', function() {
- beforeEach(function() {
- window.onTouchBasedDevice.and.returnValue(['iPad']);
-
- state = jasmine.initializePlayer();
- $.fn.scrollTo.calls.reset();
- });
-
- it('show explanation message', function() {
- expect($('.subtitles .subtitles-menu li')).toHaveText(
- 'Transcript will be displayed when you start playing the video.'
- );
- });
-
- it('show transcript on play', function(done) {
- state.el.trigger('play');
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(function() {
- var captionsData = jasmine.stubbedCaption,
- $items = $('.subtitles li span[data-index]');
-
- _.each(captionsData.text, function(text, index) {
- var item = $items.eq(index);
-
- expect(parseIntAttribute(item, 'data-index')).toEqual(index);
- expect(parseIntAttribute(item, 'data-start')).toEqual(captionsData.start[index]);
- expect(item.attr('tabindex')).toEqual('0');
- expect(item.text().trim()).toEqual(text);
- });
- }).always(done);
- });
-
- it('does not set rendered to true', function() {
- expect(state.videoCaption.rendered).toBeFalsy();
- });
- });
-
- describe('when no transcripts file was specified', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer('video_all.html', {
- sub: '',
- transcriptLanguages: {}
- });
- });
-
- it('transcript panel is not shown', function() {
- expect(state.videoCaption.languageChooserEl).toBeHidden();
- });
- });
- });
-
- describe('mouse movement', function() {
- var originalClearTimeout;
-
- beforeEach(function(done) {
- jasmine.clock().install();
- state = jasmine.initializePlayer();
- jasmine.clock().tick(50);
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(done);
-
- // Why we can't use spyOn(): https://github.com/jasmine/jasmine/issues/826
- originalClearTimeout = window.clearTimeout;
- window.clearTimeout = jasmine.createSpy().and.callFake(originalClearTimeout);
- });
-
- afterEach(function() {
- window.clearTimeout = originalClearTimeout;
- jasmine.clock().uninstall();
- });
-
- describe('when cursor is outside of the transcript box', function() {
- it('does not set freezing timeout', function() {
- expect(state.videoCaption.frozen).toBeFalsy();
- });
- });
-
- describe('when cursor is in the transcript box', function() {
- beforeEach(function() {
- spyOn(state.videoCaption, 'onMouseLeave');
- $(window).trigger(jQuery.Event('mousemove'));
- jasmine.clock().tick(state.config.captionsFreezeTime);
- $('.subtitles-menu').trigger(jQuery.Event('mouseenter'));
- jasmine.clock().tick(state.config.captionsFreezeTime);
- });
-
- it('set the freezing timeout', function() {
- expect(state.videoCaption.frozen).not.toBeFalsy();
- expect(state.videoCaption.onMouseLeave).toHaveBeenCalled();
- });
-
- describe('when the cursor is moving', function() {
- it('reset the freezing timeout', function() {
- $('.subtitles-menu').trigger(jQuery.Event('mousemove'));
- expect(window.clearTimeout).toHaveBeenCalled();
- });
- });
-
- describe('when the mouse is scrolling', function() {
- it('reset the freezing timeout', function() {
- $('.subtitles-menu').trigger(jQuery.Event('mousewheel'));
- expect(window.clearTimeout).toHaveBeenCalled();
- });
- });
- });
-
- describe(
- 'when cursor is moving out of the transcript box',
- function() {
- beforeEach(function() {
- state.videoCaption.frozen = 100;
- $.fn.scrollTo.calls.reset();
- });
-
- describe('always', function() {
- beforeEach(function() {
- $('.subtitles-menu').trigger(jQuery.Event('mouseout'));
- });
-
- it('reset the freezing timeout', function() {
- expect(window.clearTimeout).toHaveBeenCalledWith(100);
- });
-
- it('unfreeze the transcript', function() {
- expect(state.videoCaption.frozen).toBeNull();
- });
- });
-
- describe('when the player is playing', function() {
- beforeEach(function() {
- state.videoCaption.playing = true;
- $('.subtitles-menu span[data-index]:first')
- .parent()
- .addClass('current');
- $('.subtitles-menu').trigger(jQuery.Event('mouseout'));
- });
-
- it('scroll the transcript', function() {
- expect($.fn.scrollTo).toHaveBeenCalled();
- });
- });
-
- describe('when the player is not playing', function() {
- beforeEach(function() {
- state.videoCaption.playing = false;
- $('.subtitles-menu').trigger(jQuery.Event('mouseout'));
- });
-
- it('does not scroll the transcript', function() {
- expect($.fn.scrollTo).not.toHaveBeenCalled();
- });
- });
- });
- });
-
- describe('fetchCaption', function() {
- var Caption, msg;
-
- beforeEach(function() {
- state = jasmine.initializePlayer();
- Caption = state.videoCaption;
- spyOn($, 'ajaxWithPrefix').and.callThrough();
- spyOn(Caption, 'renderCaption');
- spyOn(Caption, 'bindHandlers');
- spyOn(Caption, 'updatePlayTime');
- spyOn(Caption, 'hideCaptions');
- spyOn(state, 'youtubeId').and.returnValue('Z5KLxerq05Y');
- });
-
- it('show transcript on language change', function() {
- Caption.loaded = true;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.hideCaptions).toHaveBeenCalledWith(false);
- });
-
- msg = 'use cookie to show/hide transcripts if they have not been '
- + 'loaded yet';
- it(msg, function() {
- Caption.loaded = false;
- Caption.hideCaptionsOnLoad = false;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.hideCaptions).toHaveBeenCalledWith(false);
-
- Caption.loaded = false;
- Caption.hideCaptions.calls.reset();
- Caption.hideCaptionsOnLoad = true;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.hideCaptions).toHaveBeenCalledWith(true);
- });
-
- it('on success: on touch devices', function() {
- state.isTouch = true;
- Caption.loaded = false;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.bindHandlers).toHaveBeenCalled();
- expect(Caption.renderCaption).not.toHaveBeenCalled();
- expect(Caption.updatePlayTime).not.toHaveBeenCalled();
- expect(Caption.loaded).toBeTruthy();
- });
-
- msg = 'on success: change language on touch devices when '
- + 'transcripts have not been rendered yet';
- it(msg, function() {
- state.isTouch = true;
- Caption.loaded = true;
- Caption.rendered = false;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.bindHandlers).not.toHaveBeenCalled();
- expect(Caption.renderCaption).not.toHaveBeenCalled();
- expect(Caption.updatePlayTime).not.toHaveBeenCalled();
- expect(Caption.loaded).toBeTruthy();
- });
-
- it('on success: re-render on touch devices', function() {
- state.isTouch = true;
- Caption.loaded = true;
- Caption.rendered = true;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.bindHandlers).not.toHaveBeenCalled();
- expect(Caption.renderCaption).toHaveBeenCalled();
- expect(Caption.updatePlayTime).toHaveBeenCalled();
- expect(Caption.loaded).toBeTruthy();
- });
-
- it('on success: rendered correct', function() {
- Caption.loaded = false;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.bindHandlers).toHaveBeenCalled();
- expect(Caption.renderCaption).toHaveBeenCalled();
- expect(Caption.updatePlayTime).not.toHaveBeenCalled();
- expect(Caption.loaded).toBeTruthy();
- });
-
- it('on success: re-rendered correct', function() {
- Caption.loaded = true;
- Caption.rendered = true;
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.bindHandlers).not.toHaveBeenCalled();
- expect(Caption.renderCaption).toHaveBeenCalled();
- expect(Caption.updatePlayTime).toHaveBeenCalled();
- expect(Caption.loaded).toBeTruthy();
- });
-
- msg = 'on error: transcripts are hidden if there are no transcripts';
- it(msg, function() {
- spyOn(Caption, 'fetchAvailableTranslations');
- $.ajax.and.callFake(function(settings) {
- _.result(settings, 'error');
- });
-
- state.config.transcriptLanguages = {};
-
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.fetchAvailableTranslations).not.toHaveBeenCalled();
- expect(Caption.hideCaptions.calls.mostRecent().args[0]).toEqual(true);
- });
-
- msg = 'on error: for Html5 player an attempt to fetch transcript '
- + 'with youtubeId if there are no additional transcripts';
- it(msg, function() {
- spyOn(Caption, 'fetchAvailableTranslations');
- spyOn(Caption, 'fetchCaption').and.callThrough();
- spyOn(Caption, 'hideClosedCaptions').and.callThrough();
- $.ajax.and.callFake(function(settings) {
- _.result(settings, 'error');
- });
-
- state.config.transcriptLanguages = {};
- state.videoType = 'html5';
-
- Caption.fetchCaption();
-
- expect(Caption.fetchAvailableTranslations).not.toHaveBeenCalled();
- expect(Caption.hideCaptions.calls.mostRecent().args[0]).toEqual(true);
- expect(Caption.fetchCaption.calls.mostRecent().args[0]).toEqual(true);
- expect(Caption.fetchCaption.calls.count()).toEqual(2);
- expect(Caption.hideClosedCaptions.calls.count()).toEqual(1);
- });
-
- msg = 'on success: when fetchCaption called with fetch_with_youtubeId to '
- + 'get transcript with youtubeId for html5';
- it(msg, function() {
- spyOn(Caption, 'fetchAvailableTranslations');
- spyOn(Caption, 'fetchCaption').and.callThrough();
-
- Caption.loaded = true;
- state.config.transcriptLanguages = {};
- state.videoType = 'html5';
-
- Caption.fetchCaption(true);
-
- expect(Caption.fetchAvailableTranslations).not.toHaveBeenCalled();
- expect($.ajaxWithPrefix.calls.mostRecent().args[0].data)
- .toEqual({videoId: 'Z5KLxerq05Y'});
- expect(Caption.hideCaptions).toHaveBeenCalledWith(false);
- expect(Caption.fetchCaption.calls.mostRecent().args[0]).toEqual(true);
- expect(Caption.fetchCaption.calls.count()).toEqual(1);
- });
-
- msg = 'on error: fetch available translations if there are '
- + 'additional transcripts';
- it(msg, function() {
- $.ajax
- .and.callFake(function(settings) {
- _.result(settings, 'error');
- });
-
- state.config.transcriptLanguages = {
- en: 'English',
- uk: 'Ukrainian'
- };
-
- spyOn(Caption, 'fetchAvailableTranslations');
- Caption.fetchCaption();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.fetchAvailableTranslations).toHaveBeenCalled();
- });
- });
-
- describe('fetchAvailableTranslations', function() {
- var Caption, msg;
-
- beforeEach(function() {
- state = jasmine.initializePlayer();
- Caption = state.videoCaption;
- spyOn($, 'ajaxWithPrefix').and.callThrough();
- spyOn(Caption, 'hideCaptions');
- spyOn(Caption, 'fetchCaption');
- spyOn(Caption, 'renderLanguageMenu');
- });
-
- it('request created with correct parameters', function() {
- Caption.fetchAvailableTranslations();
-
- expect($.ajaxWithPrefix).toHaveBeenCalledWith({
- url: '/transcript/available_translations',
- notifyOnError: false,
- success: jasmine.any(Function),
- error: jasmine.any(Function)
- });
- });
-
- msg = 'on success: language menu is rendered if translations available';
- it(msg, function() {
- state.config.transcriptLanguages = {
- en: 'English',
- uk: 'Ukrainian',
- de: 'German'
- };
- Caption.fetchAvailableTranslations();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(state.config.transcriptLanguages).toEqual({
- uk: 'Ukrainian',
- de: 'German'
- });
- expect(Caption.renderLanguageMenu).toHaveBeenCalledWith({
- uk: 'Ukrainian',
- de: 'German'
- });
- });
-
- msg = 'on success: language menu isn\'t rendered if translations unavailable';
- it(msg, function() {
- state.config.transcriptLanguages = {
- en: 'English',
- ru: 'Russian'
- };
- Caption.fetchAvailableTranslations();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(state.config.transcriptLanguages).toEqual({});
- expect(Caption.renderLanguageMenu).not.toHaveBeenCalled();
- });
-
- msg = 'on error: transcripts are hidden if there are no transcript';
- it(msg, function() {
- $.ajax.and.callFake(function(settings) {
- _.result(settings, 'error');
- });
- Caption.fetchAvailableTranslations();
-
- expect($.ajaxWithPrefix).toHaveBeenCalled();
- expect(Caption.hideCaptions).toHaveBeenCalledWith(true);
- expect(Caption.languageChooserEl).toBeHidden();
- });
- });
-
- describe('play', function() {
- describe('when the transcript was not rendered', function() {
- beforeEach(function(done) {
- window.onTouchBasedDevice.and.returnValue(['iPad']);
-
- state = jasmine.initializePlayer();
- state.videoCaption.play();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(function() {
- done();
- });
- });
-
- it('render the transcript', function() {
- var captionsData;
-
- captionsData = jasmine.stubbedCaption;
-
- $('.subtitles li span[data-index]').each(
- function(index, item) {
- expect(parseIntAttribute($(item), 'data-index')).toEqual(index);
- expect(parseIntAttribute($(item), 'data-start')).toEqual(captionsData.start[index]);
- expect($(item).attr('tabindex')).toEqual('0');
- expect($(item).text().trim()).toEqual(captionsData.text[index]);
- });
- });
-
- it('add a padding element to transcript', function() {
- expect($('.subtitles li:first')).toHaveClass('spacing');
- expect($('.subtitles li:last')).toHaveClass('spacing');
- });
-
- it('set rendered to true', function() {
- expect(state.videoCaption.rendered).toBeTruthy();
- });
-
- it('set playing to true', function() {
- expect(state.videoCaption.playing).toBeTruthy();
- });
- });
- });
-
- describe('pause', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- state.videoCaption.playing = true;
- state.videoCaption.pause();
- });
-
- it('set playing to false', function() {
- expect(state.videoCaption.playing).toBeFalsy();
- });
- });
-
- describe('updatePlayTime', function() {
- beforeEach(function(done) {
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(done);
- });
-
- describe('when the video speed is 1.0x', function() {
- it('search the caption based on time', function() {
- state.videoCaption.updatePlayTime(25.000);
- expect(state.videoCaption.currentIndex).toEqual(5);
-
- // Flash mode
- spyOn(state, 'isFlashMode').and.returnValue(true);
- state.speed = '1.0';
- state.videoCaption.updatePlayTime(25.000);
- expect(state.videoCaption.currentIndex).toEqual(5);
- });
- });
-
- describe('when the video speed is not 1.0x', function() {
- it('search the transcript based on 1.0x speed', function() {
- state.videoCaption.updatePlayTime(25.000);
- expect(state.videoCaption.currentIndex).toEqual(5);
-
- // To test speed, don't use start / end times.
- state.config.startTime = 0;
- state.config.endTime = null;
-
- // Flash mode
- state.speed = '2.0';
- spyOn(state, 'isFlashMode').and.returnValue(true);
- state.videoCaption.updatePlayTime(25.000);
- expect(state.videoCaption.currentIndex).toEqual(9);
- state.speed = '0.75';
- state.videoCaption.updatePlayTime(25.000);
- expect(state.videoCaption.currentIndex).toEqual(3);
- });
- });
-
- describe('when the index is not the same', function() {
- beforeEach(function() {
- state.videoCaption.currentIndex = 1;
- $('.subtitles li span[data-index=5]').addClass('current');
- state.videoCaption.updatePlayTime(25.000);
- });
-
- it('deactivate the previous transcript', function() {
- expect($('.subtitles li span[data-index=1]'))
- .not.toHaveClass('current');
- });
-
- it('activate new transcript', function() {
- expect($('.subtitles li span[data-index=5]'))
- .toHaveClass('current');
- });
-
- it('save new index', function() {
- expect(state.videoCaption.currentIndex).toEqual(5);
- });
-
- it('scroll transcript to new position', function() {
- expect($.fn.scrollTo).toHaveBeenCalled();
- });
- });
-
- describe('when the index is the same', function() {
- it('does not change current subtitle', function() {
- state.videoCaption.currentIndex = 1;
- $('.subtitles li span[data-index=3]').addClass('current');
- state.videoCaption.updatePlayTime(15.000);
- expect($('.subtitles li span[data-index=3]'))
- .toHaveClass('current');
- });
- });
- });
-
- describe('resize', function() {
- beforeEach(function(done) {
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(function() {
- $('.subtitles li span[data-index=1]').addClass('current');
- state.videoCaption.onResize();
- }).always(done);
- });
-
- describe('set the height of transcript container', function() {
- it('when transcript button is enabled', function() {
- var realHeight = parseInt(
- $('.subtitles').css('maxHeight'), 10
- ),
- shouldBeHeight = $('.video-wrapper').height();
-
- // Because of some problems with rounding on different
- // environments: Linux * Mac * FF * Chrome
- expect(realHeight).toBeCloseTo(shouldBeHeight, 2);
- });
-
- it('when transcript button is disabled ', function() {
- var realHeight, videoWrapperHeight, progressSliderHeight,
- controlHeight, shouldBeHeight;
-
- state.captionsHidden = true;
- state.videoCaption.setSubtitlesHeight();
-
- realHeight = parseInt(
- $('.subtitles').css('maxHeight'), 10
- );
- videoWrapperHeight = $('.video-wrapper').height();
- progressSliderHeight = state.el.find('.slider').height();
- controlHeight = state.el.find('.video-controls').height();
- shouldBeHeight = parseInt((
- videoWrapperHeight
- - 0.5 * progressSliderHeight
- - controlHeight
- ), 10);
-
- expect(realHeight).toBe(shouldBeHeight);
- });
- });
-
- it('set the height of transcript spacing', function() {
- var firstSpacing, lastSpacing;
-
- firstSpacing = Math.abs(parseInt(
- $('.subtitles .spacing:first').css('height'), 10
- ));
- lastSpacing = Math.abs(parseInt(
- $('.subtitles .spacing:last').css('height'), 10
- ));
-
- expect(firstSpacing - state.videoCaption.topSpacingHeight())
- .toBeLessThan(1);
- expect(lastSpacing - state.videoCaption.bottomSpacingHeight())
- .toBeLessThan(1);
- });
-
- it('scroll transcript to new position', function() {
- expect($.fn.scrollTo).toHaveBeenCalled();
- });
- });
-
- xdescribe('scrollCaption', function() {
- beforeEach(function() {
- runs(function() {
- state = jasmine.initializePlayer();
- });
-
- waitsFor(function() {
- return state.videoCaption.rendered;
- }, 'Transcripts are not rendered', WAIT_TIMEOUT);
- });
-
- describe('when frozen', function() {
- it('does not scroll the transcript', function() {
- runs(function() {
- state.videoCaption.frozen = true;
- $('.subtitles li span[data-index=1]').addClass('current');
- state.videoCaption.scrollCaption();
- expect($.fn.scrollTo).not.toHaveBeenCalled();
- });
- });
- });
-
- describe('when not frozen', function() {
- beforeEach(function() {
- runs(function() {
- state.videoCaption.frozen = false;
- });
- });
-
- describe('when there is no current transcript', function() {
- it('does not scroll the transcript', function() {
- runs(function() {
- state.videoCaption.scrollCaption();
- expect($.fn.scrollTo).not.toHaveBeenCalled();
- });
- });
- });
-
- describe('when there is a current transcript', function() {
- it('scroll to current transcript', function() {
- runs(function() {
- $('.subtitles li span[data-index=1]').addClass('current');
- state.videoCaption.scrollCaption();
- expect($.fn.scrollTo).toHaveBeenCalled();
- });
- });
- });
- });
- });
-
- xdescribe('seekPlayer', function() {
- beforeEach(function() {
- runs(function() {
- state = jasmine.initializePlayer();
- });
-
- waitsFor(function() {
- var duration = state.videoPlayer.duration(),
- isRendered = state.videoCaption.rendered;
-
- return isRendered && duration;
- }, 'Transcripts are not rendered', WAIT_TIMEOUT);
- });
-
- describe('when the video speed is 1.0x', function() {
- it('trigger seek event with the correct time', function() {
- runs(function() {
- state.videoSpeedControl.currentSpeed = '1.0';
- $('.subtitles li span[data-start="14910"]').trigger('click');
- expect(state.videoPlayer.currentTime).toEqual(14.91);
- });
- });
- });
-
- describe('when the video speed is not 1.0x', function() {
- it('trigger seek event with the correct time', function() {
- runs(function() {
- state.videoSpeedControl.currentSpeed = '0.75';
- $('.subtitles li span[data-start="14910"]').trigger('click');
- expect(state.videoPlayer.currentTime).toEqual(14.91);
- });
- });
- });
-
- describe('when the player type is Flash at speed 0.75x',
- function() {
- it('trigger seek event with the correct time', function() {
- runs(function() {
- state.videoSpeedControl.currentSpeed = '0.75';
- state.currentPlayerMode = 'flash';
- $('.subtitles li span[data-start="14910"]').trigger('click');
- expect(state.videoPlayer.currentTime).toEqual(15);
- });
- });
- });
- });
-
- describe('toggleTranscript', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- $('.subtitles li span[data-index=1]').addClass('current');
- });
-
- describe('when the transcript is visible', function() {
- beforeEach(function() {
- state.el.removeClass('closed');
- state.videoCaption.toggleTranscript(jQuery.Event('click'));
- });
-
- it('hide the transcript', function() {
- expect(state.el).toHaveClass('closed');
- });
- });
-
- describe('when the transcript is hidden', function() {
- beforeEach(function() {
- state.el.addClass('closed');
- state.videoCaption.toggleTranscript(jQuery.Event('click'));
- jasmine.clock().install();
- });
-
- afterEach(function() {
- jasmine.clock().uninstall();
- });
-
- it('show the transcript', function() {
- expect(state.el).not.toHaveClass('closed');
- });
-
- // Test turned off due to flakiness (11/25/13)
- xit('scroll the transcript', function() {
- // After transcripts are shown, and the video plays for a
- // bit.
- jasmine.clock().tick(1000);
-
- // The transcripts should have advanced by at least one
- // position. When they advance, the list scrolls. The
- // current transcript position should be constantly
- // visible.
- runs(function() {
- expect($.fn.scrollTo).toHaveBeenCalled();
- });
- });
- });
- });
-
- describe('transcript accessibility', function() {
- beforeEach(function(done) {
- state = jasmine.initializePlayer();
-
- jasmine.waitUntil(function() {
- return state.videoCaption.rendered;
- }).then(done);
- });
-
- describe('when getting focus through TAB key', function() {
- beforeEach(function() {
- state.videoCaption.isMouseFocus = false;
- $('.subtitles li span[data-index=0]').trigger(
- jQuery.Event('focus')
- );
- });
-
- it('shows an outline around the transcript', function() {
- expect($('.subtitles span[data-index=0]').parent())
- .toHaveClass('focused');
- });
-
- it('has automatic scrolling disabled', function() {
- expect(state.videoCaption.autoScrolling).toBe(false);
- });
- });
-
- describe('when loosing focus through TAB key', function() {
- beforeEach(function() {
- $('.subtitles li span[data-index=0]').trigger(
- jQuery.Event('blur')
- );
- });
-
- it('does not show an outline around the transcript', function() {
- expect($('.subtitles li span[data-index=0]'))
- .not.toHaveClass('focused');
- });
-
- it('has automatic scrolling enabled', function() {
- expect(state.videoCaption.autoScrolling).toBe(true);
- });
- });
-
- describe(
- 'when same transcript gets the focus through mouse after '
- + 'having focus through TAB key',
- function() {
- beforeEach(function() {
- state.videoCaption.isMouseFocus = false;
- $('.subtitles li span[data-index=0]')
- .trigger(jQuery.Event('focus'));
- $('.subtitles li span[data-index=0]')
- .trigger(jQuery.Event('mousedown'));
- });
-
- it('does not show an outline around it', function() {
- expect($('.subtitles li span[data-index=0]'))
- .not.toHaveClass('focused');
- });
-
- it('has automatic scrolling enabled', function() {
- expect(state.videoCaption.autoScrolling).toBe(true);
- });
- });
-
- describe(
- 'when a second transcript gets focus through mouse after '
- + 'first had focus through TAB key',
- function() {
- var $subDataLiIdx0, $subDataLiIdx1;
-
- beforeEach(function() {
- $subDataLiIdx0 = $('.subtitles li span[data-index=0]');
- $subDataLiIdx1 = $('.subtitles li span[data-index=1]');
-
- state.videoCaption.isMouseFocus = false;
-
- $subDataLiIdx0.trigger(jQuery.Event('focus'));
- $subDataLiIdx0.trigger(jQuery.Event('blur'));
-
- state.videoCaption.isMouseFocus = true;
-
- $subDataLiIdx1.trigger(jQuery.Event('mousedown'));
- });
-
- it('does not show an outline around the first', function() {
- expect($subDataLiIdx0).not.toHaveClass('focused');
- });
-
- it('does not show an outline around the second', function() {
- expect($subDataLiIdx1).not.toHaveClass('focused');
- });
-
- it('has automatic scrolling enabled', function() {
- expect(state.videoCaption.autoScrolling).toBe(true);
- });
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_context_menu_spec.js b/xmodule/js/spec/video/video_context_menu_spec.js
deleted file mode 100644
index b8aa96bda779..000000000000
--- a/xmodule/js/spec/video/video_context_menu_spec.js
+++ /dev/null
@@ -1,439 +0,0 @@
-/* globals _ */
-(function() {
- 'use strict';
-
- describe('Video Context Menu', function() {
- var state, openMenu, keyPressEvent, openSubmenuMouse, openSubmenuKeyboard, closeSubmenuMouse,
- closeSubmenuKeyboard, menu, menuItems, menuSubmenuItem, submenu, submenuItems, overlay, $playButton;
-
- openMenu = function() {
- var $container = $('.video');
- $container.find('video').trigger('contextmenu');
- menu = $container.children('.contextmenu');
- menuItems = menu.children('.menu-item').not('.submenu-item');
- menuSubmenuItem = menu.children('.menu-item.submenu-item');
- submenu = menuSubmenuItem.children('.submenu');
- submenuItems = submenu.children('.menu-item');
- overlay = $container.children('.overlay');
- $playButton = $('.video_control.play');
- };
-
- keyPressEvent = function(key) {
- return $.Event('keydown', {keyCode: key});
- };
-
- // eslint-disable-next-line no-shadow
- openSubmenuMouse = function(menuSubmenuItem) {
- menuSubmenuItem.mouseover();
- jasmine.clock().tick(200);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- };
-
- // eslint-disable-next-line no-shadow
- openSubmenuKeyboard = function(menuSubmenuItem, keyCode) {
- menuSubmenuItem.focus().trigger(keyPressEvent(keyCode || $.ui.keyCode.RIGHT));
- expect(menuSubmenuItem).toHaveClass('is-opened');
- expect(menuSubmenuItem.children().last().children().first()).toBeFocused();
- };
-
- // eslint-disable-next-line no-shadow
- closeSubmenuMouse = function(menuSubmenuItem) {
- menuSubmenuItem.mouseleave();
- jasmine.clock().tick(200);
- expect(menuSubmenuItem).not.toHaveClass('is-opened');
- };
-
- // eslint-disable-next-line no-shadow
- closeSubmenuKeyboard = function(menuSubmenuItem) {
- menuSubmenuItem.children().first().focus().trigger(keyPressEvent($.ui.keyCode.LEFT));
- expect(menuSubmenuItem).not.toHaveClass('is-opened');
- expect(menuSubmenuItem).toBeFocused();
- };
-
- beforeEach(function() {
- jasmine.clock().install();
- // $.cookie is mocked, make sure we have a state with an unmuted volume.
- $.cookie.and.returnValue('100');
- jasmine.addMatchers({
- toHaveCorrectLabels: function() {
- return {
- compare: function(actual, labelsList) {
- return {
- pass: _.difference(labelsList, _.map(actual, function(item) {
- return $(item).text();
- })).length === 0
- };
- }
- };
- }
- });
- });
-
- afterEach(function() {
- $('source').remove();
- _.result(state.storage, 'clear');
- _.result($('video').data('contextmenu'), 'destroy');
- _.result(state.videoPlayer, 'destroy');
- jasmine.clock().uninstall();
- });
-
- describe('constructor', function() {
- it('the structure should be created on first `contextmenu` call', function() {
- state = jasmine.initializePlayer();
- expect(menu).not.toExist();
- openMenu();
- /*
- Make sure we have the expected HTML structure:
- - Play (Pause)
- - Mute (Unmute)
- - Fill browser (Exit full browser)
- - Speed >
- - 0.75x
- - 1.0x
- - 1.25x
- - 1.50x
- */
-
- // Only one context menu per video container
- expect(menu).toBeInDOM();
- expect(menu).toHaveClass('is-opened');
- expect(menuItems).toHaveCorrectLabels(['Play', 'Mute', 'Fill browser']);
- expect(menuSubmenuItem.children('span')).toHaveText('Speed');
- expect(submenuItems).toHaveCorrectLabels(['0.75x', '1.0x', '1.25x', '1.50x']);
- // Check that one of the speed submenu item is selected
- expect(_.size(submenuItems.filter('.is-selected'))).toBe(1);
- });
-
- it('add ARIA attributes to menu, menu items, submenu and submenu items', function() {
- state = jasmine.initializePlayer();
- openMenu();
- // Menu and its items.
- expect(menu).toHaveAttr('role', 'menu');
- menuItems.each(function() {
- expect($(this)).toHaveAttrs({
- 'aria-selected': 'false',
- role: 'menuitem'
- });
- });
-
- expect(menuSubmenuItem).toHaveAttrs({
- 'aria-expanded': 'false',
- 'aria-haspopup': 'true',
- role: 'menuitem'
- });
-
- // Submenu and its items.
- expect(submenu).toHaveAttr('role', 'menu');
- submenuItems.each(function() {
- expect($(this)).toHaveAttr('role', 'menuitem');
- expect($(this)).toHaveAttr('aria-selected');
- });
- });
-
- it('is not used by Youtube type of video player', function() {
- state = jasmine.initializePlayer('video.html');
- expect($('video, iframe')).not.toHaveData('contextmenu');
- });
- });
-
- describe('methods:', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- openMenu();
- });
-
- it('menu can be destroyed successfully', function() {
- var menuitemEvents = ['click', 'keydown', 'contextmenu', 'mouseover'],
- menuEvents = ['keydown', 'contextmenu', 'mouseleave', 'mouseover'];
-
- menu.data('menu').destroy();
- expect(menu).not.toBeInDOM();
- expect(overlay).not.toBeInDOM();
- _.each(menuitemEvents, function(eventName) {
- expect(menuItems.first()).not.toHandle(eventName);
- });
- _.each(menuEvents, function(eventName) {
- expect(menuSubmenuItem).not.toHandle(eventName);
- });
- _.each(menuEvents, function(eventName) {
- expect(menu).not.toHandle(eventName);
- });
- expect($('video')).not.toHandle('contextmenu');
- expect($('video')).not.toHaveData('contextmenu');
- });
-
- it('can change label for the submenu', function() {
- expect(menuSubmenuItem.children('span')).toHaveText('Speed');
- menuSubmenuItem.data('menu').setLabel('New Name');
- expect(menuSubmenuItem.children('span')).toHaveText('New Name');
- });
-
- it('can change label for the menuitem', function() {
- expect(menuItems.first()).toHaveText('Play');
- menuItems.first().data('menu').setLabel('Pause');
- expect(menuItems.first()).toHaveText('Pause');
- });
- });
-
- describe('when video is right-clicked', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- jasmine.mockFullscreenAPI();
- openMenu();
- });
-
- it('context menu opens', function() {
- expect(menu).toHaveClass('is-opened');
- expect(overlay).toBeInDOM();
- });
-
- it('mouseover and mouseleave behave as expected', function() {
- openSubmenuMouse(menuSubmenuItem);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- closeSubmenuMouse(menuSubmenuItem);
- expect(menuSubmenuItem).not.toHaveClass('is-opened');
- submenuItems.eq(1).mouseover();
- expect(submenuItems.eq(1)).toBeFocused();
- });
-
- it('mouse left-clicking outside of the context menu will close it', function() {
- // Left-click outside of open menu, for example on Play button
- $playButton.click();
- expect(menu).not.toHaveClass('is-opened');
- expect(overlay).not.toBeInDOM();
- });
-
- it('mouse right-clicking outside of video will close it', function() {
- // Right-click outside of open menu for example on Play button
- $playButton.trigger('contextmenu');
- expect(menu).not.toHaveClass('is-opened');
- expect(overlay).not.toBeInDOM();
- });
-
- it('mouse right-clicking inside video but outside of context menu will not close it', function() {
- spyOn(menu.data('menu'), 'pointInContainerBox').and.returnValue(true);
- overlay.trigger('contextmenu');
- expect(menu).toHaveClass('is-opened');
- expect(overlay).toBeInDOM();
- });
-
- it('mouse right-clicking inside video but outside of context menu will close submenus', function() {
- spyOn(menu.data('menu'), 'pointInContainerBox').and.returnValue(true);
- openSubmenuMouse(menuSubmenuItem);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- overlay.trigger('contextmenu');
- expect(menuSubmenuItem).not.toHaveClass('is-opened');
- });
-
- it('mouse left/right-clicking behaves as expected on play/pause menu item', function() {
- var menuItem = menuItems.first();
- spyOn(state.videoPlayer, 'isPlaying');
- spyOn(state.videoPlayer, 'play').and.callFake(function() {
- state.videoPlayer.isPlaying.and.returnValue(true);
- state.el.trigger('play');
- });
- spyOn(state.videoPlayer, 'pause').and.callFake(function() {
- state.videoPlayer.isPlaying.and.returnValue(false);
- state.el.trigger('pause');
- });
- // Left-click on play
- menuItem.click();
- expect(state.videoPlayer.play).toHaveBeenCalled();
- expect(menuItem).toHaveText('Pause');
- openMenu();
- // Left-click on pause
- menuItem.click();
- expect(state.videoPlayer.pause).toHaveBeenCalled();
- expect(menuItem).toHaveText('Play');
- state.videoPlayer.play.calls.reset();
- // Right-click on play
- menuItem.trigger('contextmenu');
- expect(state.videoPlayer.play).toHaveBeenCalled();
- expect(menuItem).toHaveText('Pause');
- });
-
- it('mouse left/right-clicking behaves as expected on mute/unmute menu item', function() {
- var menuItem = menuItems.eq(1);
- // Left-click on mute
- menuItem.click();
- expect(state.videoVolumeControl.getMuteStatus()).toBe(true);
- expect(menuItem).toHaveText('Unmute');
- openMenu();
- // Left-click on unmute
- menuItem.click();
- expect(state.videoVolumeControl.getMuteStatus()).toBe(false);
- expect(menuItem).toHaveText('Mute');
- // Right-click on mute
- menuItem.trigger('contextmenu');
- expect(state.videoVolumeControl.getMuteStatus()).toBe(true);
- expect(menuItem).toHaveText('Unmute');
- openMenu();
- // Right-click on unmute
- menuItem.trigger('contextmenu');
- expect(state.videoVolumeControl.getMuteStatus()).toBe(false);
- expect(menuItem).toHaveText('Mute');
- });
-
- it('mouse left/right-clicking behaves as expected on go to Exit full browser menu item', function() {
- var menuItem = menuItems.eq(2);
- // Left-click on Fill browser
- menuItem.click();
- expect(state.isFullScreen).toBe(true);
- expect(menuItem).toHaveText('Exit full browser');
- openMenu();
- // Left-click on Exit full browser
- menuItem.click();
- expect(state.isFullScreen).toBe(false);
- expect(menuItem).toHaveText('Fill browser');
- // Right-click on Fill browser
- menuItem.trigger('contextmenu');
- expect(state.isFullScreen).toBe(true);
- expect(menuItem).toHaveText('Exit full browser');
- openMenu();
- // Right-click on Exit full browser
- menuItem.trigger('contextmenu');
- expect(state.isFullScreen).toBe(false);
- expect(menuItem).toHaveText('Fill browser');
- });
-
- it('mouse left/right-clicking behaves as expected on speed submenu item', function() {
- // Set speed to 0.75x
- state.videoSpeedControl.setSpeed('0.75');
- // Left-click on second submenu speed (1.0x)
- openSubmenuMouse(menuSubmenuItem);
- submenuItems.eq(1).click();
-
- // Expect speed to be 1.0x
- expect(state.videoSpeedControl.currentSpeed).toBe('1.0');
- // Expect speed submenu item 0.75x not to be active
- expect(submenuItems.first()).not.toHaveClass('is-selected');
- // Expect speed submenu item 1.0x to be active
- expect(submenuItems.eq(1)).toHaveClass('is-selected');
-
- // Set speed to 0.75x
- state.videoSpeedControl.setSpeed('0.75');
- // Right-click on second submenu speed (1.0x)
- openSubmenuMouse(menuSubmenuItem);
- submenuItems.eq(1).trigger('contextmenu');
-
- // Expect speed to be 1.0x
- expect(state.videoSpeedControl.currentSpeed).toBe('1.0');
- // Expect speed submenu item 0.75x not to be active
- expect(submenuItems.first()).not.toHaveClass('is-selected');
- // Expect speed submenu item 1.0x to be active
- expect(submenuItems.eq(1)).toHaveClass('is-selected');
- });
- });
-
- describe('Keyboard interactions', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- openMenu();
- });
-
- it('focus the first item of the just opened menu on UP keydown', function() {
- menu.trigger(keyPressEvent($.ui.keyCode.UP));
- expect(menuSubmenuItem).toBeFocused();
- });
-
- it('focus the last item of the just opened menu on DOWN keydown', function() {
- menu.trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuItems.first()).toBeFocused();
- });
-
- it('open the submenu on ENTER keydown', function() {
- openSubmenuKeyboard(menuSubmenuItem, $.ui.keyCode.ENTER);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- expect(submenuItems.first()).toBeFocused();
- });
-
- it('open the submenu on SPACE keydown', function() {
- openSubmenuKeyboard(menuSubmenuItem, $.ui.keyCode.SPACE);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- expect(submenuItems.first()).toBeFocused();
- });
-
- it('open the submenu on RIGHT keydown', function() {
- openSubmenuKeyboard(menuSubmenuItem, $.ui.keyCode.RIGHT);
- expect(menuSubmenuItem).toHaveClass('is-opened');
- expect(submenuItems.first()).toBeFocused();
- });
-
- it('close the menu on ESCAPE keydown', function() {
- menu.trigger(keyPressEvent($.ui.keyCode.ESCAPE));
- expect(menu).not.toHaveClass('is-opened');
- expect(overlay).not.toBeInDOM();
- });
-
- it('close the submenu on ESCAPE keydown', function() {
- openSubmenuKeyboard(menuSubmenuItem);
- menuSubmenuItem.trigger(keyPressEvent($.ui.keyCode.ESCAPE));
- expect(menuSubmenuItem).not.toHaveClass('is-opened');
- expect(overlay).not.toBeInDOM();
- });
-
- it('close the submenu on LEFT keydown on submenu items', function() {
- closeSubmenuKeyboard(menuSubmenuItem);
- });
-
- it('do nothing on RIGHT keydown on submenu item', function() {
- submenuItems.eq(1).focus().trigger(keyPressEvent($.ui.keyCode.RIGHT)); // Mute
- // Is still focused.
- expect(submenuItems.eq(1)).toBeFocused();
- });
-
- it('do nothing on TAB keydown on menu item', function() {
- submenuItems.eq(1).focus().trigger(keyPressEvent($.ui.keyCode.TAB)); // Mute
- // Is still focused.
- expect(submenuItems.eq(1)).toBeFocused();
- });
-
- it('UP and DOWN keydown function as expected on menu/submenu items', function() {
- menuItems.eq(0).focus(); // Play
- expect(menuItems.eq(0)).toBeFocused();
- menuItems.eq(0).trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuItems.eq(1)).toBeFocused(); // Mute
- menuItems.eq(1).trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuItems.eq(2)).toBeFocused(); // Fullscreen
- menuItems.eq(2).trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuSubmenuItem).toBeFocused(); // Speed
- menuSubmenuItem.trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuItems.eq(0)).toBeFocused(); // Play
-
- menuItems.eq(0).trigger(keyPressEvent($.ui.keyCode.UP));
- expect(menuSubmenuItem).toBeFocused(); // Speed
- // Check if hidden item can be skipped correctly.
- menuItems.eq(2).hide(); // hide Fullscreen item
- menuSubmenuItem.trigger(keyPressEvent($.ui.keyCode.UP));
- expect(menuItems.eq(1)).toBeFocused(); // Mute
- menuItems.eq(1).trigger(keyPressEvent($.ui.keyCode.UP));
- expect(menuItems.eq(0)).toBeFocused(); // Play
- });
-
- it('current item is still focused if all siblings are hidden', function() {
- menuItems.eq(0).focus(); // Play
- expect(menuItems.eq(0)).toBeFocused(); // hide all siblings
- menuItems.eq(0).siblings().hide();
- menuSubmenuItem.trigger(keyPressEvent($.ui.keyCode.DOWN));
- expect(menuItems.eq(0)).toBeFocused();
- menuSubmenuItem.trigger(keyPressEvent($.ui.keyCode.UP));
- expect(menuItems.eq(0)).toBeFocused();
- });
-
- it('ENTER keydown on menu/submenu item selects its data and closes menu', function() {
- menuItems.eq(2).focus().trigger(keyPressEvent($.ui.keyCode.ENTER)); // Fullscreen
- expect(menuItems.eq(2)).toHaveClass('is-selected');
- expect(menuItems.eq(2).siblings()).not.toHaveClass('is-selected');
- expect(state.isFullScreen).toBeTruthy();
- expect(menuItems.eq(2)).toHaveText('Exit full browser');
- });
-
- it('SPACE keydown on menu/submenu item selects its data and closes menu', function() {
- submenuItems.eq(2).focus().trigger(keyPressEvent($.ui.keyCode.SPACE)); // 1.25x
- expect(submenuItems.eq(2)).toHaveClass('is-selected');
- expect(submenuItems.eq(2).siblings()).not.toHaveClass('is-selected');
- expect(state.videoSpeedControl.currentSpeed).toBe('1.25');
- });
- });
- });
-}());
diff --git a/xmodule/js/spec/video/video_control_spec.js b/xmodule/js/spec/video/video_control_spec.js
deleted file mode 100644
index 248c3c31d2be..000000000000
--- a/xmodule/js/spec/video/video_control_spec.js
+++ /dev/null
@@ -1,524 +0,0 @@
-(function(WAIT_TIMEOUT) {
- 'use strict';
-
- describe('VideoControl', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- state.videoPlayer.destroy();
- window.onTouchBasedDevice = oldOTBD;
- });
-
- describe('constructor', function() {
- beforeEach(function() {
- window.VideoState = {};
- state = jasmine.initializePlayer();
- });
-
- it('render the video controls', function() {
- expect($('.video-controls')).toContainElement(
- [
- '.slider',
- 'ul.vcr',
- 'a.play',
- '.vidtime'
- ].join(',')
- );
-
- expect($('.video-controls').find('.vidtime'))
- .toHaveText('0:00 / 0:00');
- });
- });
-
- describe('constructor with start-time', function() {
- it(
- 'saved position is 0, timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- savedVideoPosition: 0
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
- return isFinite(duration) && duration > 0 && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 1:00');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
- }).always(done);
- });
-
- it(
- 'saved position is after start-time, '
- + 'timer slider and VCR set to saved position',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- savedVideoPosition: 15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:15 / 1:00');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(15);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is negative, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- savedVideoPosition: -15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 1:00');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is not a number, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- savedVideoPosition: 'a'
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 1:00');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is greater than end-time, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- savedVideoPosition: 10000
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 1:00');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
- });
-
- describe('constructor with end-time', function() {
- it(
- 'saved position is 0, timer slider and VCR set to 0:00 '
- + 'and ending at specified end-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- end: 20,
- savedVideoPosition: 0
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:00 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(0);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is after start-time, '
- + 'timer slider and VCR set to saved position',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- end: 20,
- savedVideoPosition: 15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:15 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(15);
-
- state.storage.clear();
- }).always(done);
- });
-
- // TODO: Fix!
- it(
- 'saved position is negative, timer slider and VCR set to 0:00',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- end: 20,
- savedVideoPosition: -15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:00 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(0);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is not a number, '
- + 'timer slider and VCR set to 0:00',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- end: 20,
- savedVideoPosition: 'a'
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:00 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(0);
-
- state.storage.clear();
- }).always(done);
- });
-
- // TODO: Fix!
- it(
- 'saved position is greater than end-time, '
- + 'timer slider and VCR set to 0:00',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- end: 20,
- savedVideoPosition: 10000
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:00 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(0);
-
- state.storage.clear();
- }).always(done);
- });
- });
-
- describe('constructor with start-time and end-time', function() {
- it(
- 'saved position is 0, timer slider and VCR set to appropriate start and end times',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- end: 20,
- savedVideoPosition: 0
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is after start-time, '
- + 'timer slider and VCR set to saved position',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- end: 20,
- savedVideoPosition: 15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:15 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(15);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is negative, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- end: 20,
- savedVideoPosition: -15
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is not a number, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- end: 20,
- savedVideoPosition: 'a'
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
-
- it(
- 'saved position is greater than end-time, '
- + 'timer slider and VCR set to start-time',
- function(done) {
- var duration, sliderEl, expectedValue;
-
- window.VideoState = {};
- state = jasmine.initializePlayer({
- start: 10,
- end: 20,
- savedVideoPosition: 10000
- });
- sliderEl = state.videoProgressSlider.slider;
- spyOn(state.videoPlayer, 'duration').and.returnValue(60);
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return isFinite(duration) && duration > 0
- && isFinite(state.videoPlayer.startTime);
- }).then(function() {
- expectedValue = $('.video-controls').find('.vidtime');
- expect(expectedValue).toHaveText('0:10 / 0:20');
-
- expectedValue = sliderEl.slider('option', 'value');
- expect(expectedValue).toBe(10);
-
- state.storage.clear();
- }).always(done);
- });
- });
-
- it('show', function() {
- var controls;
- state = jasmine.initializePlayer();
- controls = state.el.find('.video-controls');
- controls.addClass('is-hidden');
-
- state.videoControl.show();
- expect(controls).not.toHaveClass('is-hidden');
- });
-
- it('can destroy itself', function() {
- state = jasmine.initializePlayer();
- state.videoControl.destroy();
- expect(state.videoControl).toBeUndefined();
- });
-
- it('can focus the first control', function(done) {
- var btnPlay;
- state = jasmine.initializePlayer({focusFirstControl: true});
- btnPlay = state.el.find('.video-controls .play');
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-initialized');
- }).then(function() {
- expect(btnPlay).toBeFocused();
- }).always(done);
- });
- });
-}).call(this, window.WAIT_TIMEOUT);
diff --git a/xmodule/js/spec/video/video_events_bumper_plugin_spec.js b/xmodule/js/spec/video/video_events_bumper_plugin_spec.js
deleted file mode 100644
index b613166987b6..000000000000
--- a/xmodule/js/spec/video/video_events_bumper_plugin_spec.js
+++ /dev/null
@@ -1,158 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- 'use strict';
-
- describe('VideoPlayer Events Bumper plugin', function() {
- var Logger = window.Logger;
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- state = jasmine.initializePlayer('video_with_bumper.html');
- spyOn(Logger, 'log');
- $('.poster .btn-play').click();
- spyOn(state.bumperState.videoEventsBumperPlugin, 'getCurrentTime').and.returnValue(10);
- spyOn(state.bumperState.videoEventsBumperPlugin, 'getDuration').and.returnValue(20);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- if (state.bumperState && state.bumperState.videoPlayer) {
- state.bumperState.videoPlayer.destroy();
- }
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- });
-
- it('can emit "edx.video.bumper.loaded" event', function() {
- state.el.trigger('ready');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.loaded', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.played" event', function() {
- state.el.trigger('play');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.played', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.stopped" event', function() {
- state.el.trigger('ended');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.stopped', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
-
- Logger.log.calls.reset();
- state.el.trigger('stop');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.stopped', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.skipped" event', function() {
- state.el.trigger('skip', [false]);
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.skipped', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.dismissed" event', function() {
- state.el.trigger('skip', [true]);
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.dismissed', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.transcript.menu.shown" event', function() {
- state.el.trigger('language_menu:show');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.shown', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.transcript.menu.hidden" event', function() {
- state.el.trigger('language_menu:hide');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.hidden', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.transcript.shown" event', function() {
- state.el.trigger('captions:show');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.shown', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can emit "edx.video.bumper.transcript.hidden" event', function() {
- state.el.trigger('captions:hide');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.hidden', {
- host_component_id: 'id',
- bumper_id: '/base/fixtures/test.mp4',
- code: 'html5',
- currentTime: 10,
- duration: 20
- });
- });
-
- it('can destroy itself', function() {
- var plugin = state.bumperState.videoEventsBumperPlugin;
- spyOn($.fn, 'off').and.callThrough();
- plugin.destroy();
- expect(state.bumperState.videoEventsBumperPlugin).toBeUndefined();
- expect($.fn.off).toHaveBeenCalledWith({
- ready: plugin.onReady,
- play: plugin.onPlay,
- 'ended stop': plugin.onEnded,
- skip: plugin.onSkip,
- 'language_menu:show': plugin.onShowLanguageMenu,
- 'language_menu:hide': plugin.onHideLanguageMenu,
- 'captions:show': plugin.onShowCaptions,
- 'captions:hide': plugin.onHideCaptions,
- destroy: plugin.destroy
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_events_plugin_spec.js b/xmodule/js/spec/video/video_events_plugin_spec.js
deleted file mode 100644
index 860cfb5e07ba..000000000000
--- a/xmodule/js/spec/video/video_events_plugin_spec.js
+++ /dev/null
@@ -1,259 +0,0 @@
-import '../helper.js';
-
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- 'use strict';
-
- var describeInfo, state, oldOTBD;
-
- describeInfo = new jasmine.DescribeInfo('', function() {
- var Logger = window.Logger;
-
- beforeEach(function() {
- spyOn(Logger, 'log');
- spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- });
-
- it('can emit "load_video" event', function() {
- state.el.trigger('ready');
- expect(Logger.log).toHaveBeenCalledWith('load_video', {
- id: 'id',
- code: this.code,
- duration: this.duration
- });
- });
-
- it('can emit "play_video" event when emitPlayVideoEvent is true', function() {
- state.videoEventsPlugin.emitPlayVideoEvent = true;
- state.el.trigger('play');
- expect(Logger.log).toHaveBeenCalledWith('play_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeFalsy();
- });
-
- it('can not emit "play_video" event when emitPlayVideoEvent is false', function() {
- state.videoEventsPlugin.emitPlayVideoEvent = false;
- state.el.trigger('play');
- expect(Logger.log).not.toHaveBeenCalled();
- });
-
- it('can emit "pause_video" event', function() {
- state.el.trigger('pause');
- expect(Logger.log).toHaveBeenCalledWith('pause_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
- });
-
- it('can emit "complete_video" event when video is marked as complete', function() {
- state.el.trigger('complete');
- expect(Logger.log).toHaveBeenCalledWith('complete_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- });
-
- it('can emit "speed_change_video" event', function() {
- state.el.trigger('speedchange', ['2.0', '1.0']);
- expect(Logger.log).toHaveBeenCalledWith('speed_change_video', {
- id: 'id',
- code: this.code,
- current_time: 10,
- old_speed: '1.0',
- new_speed: '2.0',
- duration: this.duration
- });
- });
-
- it('can emit "seek_video" event', function() {
- state.el.trigger('seek', [1, 0, 'any']);
- expect(Logger.log).toHaveBeenCalledWith('seek_video', {
- id: 'id',
- code: this.code,
- old_time: 0,
- new_time: 1,
- type: 'any',
- duration: this.duration
- });
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
- });
-
- it('can emit "play_video" event after "seek_video" event ', function() {
- state.videoEventsPlugin.emitPlayVideoEvent = false;
- state.el.trigger('seek', [1, 0, 'any']);
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
- });
-
- it('can emit "stop_video" event', function() {
- state.el.trigger('ended');
- expect(Logger.log).toHaveBeenCalledWith('stop_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
-
- Logger.log.calls.reset();
- state.el.trigger('stop');
- expect(Logger.log).toHaveBeenCalledWith('stop_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
- });
-
- it('can emit "skip_video" event', function() {
- state.el.trigger('skip', [false]);
- expect(Logger.log).toHaveBeenCalledWith('skip_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- });
-
- it('can emit "do_not_show_again_video" event', function() {
- state.el.trigger('skip', [true]);
- expect(Logger.log).toHaveBeenCalledWith('do_not_show_again_video', {
- id: 'id',
- code: this.code,
- currentTime: 10,
- duration: this.duration
- });
- });
-
- it('can emit "edx.video.language_menu.shown" event', function() {
- state.el.trigger('language_menu:show');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.shown', {
- id: 'id',
- code: this.code,
- duration: this.duration
- });
- });
-
- it('can emit "edx.video.language_menu.hidden" event', function() {
- state.el.trigger('language_menu:hide');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.hidden', {
- id: 'id',
- code: this.code,
- language: 'en',
- duration: this.duration
- });
- });
-
- it('can emit "show_transcript" event', function() {
- state.el.trigger('transcript:show');
- expect(Logger.log).toHaveBeenCalledWith('show_transcript', {
- id: 'id',
- code: this.code,
- current_time: 10,
- duration: this.duration
- });
- });
-
- it('can emit "hide_transcript" event', function() {
- state.el.trigger('transcript:hide');
- expect(Logger.log).toHaveBeenCalledWith('hide_transcript', {
- id: 'id',
- code: this.code,
- current_time: 10,
- duration: this.duration
- });
- });
-
- it('can emit "edx.video.closed_captions.shown" event', function() {
- state.el.trigger('captions:show');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.shown', {
- id: 'id',
- code: this.code,
- current_time: 10,
- duration: this.duration
- });
- });
-
- it('can emit "edx.video.closed_captions.hidden" event', function() {
- state.el.trigger('captions:hide');
- expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.hidden', {
- id: 'id',
- code: this.code,
- current_time: 10,
- duration: this.duration
- });
- });
-
- it('can destroy itself', function() {
- var plugin = state.videoEventsPlugin;
- spyOn($.fn, 'off').and.callThrough();
- state.videoEventsPlugin.destroy();
- expect(state.videoEventsPlugin).toBeUndefined();
- expect($.fn.off).toHaveBeenCalledWith({
- ready: plugin.onReady,
- play: plugin.onPlay,
- pause: plugin.onPause,
- complete: plugin.onComplete,
- 'ended stop': plugin.onEnded,
- seek: plugin.onSeek,
- skip: plugin.onSkip,
- speedchange: plugin.onSpeedChange,
- autoadvancechange: plugin.onAutoAdvanceChange,
- 'language_menu:show': plugin.onShowLanguageMenu,
- 'language_menu:hide': plugin.onHideLanguageMenu,
- 'transcript:show': plugin.onShowTranscript,
- 'transcript:hide': plugin.onHideTranscript,
- 'captions:show': plugin.onShowCaptions,
- 'captions:hide': plugin.onHideCaptions,
- destroy: plugin.destroy
- });
- });
- });
-
- describe('VideoPlayer Events plugin', function() {
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
- });
-
- describe('html5 encoding only', function() {
- beforeEach(function(done) {
- this.code = 'html5';
- this.duration = 111;
- state = jasmine.initializePlayer('video_html5.html');
- done();
- });
- jasmine.getEnv().describe(describeInfo.description, describeInfo.specDefinitions);
- });
-
- describe('hls encoding', function() {
- beforeEach(function(done) {
- this.code = 'hls';
- this.duration = 111;
- state = jasmine.initializeHLSPlayer();
- done();
- });
- jasmine.getEnv().describe(describeInfo.description, describeInfo.specDefinitions);
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_focus_grabber_spec.js b/xmodule/js/spec/video/video_focus_grabber_spec.js
deleted file mode 100644
index 9aca50e97cad..000000000000
--- a/xmodule/js/spec/video/video_focus_grabber_spec.js
+++ /dev/null
@@ -1,108 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('Video FocusGrabber', function() {
- var state;
-
- beforeEach(function() {
- // https://github.com/pivotal/jasmine/issues/184
- //
- // This is a known issue. jQuery animations depend on setTimeout
- // and the jasmine mock clock stubs that function. You need to turn
- // off jQuery animations ($.fx.off()) in a global beforeEach.
- //
- // I think this is a good pattern - you don't want animations
- // messing with your tests. If you need to test with animations on
- // I suggest you add incremental browser-based testing to your
- // stack.
- jQuery.fx.off = true;
-
- jasmine.stubRequests();
- loadFixtures('video_html5.html');
- state = new Video('#example');
-
- spyOnEvent(state.el, 'mousemove');
- spyOn(state.focusGrabber, 'disableFocusGrabber').and.callThrough();
- spyOn(state.focusGrabber, 'enableFocusGrabber').and.callThrough();
- });
-
- afterEach(function() {
- // Turn jQuery animations back on.
- jQuery.fx.off = true;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it(
- 'check existence of focus grabber elements and their position',
- function() {
- var firstFGEl = state.el.find('.focus_grabber.first'),
- lastFGEl = state.el.find('.focus_grabber.last'),
- tcWrapperEl = state.el.find('.tc-wrapper');
-
- // Existence check.
- expect(firstFGEl.length).toBe(1);
- expect(lastFGEl.length).toBe(1);
-
- // Position check.
- expect(firstFGEl.index() + 1).toBe(tcWrapperEl.index());
- expect(lastFGEl.index() - 1).toBe(tcWrapperEl.index());
- });
-
- it('from the start, focus grabbers are disabled', function() {
- expect(state.focusGrabber.elFirst.attr('tabindex')).toBe('-1');
- expect(state.focusGrabber.elLast.attr('tabindex')).toBe('-1');
- });
-
- it(
- 'when first focus grabber is focused "mousemove" event is '
- + 'triggered, grabbers are disabled',
- function() {
- state.focusGrabber.elFirst.triggerHandler('focus');
-
- expect('mousemove').toHaveBeenTriggeredOn(state.el);
- expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled();
- });
-
- it(
- 'when last focus grabber is focused "mousemove" event is '
- + 'triggered, grabbers are disabled',
- function() {
- state.focusGrabber.elLast.triggerHandler('focus');
-
- expect('mousemove').toHaveBeenTriggeredOn(state.el);
- expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled();
- });
-
- // Disabled on 18.11.2013 due to flakiness on local dev machine.
- //
- // Video FocusGrabber: after controls hide focus grabbers are
- // enabled [fail]
- // Expected spy enableFocusGrabber to have been called.
- //
- // Approximately 1 in 8 times this test fails.
- //
- // TODO: Most likely, focusGrabber will be disabled in the future. This
- // test could become unneeded in the future.
- xit('after controls hide focus grabbers are enabled', function() {
- runs(function() {
- // Captions should not be "sticky" for the autohide mechanism
- // to work.
- state.videoCaption.hideCaptions(true);
-
- // Make sure that the controls are visible. After this event
- // is triggered a count down is started to autohide captions.
- state.el.triggerHandler('mousemove');
- });
-
- // Wait for the autohide to happen. We make it +100ms to make sure
- // that there is clearly no race conditions for our expect below.
- waits(state.videoControl.fadeOutTimeout + 100);
-
- runs(function() {
- expect(
- state.focusGrabber.enableFocusGrabber
- ).toHaveBeenCalled();
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_full_screen_spec.js b/xmodule/js/spec/video/video_full_screen_spec.js
deleted file mode 100644
index 46e4482e2d9b..000000000000
--- a/xmodule/js/spec/video/video_full_screen_spec.js
+++ /dev/null
@@ -1,99 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoFullScreen', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- state.videoPlayer.destroy();
- window.onTouchBasedDevice = oldOTBD;
- });
-
- describe('constructor', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- jasmine.mockFullscreenAPI();
- });
-
- it('renders the fullscreen control', function() {
- expect($('.add-fullscreen')).toExist();
- expect(state.videoFullScreen.fullScreenState).toBe(false);
- });
-
- it('correctly adds ARIA attributes to fullscreen control', function() {
- var $fullScreenControl = $('.add-fullscreen');
-
- expect($fullScreenControl).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('correctly triggers the event handler to toggle fullscreen mode', function() {
- spyOn(state.videoFullScreen, 'exit');
- spyOn(state.videoFullScreen, 'enter');
-
- state.videoFullScreen.fullScreenState = false;
- state.videoFullScreen.toggle();
- expect(state.videoFullScreen.enter).toHaveBeenCalled();
-
- state.videoFullScreen.fullScreenState = true;
- state.videoFullScreen.toggle();
- expect(state.videoFullScreen.exit).toHaveBeenCalled();
- });
-
- it('correctly updates ARIA on state change', function() {
- var $fullScreenControl = $('.add-fullscreen');
- $fullScreenControl.click();
- expect($fullScreenControl).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- $fullScreenControl.click();
- expect($fullScreenControl).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('correctly can out of fullscreen by pressing esc', function() {
- spyOn(state.videoCommands, 'execute');
- var esc = $.Event('keyup');
- esc.keyCode = 27;
- state.isFullScreen = true;
- $(document).trigger(esc);
- expect(state.videoCommands.execute).toHaveBeenCalledWith('toggleFullScreen');
- });
-
- it('can update video dimensions on state change', function() {
- state.videoFullScreen.enter();
- expect(state.resizer.setMode).toHaveBeenCalledWith('both');
- state.videoFullScreen.exit();
- expect(state.resizer.setMode).toHaveBeenCalledWith('width');
- });
-
- it('can destroy itself', function() {
- state.videoFullScreen.destroy();
- expect($('.add-fullscreen')).not.toExist();
- expect(state.videoFullScreen).toBeUndefined();
- });
- });
-
- it('Controls height is actual on switch to fullscreen', function() {
- spyOn($.fn, 'height').and.callFake(function(val) {
- return _.isUndefined(val) ? 100 : this;
- });
-
- state = jasmine.initializePlayer();
-
- state.videoFullScreen.enter();
- expect(state.videoFullScreen.height).toBe(150);
- state.videoFullScreen.exit();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_play_pause_control_spec.js b/xmodule/js/spec/video/video_play_pause_control_spec.js
deleted file mode 100644
index d6af3515383f..000000000000
--- a/xmodule/js/spec/video/video_play_pause_control_spec.js
+++ /dev/null
@@ -1,63 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoPlayPauseControl', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- state = jasmine.initializePlayer();
- spyOn(state.videoCommands, 'execute');
- spyOn(state.videoSaveStatePlugin, 'saveState');
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- state.videoPlayer.destroy();
- window.onTouchBasedDevice = oldOTBD;
- });
-
- it('can render the control', function() {
- expect($('.video_control.play')).toExist();
- });
-
- it('add ARIA attributes to play control', function() {
- expect($('.video_control.play')).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('can update ARIA state on play', function() {
- state.el.trigger('play');
- expect($('.video_control.pause')).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('can update ARIA state on video ends', function() {
- state.el.trigger('play');
- state.el.trigger('ended');
- expect($('.video_control.play')).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('can update state on pause', function() {
- state.el.trigger('pause');
- expect(state.videoSaveStatePlugin.saveState).toHaveBeenCalledWith(true);
- });
-
- it('can start video playing on click', function() {
- $('.video_control.play').click();
- expect(state.videoCommands.execute).toHaveBeenCalledWith('togglePlayback');
- });
-
- it('can destroy itself', function() {
- state.videoPlayPauseControl.destroy();
- expect(state.videoPlayPauseControl).toBeUndefined();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_play_placeholder_spec.js b/xmodule/js/spec/video/video_play_placeholder_spec.js
deleted file mode 100644
index f43280ec39d6..000000000000
--- a/xmodule/js/spec/video/video_play_placeholder_spec.js
+++ /dev/null
@@ -1,149 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoPlayPlaceholder', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(['iPad']);
-
- state = jasmine.initializePlayer();
- spyOn(state.videoCommands, 'execute');
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- state.videoPlayer.destroy();
- window.onTouchBasedDevice = oldOTBD;
- });
-
- var cases = [
- {
- name: 'PC',
- isShown: false,
- isTouch: null
- }, {
- name: 'iPad',
- isShown: true,
- isTouch: ['iPad']
- }, {
- name: 'Android',
- isShown: true,
- isTouch: ['Android']
- }, {
- name: 'iPhone',
- isShown: false,
- isTouch: ['iPhone']
- }
- ];
-
- beforeEach(function() {
- jasmine.stubRequests();
- spyOn(window.YT, 'Player').and.callThrough();
- });
-
- it('works correctly on calling proper methods', function() {
- var btnPlay;
-
- state = jasmine.initializePlayer();
- btnPlay = state.el.find('.btn-play');
-
- state.videoPlayPlaceholder.show();
-
- expect(btnPlay).not.toHaveClass('is-hidden');
- expect(btnPlay).toHaveAttrs({
- 'aria-hidden': 'false',
- tabindex: '0'
- });
-
- state.videoPlayPlaceholder.hide();
-
- expect(btnPlay).toHaveClass('is-hidden');
- expect(btnPlay).toHaveAttrs({
- 'aria-hidden': 'true',
- tabindex: '-1'
- });
- });
-
- $.each(cases, function(index, data) {
- var message = [
- (data.isShown) ? 'is' : 'is not',
- ' shown on',
- data.name
- ].join('');
-
- it(message, function() {
- var btnPlay;
-
- window.onTouchBasedDevice.and.returnValue(data.isTouch);
- state = jasmine.initializePlayer();
- btnPlay = state.el.find('.btn-play');
-
- if (data.isShown) {
- expect(btnPlay).not.toHaveClass('is-hidden');
- } else {
- expect(btnPlay).toHaveClass('is-hidden');
- }
- });
- });
-
- $.each(['iPad', 'Android'], function(index, device) {
- it(
- 'is shown on paused video on ' + device
- + ' in HTML5 player',
- function() {
- var btnPlay;
-
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayer();
- btnPlay = state.el.find('.btn-play');
-
- state.el.trigger('play');
- state.el.trigger('pause');
- expect(btnPlay).not.toHaveClass('is-hidden');
- });
-
- it(
- 'is hidden on playing video on ' + device
- + ' in HTML5 player',
- function() {
- var btnPlay;
-
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayer();
- btnPlay = state.el.find('.btn-play');
-
- state.el.trigger('play');
- expect(btnPlay).toHaveClass('is-hidden');
- });
-
- it(
- 'is hidden on paused video on ' + device
- + ' in YouTube player',
- function() {
- var btnPlay;
-
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayerYouTube();
- btnPlay = state.el.find('.btn-play');
-
- state.el.trigger('play');
- state.el.trigger('pause');
- expect(btnPlay).toHaveClass('is-hidden');
- });
- });
-
- it('starts play the video on click', function() {
- $('.btn-play').click();
- expect(state.videoCommands.execute).toHaveBeenCalledWith('play');
- });
-
- it('can destroy itself', function() {
- state.videoPlayPlaceholder.destroy();
- expect(state.videoPlayPlaceholder).toBeUndefined();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_play_skip_control_spec.js b/xmodule/js/spec/video/video_play_skip_control_spec.js
deleted file mode 100644
index 88bf7ab9e47e..000000000000
--- a/xmodule/js/spec/video/video_play_skip_control_spec.js
+++ /dev/null
@@ -1,60 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoPlaySkipControl', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- state = jasmine.initializePlayer('video_with_bumper.html');
- $('.poster .btn-play').click();
- spyOn(state.bumperState.videoCommands, 'execute');
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- if (state.bumperState && state.bumperState.videoPlayer) {
- state.bumperState.videoPlayer.destroy();
- }
- window.onTouchBasedDevice = oldOTBD;
- if (state.videoPlayer) {
- _.result(state.videoPlayer, 'destroy');
- }
- });
-
- it('can render the control', function() {
- expect($('.video_control.play')).toBeInDOM();
- });
-
- it('can update state on play', function() {
- state.el.trigger('play');
- expect($('.video_control.play')).not.toBeInDOM();
- expect($('.video_control.skip')).toBeInDOM();
- });
-
- it('can start video playing on click', function() {
- $('.video_control.play').click();
- expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('play');
- });
-
- it('can skip the video on click', function() {
- state.el.trigger('play');
- spyOn(state.bumperState.videoPlayer, 'isPlaying').and.returnValue(true);
- $('.video_control.skip').first().click();
- expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('skip');
- });
-
- it('can destroy itself', function() {
- var plugin = state.bumperState.videoPlaySkipControl,
- el = plugin.el;
- spyOn($.fn, 'off').and.callThrough();
- plugin.destroy();
- expect(state.bumperState.videoPlaySkipControl).toBeUndefined();
- expect(el).not.toBeInDOM();
- expect($.fn.off).toHaveBeenCalledWith('destroy', plugin.destroy);
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_player_spec.js b/xmodule/js/spec/video/video_player_spec.js
deleted file mode 100644
index 4845fc80fa1d..000000000000
--- a/xmodule/js/spec/video/video_player_spec.js
+++ /dev/null
@@ -1,1101 +0,0 @@
-/* global YT */
-
-// eslint-disable-next-line no-shadow-restricted-names
-(function(require, define, undefined) {
- 'use strict';
-
- require(
- ['video/03_video_player.js', 'hls', 'underscore'],
- function(VideoPlayer, HLS, _) {
- describe('VideoPlayer', function() {
- var STATUS = window.STATUS,
- state,
- oldOTBD,
- emptyArguments;
-
- (function() {
- emptyArguments = arguments;
- }());
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
- .and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- window.Video.previousState = null;
- if (state.storage) {
- state.storage.clear();
- }
- if (state.videoPlayer) {
- _.result(state.videoPlayer, 'destroy');
- }
- });
-
- describe('constructor', function() {
- describe('always', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- state.videoEl = $('video, iframe');
- });
-
- it('instanticate current time to zero', function() {
- expect(state.videoPlayer.currentTime).toEqual(0);
- });
-
- it('set the element', function() {
- expect(state.el).toHaveId('video_id');
- });
-
- it('create video control', function() {
- expect(state.videoControl).toBeDefined();
- expect(state.videoControl.el).toHaveClass('video-controls');
- });
-
- it('create video caption', function() {
- expect(state.videoCaption).toBeDefined();
- expect(state.speed).toEqual(1.5);
- expect(state.config.transcriptTranslationUrl)
- .toEqual('/transcript/translation/__lang__');
- });
-
- it('create video speed control', function() {
- expect(state.videoSpeedControl).toBeDefined();
- expect(state.videoSpeedControl.el).toHaveClass('speeds');
- expect(state.speed).toEqual(1.5);
- });
-
- it('create video progress slider', function() {
- expect(state.videoProgressSlider).toBeDefined();
- expect(state.videoProgressSlider.el).toHaveClass('slider');
- });
-
- // All the toHandleWith() expect tests are not necessary for
- // this version of Video. jQuery event system is not used to
- // trigger and invoke methods. This is an artifact from
- // previous version of Video.
- });
-
- it('create Youtube player', function() {
- var events;
-
- jasmine.stubRequests();
- spyOn(window.YT, 'Player').and.callThrough();
- state = jasmine.initializePlayerYouTube();
- state.videoEl = $('video, iframe');
-
- events = {
- onReady: state.videoPlayer.onReady,
- onStateChange: state.videoPlayer.onStateChange,
- onPlaybackQualityChange: state.videoPlayer.onPlaybackQualityChange,
- onError: state.videoPlayer.onError
- };
-
- expect(YT.Player).toHaveBeenCalledWith('id', {
- playerVars: {
- controls: 0,
- wmode: 'transparent',
- rel: 0,
- showinfo: 0,
- enablejsapi: 1,
- modestbranding: 1,
- html5: 1,
- cc_load_policy: 0
- },
- videoId: 'cogebirgzzM',
- events: events
- });
- });
-
- it('create Flash player', function() {
- var player;
-
- spyOn($.fn, 'trigger');
- state = jasmine.initializePlayerYouTube();
- state.videoEl = state.el.find('video, iframe').width(100);
- player = state.videoPlayer.player;
- player.getAvailablePlaybackRates.and.returnValue([1]);
- state.currentPlayerMode = 'html5';
- spyOn(window.YT, 'Player').and.callThrough();
- state.videoPlayer.onReady();
-
- expect(YT.Player).toHaveBeenCalledWith('id', {
- playerVars: {
- controls: 0,
- wmode: 'transparent',
- rel: 0,
- showinfo: 0,
- enablejsapi: 1,
- modestbranding: 1,
- cc_load_policy: 0
- },
- videoId: 'abcdefghijkl',
- events: jasmine.any(Object)
- });
-
- expect(state.resizer.setElement).toHaveBeenCalled();
- expect(state.resizer.align).toHaveBeenCalled();
- });
-
- // We can't test the invocation of HTML5Video because it is not
- // available globally. It is defined within the scope of Require
- // JS.
-
- describe('when on a touch based device', function() {
- $.each(['iPad', 'Android'], function(index, device) {
- it('create video volume control on' + device, function() {
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- expect(state.el.find('.volume')).not.toExist();
- });
- });
- });
-
- describe('when not on a touch based device', function() {
- // eslint-disable-next-line no-shadow
- var oldOTBD;
-
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
- });
-
- it('controls are in paused state', function() {
- expect(state.videoPlayer.isPlaying()).toBe(false);
- });
- });
- });
-
- describe('onReady', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
- spyOn(state.videoPlayer, 'play').and.callThrough();
- state.videoPlayer.onReady();
- });
-
- it('autoplay the first video', function() {
- expect(state.videoPlayer.play).not.toHaveBeenCalled();
- });
-
- it('invalid endTime is reset to null', function() {
- expect(state.videoPlayer.endTime).toBe(null);
- });
- });
-
- describe('onReady YouTube', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube();
-
- state.videoEl = $('video, iframe');
- });
-
- it('multiple speeds and flash mode, change back to html5 mode', function() {
- var playbackRates = state.videoPlayer.player.getAvailablePlaybackRates();
-
- state.currentPlayerMode = 'flash';
- state.videoPlayer.onReady();
- expect(playbackRates.length).toBe(4);
- expect(state.currentPlayerMode).toBe('html5');
- });
- });
-
- describe('onStateChange Youtube', function() {
- describe('when the video is ended', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube();
-
- state.videoEl = $('video, iframe');
- spyOn($.fn, 'trigger').and.callThrough();
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.ENDED
- });
- });
-
- it('pause the video control', function() {
- expect($('.video_control')).toHaveClass('play');
- });
-
- it('trigger pause and ended events', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('pause', emptyArguments);
- expect($.fn.trigger).toHaveBeenCalledWith('ended', emptyArguments);
- });
- });
- });
-
- describe('onStateChange', function() {
- describe('when the video is unstarted', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- state.videoEl = $('video, iframe');
- spyOn($.fn, 'trigger').and.callThrough();
-
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.PAUSED
- });
- });
-
- it('pause the video control', function() {
- expect($('.video_control')).toHaveClass('play');
- });
-
- it('pause the video caption', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('pause', emptyArguments);
- });
- });
-
- describe('when the video is playing', function() {
- var oldState;
-
- beforeEach(function() {
- // Create the first instance of the player.
- state = jasmine.initializePlayer();
- oldState = state;
-
- spyOn(oldState.videoPlayer, 'onPause').and.callThrough();
-
- // Now initialize a second instance.
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- spyOn(window, 'setInterval').and.returnValue(100);
- spyOn($.fn, 'trigger').and.callThrough();
-
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.PLAYING
- });
- });
-
- it('set update interval', function() {
- expect(window.setInterval).toHaveBeenCalledWith(
- state.videoPlayer.update, 200
- );
- expect(state.videoPlayer.updateInterval).toEqual(100);
- });
-
- it('play the video control', function() {
- expect($('.video_control')).toHaveClass('pause');
- });
-
- it('play the video caption', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('play', emptyArguments);
- });
- });
-
- describe('when the video is paused', function() {
- var currentUpdateIntrval;
-
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- spyOn($.fn, 'trigger').and.callThrough();
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.PLAYING
- });
-
- currentUpdateIntrval = state.videoPlayer.updateInterval;
-
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.PAUSED
- });
- });
-
- it('clear update interval', function() {
- expect(state.videoPlayer.updateInterval).toBeUndefined();
- });
-
- it('pause the video control', function() {
- expect($('.video_control')).toHaveClass('play');
- });
-
- it('pause the video caption', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('pause', emptyArguments);
- });
- });
-
- describe('when the video is ended', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
- spyOn($.fn, 'trigger').and.callThrough();
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.ENDED
- });
- });
-
- it('pause the video control', function() {
- expect($('.video_control')).toHaveClass('play');
- });
-
- it('pause the video caption', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('ended', emptyArguments);
- });
- });
- });
-
- describe('onSeek Youtube', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube();
- state.videoEl = $('video, iframe');
- });
-
- describe('when the video is playing', function() {
- beforeEach(function() {
- state.videoPlayer.onStateChange({
- data: YT.PlayerState.PLAYING
- });
- });
-
- it('Video has started playing', function() {
- expect($('.video_control')).toHaveClass('pause');
- });
-
- it('seek the player', function() {
- state.videoPlayer.seekTo(10);
- expect(state.videoPlayer.currentTime).toBe(10);
- });
- });
- });
-
- describe('onSeek', function() {
- beforeEach(function() {
- // jasmine.Clock can't be used to fake out debounce with newer versions of underscore
- spyOn(_, 'debounce').and.callFake(function(func) {
- return function() {
- func.apply(this, arguments);
- };
- });
- state = jasmine.initializePlayer();
- state.videoEl = $('video, iframe');
- spyOn(state.videoPlayer, 'duration').and.returnValue(120);
- });
-
- describe('when the video is playing', function() {
- it('call runTimer in seekTo on player', function(done) {
- state.videoPlayer.play();
- jasmine.waitUntil(function() {
- return state.videoPlayer.isPlaying();
- }).then(function() {
- spyOn(state.videoPlayer, 'stopTimer').and.callThrough();
- spyOn(state.videoPlayer, 'runTimer').and.callThrough();
- state.videoPlayer.seekTo(10);
- expect(state.videoPlayer.currentTime).toBe(10);
- expect(state.videoPlayer.stopTimer).toHaveBeenCalled();
- expect(state.videoPlayer.runTimer).toHaveBeenCalled();
- }).always(done);
- });
-
- it('seek the player', function() {
- spyOn(state.videoPlayer.player, 'seekTo').and.callThrough();
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 30}
- );
- expect(state.videoPlayer.currentTime).toBe(30);
- expect(state.videoPlayer.player.seekTo).toHaveBeenCalledWith(30, true);
- });
-
- it('call updatePlayTime on player', function() {
- spyOn(state.videoPlayer, 'updatePlayTime').and.callThrough();
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 30}
- );
- expect(state.videoPlayer.currentTime).toBe(30);
- expect(state.videoPlayer.updatePlayTime).toHaveBeenCalledWith(30, true);
- });
- });
-
- it('when the player is not playing: set the current time', function() {
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 20}
- );
- state.videoPlayer.pause();
- expect(state.videoPlayer.currentTime).toBe(20);
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 10}
- );
- expect(state.videoPlayer.currentTime).toBe(10);
- });
-
- describe('when the video is not playing', function() {
- beforeEach(function() {
- spyOn(state.videoPlayer, 'setPlaybackRate')
- .and.callThrough();
- });
-
- it('video has a correct speed', function() {
- state.speed = '2.0';
- state.videoPlayer.onPlay();
- expect(state.videoPlayer.setPlaybackRate)
- .toHaveBeenCalledWith('2.0');
- state.videoPlayer.onPlay();
- expect(state.videoPlayer.setPlaybackRate.calls.count())
- .toEqual(1);
- });
- });
- });
-
- describe('onVolumeChange', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- state.videoPlayer.onReady();
- state.videoEl = $('video, iframe');
- });
-
- it('set the volume on player', function() {
- spyOn(state.videoPlayer.player, 'setVolume');
- state.videoPlayer.onVolumeChange(60);
- expect(state.videoPlayer.player.setVolume)
- .toHaveBeenCalledWith(60);
- });
-
- describe('when the video is not playing', function() {
- beforeEach(function() {
- state.videoPlayer.player.setVolume('1');
- });
-
- it('video has a correct volume', function() {
- spyOn(state.videoPlayer.player, 'setVolume');
- state.videoVolumeControl.volume = 26;
- state.el.trigger('play');
- expect(state.videoPlayer.player.setVolume)
- .toHaveBeenCalledWith(26);
- });
- });
- });
-
- describe('update', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- spyOn(state.videoPlayer, 'updatePlayTime').and.callThrough();
- });
-
- describe(
- 'when the current time is unavailable from the player',
- function() {
- beforeEach(function() {
- state.videoPlayer.player.getCurrentTime = function() {
- return NaN;
- };
- state.videoPlayer.update();
- });
-
- it('does not trigger updatePlayTime event', function() {
- expect(state.videoPlayer.updatePlayTime)
- .not.toHaveBeenCalled();
- });
- });
-
- describe(
- 'when the current time is available from the player',
- function() {
- beforeEach(function() {
- state.videoPlayer.player.getCurrentTime = function() {
- return 60;
- };
- state.videoPlayer.update();
- });
-
- it('trigger updatePlayTime event', function() {
- expect(state.videoPlayer.updatePlayTime)
- .toHaveBeenCalledWith(60);
- });
- });
- });
-
- // Disabled 1/13/14 due to flakiness observed in master
- xdescribe('update with start & end time', function() {
- var START_TIME = 1,
- END_TIME = 2;
-
- beforeEach(function() {
- state = jasmine.initializePlayer(
- {
- start: START_TIME,
- end: END_TIME
- }
- );
-
- state.videoEl = $('video, iframe');
-
- spyOn(state.videoPlayer, 'update').and.callThrough();
- spyOn(state.videoPlayer, 'pause').and.callThrough();
- spyOn(state.videoProgressSlider, 'notifyThroughHandleEnd')
- .and.callThrough();
- });
-
- it(
- 'video is paused on first endTime, start & end time are reset',
- function(done) {
- var duration;
-
- state.videoProgressSlider.notifyThroughHandleEnd.calls.reset();
- state.videoPlayer.pause.calls.reset();
- state.videoPlayer.play();
-
- jasmine.waitUntil(function() {
- duration = Math.round(state.videoPlayer.currentTime);
- return state.videoPlayer.pause.calls.count() === 1;
- }).then(function() {
- expect(state.videoPlayer.startTime).toBe(0);
- expect(state.videoPlayer.endTime).toBe(null);
-
- expect(duration).toBe(END_TIME);
-
- expect(state.videoProgressSlider.notifyThroughHandleEnd)
- .toHaveBeenCalledWith({end: true});
- }).always(done);
- });
- });
-
- describe('updatePlayTime', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube();
- state.videoEl = $('video, iframe');
- spyOn(state.videoCaption, 'updatePlayTime').and.callThrough();
- spyOn(state.videoProgressSlider, 'updatePlayTime').and.callThrough();
- });
-
- it('update the video playback time', function(done) {
- var duration = 0;
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- if (duration > 0) {
- return true;
- }
-
- return false;
- }).then(function() {
- state.videoPlayer.goToStartTime = false;
- state.videoPlayer.updatePlayTime(60);
-
- expect($('.vidtime')).toHaveHtml('1:00 / 1:00');
- }).always(done);
- });
-
- it('update the playback time on caption', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.duration() > 0;
- }, 1000).then(function() {
- state.videoPlayer.goToStartTime = false;
- state.videoPlayer.updatePlayTime(60);
-
- expect(state.videoCaption.updatePlayTime)
- .toHaveBeenCalledWith(60);
- }).always(done);
- });
-
- it('update the playback time on progress slider', function(done) {
- var duration = 0;
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return duration > 0;
- }, 1000).then(function() {
- state.videoPlayer.goToStartTime = false;
- state.videoPlayer.updatePlayTime(60);
-
- expect(state.videoProgressSlider.updatePlayTime)
- .toHaveBeenCalledWith({
- time: 60,
- duration: duration
- });
- }).always(done);
- });
- });
-
- // Disabled 1/13/14 due to flakiness observed in master
- xdescribe(
- 'updatePlayTime when start & end times are defined',
- function() {
- var START_TIME = 1,
- END_TIME = 2;
-
- beforeEach(function() {
- state = jasmine.initializePlayer(
- {
- start: START_TIME,
- end: END_TIME
- }
- );
-
- state.videoEl = $('video, iframe');
-
- spyOn(state.videoPlayer, 'updatePlayTime').and.callThrough();
- spyOn(state.videoPlayer.player, 'seekTo').and.callThrough();
- spyOn(state.videoProgressSlider, 'updateStartEndTimeRegion')
- .and.callThrough();
- });
-
- it(
- 'when duration becomes available, updatePlayTime() is called',
- function(done) {
- var duration;
-
- expect(state.videoPlayer.initialSeekToStartTime).toBeTruthy();
- expect(state.videoPlayer.seekToStartTimeOldSpeed).toBe('void');
-
- state.videoPlayer.play();
-
- jasmine.waitUntil(function() {
- duration = state.videoPlayer.duration();
-
- return state.videoPlayer.isPlaying()
- && state.videoPlayer.initialSeekToStartTime === false;
- }).then(function() {
- expect(state.videoPlayer.startTime).toBe(START_TIME);
- expect(state.videoPlayer.endTime).toBe(END_TIME);
-
- expect(state.videoPlayer.player.seekTo)
- .toHaveBeenCalledWith(START_TIME);
-
- expect(state.videoProgressSlider.updateStartEndTimeRegion)
- .toHaveBeenCalledWith({duration: duration});
-
- expect(state.videoPlayer.seekToStartTimeOldSpeed)
- .toBe(state.speed);
- }).always(done);
- });
- });
-
- describe('updatePlayTime with invalid endTime', function() {
- beforeEach(function() {
- state = {
- el: $('#video_id'),
- videoPlayer: {
- duration: function() {
- // The video will be 60 seconds long.
- return 60;
- },
- goToStartTime: true,
- startTime: undefined,
- endTime: undefined,
- player: {
- seekTo: function() {}
- },
- figureOutStartEndTime: jasmine.createSpy(),
- figureOutStartingTime: jasmine.createSpy().and.returnValue(0)
- },
- config: {
- savedVideoPosition: 0,
- startTime: 0,
-
- // We are setting the end-time to 10000 seconds. The
- // video will be less than this, the code will reset
- // the end time to `null` - i.e. to the end of the video.
- // This is the expected behavior we will test for.
- endTime: 10000
- },
- currentPlayerMode: 'html5',
- trigger: function() {},
- browserIsFirefox: false,
- isFlashMode: jasmine.createSpy().and.returnValue(false)
- };
- });
- });
-
- describe('toggleFullScreen', function() {
- describe('when the video player is not full screen', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- jasmine.mockFullscreenAPI();
- state.videoEl = $('video, iframe');
- spyOn($.fn, 'trigger').and.callThrough();
- $('.add-fullscreen').click();
- });
-
- it('add the video-fullscreen class', function() {
- expect(state.el).toHaveClass('video-fullscreen');
- });
-
- it('tell VideoCaption to resize', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('fullscreen', [true]);
- expect(state.resizer.setMode).toHaveBeenCalledWith('both');
- expect(state.resizer.delta.substract).toHaveBeenCalled();
- });
- });
-
- describe('when the video player already full screen', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- jasmine.mockFullscreenAPI();
- state.videoEl = $('video, iframe');
- spyOn($.fn, 'trigger').and.callThrough();
- state.videoFullScreen.enter();
- $('.add-fullscreen').click();
- });
-
- it('remove the video-fullscreen class', function() {
- expect(state.el).not.toHaveClass('video-fullscreen');
- });
-
- it('tell VideoCaption to resize', function() {
- expect($.fn.trigger).toHaveBeenCalledWith('fullscreen', [false]);
- expect(state.resizer.setMode)
- .toHaveBeenCalledWith('width');
- expect(state.resizer.delta.reset).toHaveBeenCalled();
- });
- });
- });
-
- describe('duration', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- spyOn(state.videoPlayer.player, 'getDuration').and.callThrough();
- state.videoPlayer.duration();
- });
-
- it('delegate to the player', function() {
- expect(state.videoPlayer.player.getDuration).toHaveBeenCalled();
- });
- });
-
- describe('getDuration', function() {
- beforeEach(function() {
- // We need to make sure that metadata is returned via an AJAX
- // request. Without the jasmine.stubRequests() below we will
- // get the error:
- //
- // this.metadata[this.youtubeId(...)] is undefined
- jasmine.stubRequests();
-
- state = jasmine.initializePlayerYouTube();
-
- state.videoEl = $('video, iframe');
-
- spyOn(state, 'getDuration').and.callThrough();
-
- // When `state.videoPlayer.player.getDuration()` returns a `0`,
- // the fall-back function `state.getDuration()` will be called.
- state.videoPlayer.player.getDuration.and.returnValue(0);
- });
-
- it('getDuration is called as a fall-back', function() {
- state.videoPlayer.duration();
-
- expect(state.getDuration).toHaveBeenCalled();
- });
- });
-
- describe('volume', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- spyOn(state.videoPlayer.player, 'getVolume').and.callThrough();
- });
-
- it('set the player volume', function() {
- var expectedValue = 60,
- realValue;
-
- state.videoPlayer.player.setVolume(60);
- realValue = Math.round(state.videoPlayer.player.getVolume() * 100);
-
- expect(realValue).toEqual(expectedValue);
- });
- });
-
- describe('on Touch devices', function() {
- it('`is-touch` class name is added to container', function() {
- $.each(
- ['iPad', 'Android', 'iPhone'],
- function(index, device) {
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- expect(state.el).toHaveClass('is-touch');
- });
- });
-
- it('modules are not initialized on iPhone', function() {
- window.onTouchBasedDevice.and.returnValue(['iPhone']);
- state = jasmine.initializePlayer();
-
- state.videoEl = $('video, iframe');
-
- var modules = [
- state.videoControl, state.videoCaption, state.videoProgressSlider,
- state.videoSpeedControl, state.videoVolumeControl
- ];
-
- $.each(modules, function(index, module) {
- expect(module).toBeUndefined();
- });
- });
-
- $.each(['iPad', 'Android'], function(index, device) {
- var message = 'controls become visible after playing starts '
- + 'on ' + device;
-
- it(message, function(done) {
- var controls;
-
- window.onTouchBasedDevice.and.returnValue([device]);
-
- state = jasmine.initializePlayer();
- state.videoEl = $('video, iframe');
- controls = state.el.find('.video-controls');
-
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-initialized');
- }).then(function() {
- expect(controls).toHaveClass('is-hidden');
- state.videoPlayer.play();
- jasmine.waitUntil(function() {
- // Firefox does not return duration for videos until they have reached the end.
- // var duration = state.videoPlayer.duration();
- // return duration > 0 && state.videoPlayer.isPlaying();
- return state.videoPlayer.isPlaying();
- }).then(function() {
- expect(controls).not.toHaveClass('is-hidden');
- }).always(done);
- });
- });
- });
- });
-
- describe('onSpeedChange', function() {
- beforeEach(function() {
- state = {
- el: $(document),
- speed: '1.50',
- setSpeed: jasmine.createSpy(),
- saveState: jasmine.createSpy(),
- videoPlayer: {
- currentTime: 60,
- updatePlayTime: jasmine.createSpy(),
- setPlaybackRate: jasmine.createSpy(),
- player: jasmine.createSpyObj('player', ['setPlaybackRate'])
- },
- isFlashMode: jasmine.createSpy().and.returnValue(false)
- };
- });
-
- describe('always', function() {
- it('convert the current time to the new speed', function() {
- state.isFlashMode.and.returnValue(true);
- VideoPlayer.prototype.onSpeedChange.call(state, '0.75', false);
- expect(state.videoPlayer.currentTime).toBe('120.000');
- });
-
- it('set video speed to the new speed', function() {
- VideoPlayer.prototype.onSpeedChange.call(state, '0.75', false);
- expect(state.setSpeed).toHaveBeenCalledWith(0.75);
- expect(state.videoPlayer.setPlaybackRate)
- .toHaveBeenCalledWith(0.75);
- });
- });
- });
-
- describe('setPlaybackRate', function() {
- beforeEach(function() {
- state = {
- youtubeId: jasmine.createSpy().and.returnValue('videoId'),
- isFlashMode: jasmine.createSpy().and.returnValue(false),
- isHtml5Mode: jasmine.createSpy().and.returnValue(true),
- isYoutubeType: jasmine.createSpy().and.returnValue(true),
- setPlayerMode: jasmine.createSpy(),
- trigger: jasmine.createSpy(),
- videoPlayer: {
- currentTime: 60,
- isPlaying: jasmine.createSpy(),
- seekTo: jasmine.createSpy(),
- duration: jasmine.createSpy().and.returnValue(60),
- updatePlayTime: jasmine.createSpy(),
- setPlaybackRate: jasmine.createSpy(),
- player: jasmine.createSpyObj('player', [
- 'setPlaybackRate', 'loadVideoById', 'cueVideoById'
- ])
- }
- };
- });
-
- it('in Flash mode and video is playing', function() {
- state.isFlashMode.and.returnValue(true);
- state.isHtml5Mode.and.returnValue(false);
- state.videoPlayer.isPlaying.and.returnValue(true);
- VideoPlayer.prototype.setPlaybackRate.call(state, '0.75');
- expect(state.videoPlayer.player.setPlaybackRate)
- .toHaveBeenCalledWith('0.75');
- });
-
- it('in Flash mode and video not started', function() {
- state.isFlashMode.and.returnValue(true);
- state.isHtml5Mode.and.returnValue(false);
- state.videoPlayer.isPlaying.and.returnValue(false);
- VideoPlayer.prototype.setPlaybackRate.call(state, '0.75');
- expect(state.videoPlayer.player.setPlaybackRate).toHaveBeenCalledWith('0.75');
- });
-
- it('in HTML5 mode', function() {
- state.isYoutubeType.and.returnValue(false);
- VideoPlayer.prototype.setPlaybackRate.call(state, '0.75');
- expect(state.videoPlayer.player.setPlaybackRate).toHaveBeenCalledWith('0.75');
- });
-
- it('Youtube video in FF, with new speed equal 1.0', function() {
- state.browserIsFirefox = true;
-
- state.videoPlayer.isPlaying.and.returnValue(false);
- VideoPlayer.prototype.setPlaybackRate.call(state, '1.0');
- expect(state.videoPlayer.player.setPlaybackRate).toHaveBeenCalledWith('1.0');
- });
- });
-
- describe('HLS Video', function() {
- beforeEach(function() {
- state = jasmine.initializeHLSPlayer();
- });
-
- it('does not show error message if hls is supported', function() {
- expect($('.video-hls-error')).toHaveClass('is-hidden');
- });
-
- it('can extract hls video sources correctly', function() {
- expect(state.HLSVideoSources).toEqual(['/base/fixtures/hls/hls.m3u8']);
- expect(state.videoPlayer.player.hls).toBeDefined();
- });
-
- describe('on safari', function() {
- beforeEach(function() {
- spyOn(HLS, 'isSupported').and.returnValue(false);
- state = jasmine.initializeHLSPlayer();
- state.canPlayHLS = true;
- state.browserIsSafari = true;
- });
-
- it('can use native hls playback support', function() {
- expect(state.videoPlayer.player.hls).toBeUndefined();
- });
- });
- });
-
- describe('HLS Video Errors', function() {
- beforeEach(function() {
- spyOn(HLS, 'isSupported').and.returnValue(false);
- state = jasmine.initializeHLSPlayer({sources: ['/base/fixtures/hls/hls.m3u8']});
- });
-
- it('shows error message if hls is not supported', function() {
- expect($('.video-hls-error')).not.toHaveClass('is-hidden');
- expect($('.video-hls-error').text().trim()).toEqual(
- 'Your browser does not support this video format. Try using a different browser.'
- );
- });
- });
-
- describe('Video duration', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- spyOn(state.videoPlayer, 'duration').and.returnValue(61);
- });
-
- it('overrides the duration if not set', function(done) {
- jasmine.waitUntil(function() {
- return state.duration !== undefined;
- }).then(function() {
- expect(state.duration).toEqual(61);
- }).always(done);
- });
- });
-
- describe('Overlay Play Button', function() {
- var playButtonOverlaySelector = '.video-wrapper .btn-play.fa.fa-youtube-play.fa-2x';
- beforeEach(function() {
- state = jasmine.initializePlayer();
- });
-
- it('shows the play button after player is ready', function(done) {
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() !== STATUS.UNSTARTED;
- }).then(function() {
- expect($(playButtonOverlaySelector)).not.toHaveClass('is-hidden');
- }).always(done);
- });
-
- it('hides the play button on play', function(done) {
- $(state.videoPlayer.player.videoEl).trigger('click'); // play
- jasmine.waitUntil(function() {
- return state.videoPlayer.player.getPlayerState() === STATUS.PLAYING;
- }).then(function() {
- expect($(playButtonOverlaySelector)).toHaveClass('is-hidden');
- }).always(done);
- });
-
- it('plays the video when overlay button is clicked', function() {
- $('.video-wrapper .btn-play').trigger('click'); // play
- expect(state.videoPlayer.player.getPlayerState()).toEqual(STATUS.PLAYING);
- expect($(playButtonOverlaySelector)).toHaveClass('is-hidden');
- });
-
- it('shows the play button on pause', function(done) {
- $(state.videoPlayer.player.videoEl).trigger('click'); // play
- expect(state.videoPlayer.player.getPlayerState()).toEqual(STATUS.PLAYING);
- $(state.videoPlayer.player.videoEl).trigger('click'); // pause
- expect(state.videoPlayer.player.getPlayerState()).toEqual(STATUS.PAUSED);
- jasmine.waitUntil(function() {
- return $(playButtonOverlaySelector).attr('class').split(' ')
- .indexOf('is-hidden') === -1;
- }).then(function() {
- expect($(playButtonOverlaySelector)).not.toHaveClass('is-hidden');
- }).always(done);
- });
- });
-
- describe('HLS Primary Playback', function() {
- beforeEach(function() {
- spyOn(window.YT, 'Player').and.callThrough();
- });
-
- afterEach(function() {
- YT.Player.calls.reset();
- });
-
- it('loads youtube if flag is disabled', function() {
- state = jasmine.initializePlayer('video_all.html', {
- prioritizeHls: false,
- streams: '0.5:7tqY6eQzVhE,1.0:cogebirgzzM,1.5:abcdefghijkl'
- });
- expect(state.config.prioritizeHls).toBeFalsy();
- expect(YT.Player).toHaveBeenCalled();
- expect(state.videoPlayer.player.hls).toBeUndefined();
- });
-
- it('does not load youtube if flag is enabled', function() {
- state = jasmine.initializePlayer('video_all.html', {
- prioritizeHls: true,
- streams: '0.5:7tqY6eQzVhE,1.0:cogebirgzzM,1.5:abcdefghijkl',
- sources: ['/base/fixtures/test.mp4', '/base/fixtures/test.webm', '/base/fixtures/hls/hls.m3u8']
- });
- expect(state.config.prioritizeHls).toBeTruthy();
- expect(YT.Player).not.toHaveBeenCalled();
- expect(state.videoPlayer.player.hls).toBeDefined();
- });
- });
- });
- });
-}(require, define));
diff --git a/xmodule/js/spec/video/video_poster_spec.js b/xmodule/js/spec/video/video_poster_spec.js
deleted file mode 100644
index c451ebcf1d63..000000000000
--- a/xmodule/js/spec/video/video_poster_spec.js
+++ /dev/null
@@ -1,43 +0,0 @@
-(function(WAIT_TIMEOUT) {
- 'use strict';
-
- describe('VideoPoster', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- state = jasmine.initializePlayer('video_with_bumper.html');
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- if (state.bumperState && state.bumperState.videoPlayer) {
- state.bumperState.videoPlayer.destroy();
- }
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- window.onTouchBasedDevice = oldOTBD;
- });
-
- it('can render the poster', function() {
- expect($('.poster')).toExist();
- expect($('.btn-play')).toExist();
- });
-
- it('can start playing the video on click', function(done) {
- $('.btn-play').click();
- jasmine.waitUntil(function() {
- return state.el.hasClass('is-playing');
- }).done(done);
- });
-
- it('destroy itself on "play" event', function() {
- $('.btn-play').click();
- expect($('.poster')).not.toExist();
- });
- });
-}).call(this, window.WAIT_TIMEOUT);
diff --git a/xmodule/js/spec/video/video_progress_slider_spec.js b/xmodule/js/spec/video/video_progress_slider_spec.js
deleted file mode 100644
index 5f91fc6e4216..000000000000
--- a/xmodule/js/spec/video/video_progress_slider_spec.js
+++ /dev/null
@@ -1,326 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('VideoProgressSlider', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
- .and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- describe('constructor', function() {
- describe('on a non-touch based device', function() {
- beforeEach(function() {
- spyOn($.fn, 'slider').and.callThrough();
-
- state = jasmine.initializePlayer();
- });
-
- it('build the slider', function() {
- expect($('.slider').toArray()).toContain(state.videoProgressSlider.slider);
- expect($.fn.slider).toHaveBeenCalledWith({
- range: 'min',
- min: 0,
- max: null,
- slide: state.videoProgressSlider.onSlide,
- stop: state.videoProgressSlider.onStop,
- step: 5
- });
- });
-
- it('build the seek handle', function() {
- expect($('.ui-slider-handle').toArray())
- .toContain(state.videoProgressSlider.handle);
- });
-
- it('add ARIA attributes to time control', function() {
- var $timeControl = $('div.slider > .progress-handle');
-
- expect($timeControl).toHaveAttrs({
- role: 'slider',
- 'aria-label': 'Video position. Press space to toggle playback',
- 'aria-disabled': 'false'
- });
-
- expect($timeControl).toHaveAttr('aria-valuetext');
- });
- });
-
- describe('on a touch-based device', function() {
- it('does not build the slider on iPhone', function() {
- window.onTouchBasedDevice.and.returnValue(['iPhone']);
-
- state = jasmine.initializePlayer();
-
- expect(state.videoProgressSlider).toBeUndefined();
-
- // We can't expect $.fn.slider not to have been called,
- // because sliders are used in other parts of Video.
- });
- $.each(['iPad', 'Android'], function(index, device) {
- it('build the slider on ' + device, function() {
- window.onTouchBasedDevice.and.returnValue([device]);
-
- state = jasmine.initializePlayer();
-
- expect(state.videoProgressSlider.slider).toBeDefined();
- });
- });
- });
- });
-
- describe('play', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- });
-
- describe('when the slider was already built', function() {
- var spy;
-
- beforeEach(function() {
- spy = spyOn(state.videoProgressSlider, 'buildSlider');
- spy.and.callThrough();
- state.videoPlayer.play();
- });
-
- it('does not build the slider', function() {
- expect(spy.calls.count()).toEqual(0);
- });
- });
-
- // Currently, the slider is not rebuilt if it does not exist.
- });
-
- describe('updatePlayTime', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- });
-
- describe('when frozen', function() {
- beforeEach(function() {
- spyOn($.fn, 'slider').and.callThrough();
- state.videoProgressSlider.frozen = true;
- state.videoProgressSlider.updatePlayTime(20, 120);
- });
-
- it('does not update the slider', function() {
- expect($.fn.slider).not.toHaveBeenCalled();
- });
- });
-
- describe('when not frozen', function() {
- beforeEach(function() {
- spyOn($.fn, 'slider').and.callThrough();
- state.videoProgressSlider.frozen = false;
- state.videoProgressSlider.updatePlayTime({
- time: 20,
- duration: 120
- });
- });
-
- it('update the max value of the slider', function() {
- expect($.fn.slider).toHaveBeenCalledWith(
- 'option', 'max', 120
- );
- });
-
- it('update current value of the slider', function() {
- expect($.fn.slider).toHaveBeenCalledWith(
- 'option', 'value', 20
- );
- });
-
- it('required aria values updated', function() {
- expect(state.videoProgressSlider.handle.attr('aria-valuenow')).toBe('20');
- expect(state.videoProgressSlider.handle.attr('aria-valuemax')).toBe('120');
- });
- });
- });
-
- describe('onSlide', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- spyOn($.fn, 'slider').and.callThrough();
- spyOn(state.videoPlayer, 'onSlideSeek').and.callThrough();
- });
-
- // Disabled 12/30/13 due to flakiness in master
- xit('freeze the slider', function() {
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 20}
- );
-
- expect(state.videoProgressSlider.frozen).toBeTruthy();
- });
-
- // Disabled 12/30/13 due to flakiness in master
- xit('trigger seek event', function() {
- state.videoProgressSlider.onSlide(
- jQuery.Event('slide'), {value: 20}
- );
-
- expect(state.videoPlayer.onSlideSeek).toHaveBeenCalled();
- });
- });
-
- describe('onStop', function() {
- beforeEach(function() {
- jasmine.clock().install();
-
- state = jasmine.initializePlayer();
-
- spyOn(state.videoPlayer, 'onSlideSeek').and.callThrough();
- });
-
- afterEach(function() {
- jasmine.clock().uninstall();
- });
-
- // Disabled 12/30/13 due to flakiness in master
- xit('freeze the slider', function() {
- state.videoProgressSlider.onStop(
- jQuery.Event('stop'), {value: 20}
- );
-
- expect(state.videoProgressSlider.frozen).toBeTruthy();
- });
-
- // Disabled 12/30/13 due to flakiness in master
- xit('trigger seek event', function() {
- state.videoProgressSlider.onStop(
- jQuery.Event('stop'), {value: 20}
- );
-
- expect(state.videoPlayer.onSlideSeek).toHaveBeenCalled();
- });
-
- // Disabled 12/30/13 due to flakiness in master
- xit('set timeout to unfreeze the slider', function() {
- state.videoProgressSlider.onStop(
- jQuery.Event('stop'), {value: 20}
- );
-
- jasmine.clock().tick(200);
-
- expect(state.videoProgressSlider.frozen).toBeFalsy();
- });
- });
-
- it('getRangeParams', function() {
- var testCases = [
- {
- startTime: 10,
- endTime: 20,
- duration: 150
- },
- {
- startTime: 90,
- endTime: 100,
- duration: 100
- },
- {
- startTime: 0,
- endTime: 200,
- duration: 200
- }
- ];
-
- state = jasmine.initializePlayer();
-
- $.each(testCases, function(index, testCase) {
- var step = 100 / testCase.duration,
- left = testCase.startTime * step,
- width = testCase.endTime * step - left,
- expectedParams = {
- left: left + '%',
- width: width + '%'
- },
- params = state.videoProgressSlider.getRangeParams(
- testCase.startTime, testCase.endTime, testCase.duration
- );
-
- expect(params).toEqual(expectedParams);
- });
- });
-
- describe('notifyThroughHandleEnd', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
-
- spyOnEvent(state.videoProgressSlider.handle, 'focus');
- spyOn(state.videoProgressSlider, 'notifyThroughHandleEnd')
- .and.callThrough();
- });
-
- it('params.end = true', function() {
- state.videoProgressSlider.notifyThroughHandleEnd({end: true});
-
- expect(state.videoProgressSlider.handle.attr('title'))
- .toBe('Video ended');
-
- expect('focus').toHaveBeenTriggeredOn(
- state.videoProgressSlider.handle
- );
- });
-
- it('params.end = false', function() {
- state.videoProgressSlider.notifyThroughHandleEnd({end: false});
-
- expect(state.videoProgressSlider.handle.attr('title'))
- .toBe('Video position');
-
- expect('focus').not.toHaveBeenTriggeredOn(
- state.videoProgressSlider.handle
- );
- });
-
- it('is called when video plays', function(done) {
- state.videoPlayer.play();
- jasmine.waitUntil(function() {
- return state.videoPlayer.isPlaying();
- }).done(function() {
- expect(state.videoProgressSlider.notifyThroughHandleEnd).toHaveBeenCalledWith({end: false});
- }).always(done);
- });
- });
-
- it('getTimeDescription', function() {
- var cases = {
- 0: '0 seconds',
- 1: '1 second',
- 10: '10 seconds',
-
- 60: '1 minute 0 seconds',
- 121: '2 minutes 1 second',
-
- 3670: '1 hour 1 minute 10 seconds',
- 21541: '5 hours 59 minutes 1 second'
- },
- getTimeDescription;
-
- state = jasmine.initializePlayer();
-
- getTimeDescription = state.videoProgressSlider.getTimeDescription;
-
- $.each(cases, function(input, output) {
- expect(getTimeDescription(input)).toBe(output);
- });
- });
-
- it('can destroy itself', function() {
- state = jasmine.initializePlayer();
- state.videoProgressSlider.destroy();
- expect(state.videoProgressSlider).toBeUndefined();
- expect($('.slider')).toBeEmpty();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_quality_control_spec.js b/xmodule/js/spec/video/video_quality_control_spec.js
deleted file mode 100644
index 70a75dd972ed..000000000000
--- a/xmodule/js/spec/video/video_quality_control_spec.js
+++ /dev/null
@@ -1,123 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- describe('VideoQualityControl', function() {
- var state, qualityControl, videoPlayer, player;
-
- afterEach(function() {
- $('source').remove();
- if (state.storage) {
- state.storage.clear();
- }
- state.videoPlayer.destroy();
- });
-
- describe('constructor, YouTube mode', function() {
- beforeEach(function() {
- state = jasmine.initializePlayerYouTube();
- qualityControl = state.videoQualityControl;
- videoPlayer = state.videoPlayer;
- player = videoPlayer.player;
-
- // Define empty methods in YouTube stub
- player.quality = 'large';
- player.setPlaybackQuality.and.callFake(function(quality) {
- player.quality = quality;
- });
- });
-
- it('contains the quality control and is initially hidden',
- function() {
- expect(qualityControl.el).toHaveClass(
- 'quality-control is-hidden'
- );
- });
-
- it('add ARIA attributes to quality control', function() {
- expect(qualityControl.el).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('bind the quality control', function() {
- expect(qualityControl.el).toHandleWith('click',
- qualityControl.toggleQuality
- );
-
- expect(state.el).toHandle('play');
- });
-
- it('calls fetchAvailableQualities only once', function() {
- expect(player.getAvailableQualityLevels.calls.count())
- .toEqual(0);
-
- videoPlayer.onPlay();
- videoPlayer.onPlay();
-
- expect(player.getAvailableQualityLevels.calls.count())
- .toEqual(1);
- });
-
- it('initializes with a quality equal to large', function() {
- videoPlayer.onPlay();
-
- expect(player.setPlaybackQuality).toHaveBeenCalledWith('large');
- });
-
- it('shows the quality control on play if HD is available',
- function() {
- videoPlayer.onPlay();
-
- expect(qualityControl.el).not.toHaveClass('is-hidden');
- });
-
- it('leaves quality control hidden on play if HD is not available',
- function() {
- player.getAvailableQualityLevels.and.returnValue(
- ['large', 'medium', 'small']
- );
-
- videoPlayer.onPlay();
- expect(qualityControl.el).toHaveClass('is-hidden');
- });
-
- it('switch to HD if it is available', function() {
- videoPlayer.onPlay();
-
- qualityControl.quality = 'large';
- qualityControl.el.click();
- expect(player.setPlaybackQuality)
- .toHaveBeenCalledWith('highres');
-
- qualityControl.quality = 'highres';
- qualityControl.el.click();
- expect(player.setPlaybackQuality).toHaveBeenCalledWith('large');
- });
-
- it('quality control is active if HD is available',
- function() {
- player.getAvailableQualityLevels.and.returnValue(
- ['highres', 'hd1080', 'hd720']
- );
-
- qualityControl.quality = 'highres';
-
- videoPlayer.onPlay();
- expect(qualityControl.el).toHaveClass('active');
- });
-
- it('can destroy itself', function() {
- state.videoQualityControl.destroy();
- expect(state.videoQualityControl).toBeUndefined();
- expect($('.quality-control')).not.toExist();
- });
- });
-
- describe('constructor, HTML5 mode', function() {
- it('does not contain the quality control', function() {
- state = jasmine.initializePlayer();
-
- expect(state.el.find('.quality-control').length).toBe(0);
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_save_state_plugin_spec.js b/xmodule/js/spec/video/video_save_state_plugin_spec.js
deleted file mode 100644
index 55c07bb06797..000000000000
--- a/xmodule/js/spec/video/video_save_state_plugin_spec.js
+++ /dev/null
@@ -1,278 +0,0 @@
-import * as Time from 'time.js';
-
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- 'use strict';
-
- describe('VideoPlayer Save State plugin', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice')
- .and.returnValue(null);
-
- state = jasmine.initializePlayer({
- recordedYoutubeIsAvailable: true
- });
- spyOn(state.storage, 'setItem');
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- });
-
- describe('saveState function', function() {
- var videoPlayerCurrentTime, newCurrentTime, speed;
-
- // We make sure that `currentTime` is a float. We need to test
- // that Math.round() is called.
- videoPlayerCurrentTime = 3.1242;
-
- // We have two times, because one is stored in
- // `videoPlayer.currentTime`, and the other is passed directly to
- // `saveState` in `data` object. In each case, there is different
- // code that handles these times. They have to be different for
- // test completeness sake. Also, make sure it is float, as is the
- // time above.
- newCurrentTime = 5.4;
- speed = '0.75';
-
- beforeEach(function() {
- state.videoPlayer.currentTime = videoPlayerCurrentTime;
- });
-
- it('data is not an object, async is true', function() {
- itSpec({
- asyncVal: true,
- speedVal: undefined,
- positionVal: videoPlayerCurrentTime,
- data: undefined,
- ajaxData: {
- saved_video_position: Time.formatFull(Math.round(videoPlayerCurrentTime))
- }
- });
- });
-
- it('data contains speed, async is false', function() {
- itSpec({
- asyncVal: false,
- speedVal: speed,
- positionVal: undefined,
- data: {
- speed: speed
- },
- ajaxData: {
- speed: speed
- }
- });
- });
-
- it('data contains float position, async is true', function() {
- itSpec({
- asyncVal: true,
- speedVal: undefined,
- positionVal: newCurrentTime,
- data: {
- saved_video_position: newCurrentTime
- },
- ajaxData: {
- saved_video_position: Time.formatFull(Math.round(newCurrentTime))
- }
- });
- });
-
- it('data contains speed and rounded position, async is false', function() {
- itSpec({
- asyncVal: false,
- speedVal: speed,
- positionVal: Math.round(newCurrentTime),
- data: {
- speed: speed,
- saved_video_position: Math.round(newCurrentTime)
- },
- ajaxData: {
- speed: speed,
- saved_video_position: Time.formatFull(Math.round(newCurrentTime))
- }
- });
- });
-
- it('data contains empty object, async is true', function() {
- itSpec({
- asyncVal: true,
- speedVal: undefined,
- positionVal: undefined,
- data: {},
- ajaxData: {}
- });
- });
-
- it('data contains position 0, async is true', function() {
- itSpec({
- asyncVal: true,
- speedVal: undefined,
- positionVal: 0,
- data: {
- saved_video_position: 0
- },
- ajaxData: {
- saved_video_position: Time.formatFull(Math.round(0))
- }
- });
- });
-
- function itSpec(value) {
- state.config.saveStateEnabled = true;
- var asyncVal = value.asyncVal,
- speedVal = value.speedVal,
- positionVal = value.positionVal,
- data = value.data,
- ajaxData = value.ajaxData;
-
- state.videoSaveStatePlugin.saveState(asyncVal, data);
-
- if (speedVal) {
- expect(state.storage.setItem).toHaveBeenCalledWith(
- 'speed',
- speedVal,
- true
- );
- }
- if (positionVal) {
- expect(state.storage.setItem).toHaveBeenCalledWith(
- 'savedVideoPosition',
- positionVal,
- true
- );
- expect(ajaxData.saved_video_position).toBe(Time.formatFull(positionVal));
- }
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: asyncVal,
- dataType: 'json',
- data: ajaxData
- });
- }
- });
-
- it('can save state on speed change', function() {
- state.el.trigger('speedchange', ['2.0']);
- expect($.ajax).not.toHaveBeenCalledWith({
- url: state.config.saveStateUrl
- });
- state.config.saveStateEnabled = true;
- state.el.trigger('speedchange', ['2.0']);
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: true,
- dataType: 'json',
- data: {speed: '2.0'}
- });
- });
-
- it('can save state on page unload', function() {
- $.ajax.calls.reset();
- state.videoSaveStatePlugin.onUnload();
- expect($.ajax).not.toHaveBeenCalledWith({
- url: state.config.saveStateUrl
- });
- state.config.saveStateEnabled = true;
- $.ajax.calls.reset();
- state.videoSaveStatePlugin.onUnload();
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: false,
- dataType: 'json',
- data: {saved_video_position: '00:00:00'}
- });
- });
-
- it('can save state on pause', function() {
- state.el.trigger('pause');
- expect($.ajax).not.toHaveBeenCalledWith({
- url: state.config.saveStateUrl
- });
- state.config.saveStateEnabled = true;
- state.el.trigger('pause');
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: true,
- dataType: 'json',
- data: {saved_video_position: '00:00:00'}
- });
- });
-
- it('can save state on language change', function() {
- state.el.trigger('language_menu:change', ['ua']);
- expect(state.storage.setItem).toHaveBeenCalledWith('language', 'ua');
- });
-
- it('can save youtube availability', function() {
- $.ajax.calls.reset();
-
- // Test the cases where we shouldn't send anything at all -- client
- // side code determines that YouTube availability is the same as
- // what's already been recorded on the server side.
- state.config.recordedYoutubeIsAvailable = true;
- state.el.trigger('youtube_availability', [true]);
- state.config.recordedYoutubeIsAvailable = false;
- state.el.trigger('youtube_availability', [false]);
- expect($.ajax).not.toHaveBeenCalled();
-
- // Test that we can go from unavailable -> available
- state.config.saveStateEnabled = false;
- state.config.recordedYoutubeIsAvailable = false;
- state.el.trigger('youtube_availability', [true]);
- expect($.ajax).not.toHaveBeenCalled();
- state.config.saveStateEnabled = true;
- state.config.recordedYoutubeIsAvailable = false;
- state.el.trigger('youtube_availability', [true]);
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: true,
- dataType: 'json',
- data: {youtube_is_available: true}
- });
-
- // Test that we can go from available -> unavailable
- state.config.recordedYoutubeIsAvailable = true;
- state.el.trigger('youtube_availability', [false]);
- expect($.ajax).toHaveBeenCalledWith({
- url: state.config.saveStateUrl,
- type: 'POST',
- async: true,
- dataType: 'json',
- data: {youtube_is_available: false}
- });
- });
-
- it('can destroy itself', function() {
- var plugin = state.videoSaveStatePlugin;
- spyOn($.fn, 'off').and.callThrough();
- state.videoSaveStatePlugin.destroy();
- expect(state.videoSaveStatePlugin).toBeUndefined();
- expect($.fn.off).toHaveBeenCalledWith({
- speedchange: plugin.onSpeedChange,
- autoadvancechange: plugin.onAutoAdvanceChange,
- play: plugin.bindUnloadHandler,
- 'pause destroy': plugin.saveStateHandler,
- 'language_menu:change': plugin.onLanguageChange,
- youtube_availability: plugin.onYoutubeAvailability
- });
- expect($.fn.off).toHaveBeenCalledWith('destroy', plugin.destroy);
- expect($.fn.off).toHaveBeenCalledWith('unload', plugin.onUnload);
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_skip_control_spec.js b/xmodule/js/spec/video/video_skip_control_spec.js
deleted file mode 100644
index 205ba9e0a1da..000000000000
--- a/xmodule/js/spec/video/video_skip_control_spec.js
+++ /dev/null
@@ -1,47 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoSkipControl', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine
- .createSpy('onTouchBasedDevice').and.returnValue(null);
- state = jasmine.initializePlayer('video_with_bumper.html');
- $('.poster .btn-play').click();
- spyOn(state.bumperState.videoCommands, 'execute').and.callThrough();
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- if (state.bumperState && state.bumperState.videoPlayer) {
- state.bumperState.videoPlayer.destroy();
- }
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- window.onTouchBasedDevice = oldOTBD;
- });
-
- it('can render the control when video starts playing', function() {
- expect($('.skip-control')).not.toExist();
- state.el.trigger('play');
- expect($('.skip-control')).toExist();
- });
-
- it('can skip the video on click', function() {
- spyOn(state.bumperState.videoBumper, 'skipAndDoNotShowAgain');
- state.el.trigger('play');
- $('.skip-control').click();
- expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('skip', true);
- expect(state.bumperState.videoBumper.skipAndDoNotShowAgain).toHaveBeenCalled();
- });
-
- it('can destroy itself', function() {
- state.bumperState.videoPlaySkipControl.destroy();
- expect(state.bumperState.videoPlaySkipControl).toBeUndefined();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_speed_control_spec.js b/xmodule/js/spec/video/video_speed_control_spec.js
deleted file mode 100644
index 279ecc19aeec..000000000000
--- a/xmodule/js/spec/video/video_speed_control_spec.js
+++ /dev/null
@@ -1,231 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(undefined) {
- 'use strict';
-
- describe('VideoSpeedControl', function() {
- var state, oldOTBD;
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
- .and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- describe('constructor', function() {
- describe('always', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- });
-
- it('add the video speed control to player', function() {
- var $secondaryControls = $('.secondary-controls'),
- li = $secondaryControls.find('.video-speeds li');
-
- expect($secondaryControls).toContainElement('.speeds');
- expect($secondaryControls).toContainElement('.video-speeds');
- expect($secondaryControls.find('.value').text())
- .toBe('1.50x');
- expect(li.filter('.is-active')).toHaveData(
- 'speed', state.videoSpeedControl.currentSpeed
- );
- expect(li.length).toBe(state.speeds.length);
-
- $.each(li.toArray().reverse(), function(index, link) {
- expect($(link).attr('data-speed')).toEqual(state.speeds[index]);
- expect($(link).find('.speed-option').text()).toBe(
- state.speeds[index] + 'x'
- );
- });
- });
- });
-
- describe('when running on touch based device', function() {
- $.each(['iPad', 'Android'], function(index, device) {
- it('is not rendered on' + device, function() {
- window.onTouchBasedDevice.and.returnValue([device]);
- state = jasmine.initializePlayer();
-
- expect(state.el.find('.speeds')).not.toExist();
- });
- });
- });
-
- describe('when running on non-touch based device', function() {
- var $speedControl, speedEntries, $speedButton, $speedsContainer,
- KEY = $.ui.keyCode,
-
- keyPressEvent = function(key) {
- return $.Event('keydown', {keyCode: key});
- };
-
- beforeEach(function() {
- state = jasmine.initializePlayer();
- $speedControl = $('.speeds');
- $speedButton = $('.speed-button');
- $speedsContainer = $('.video-speeds');
- speedEntries = $speedsContainer.find('.speed-option');
- });
-
- it('open/close the speed menu on mouseenter/mouseleave',
- function() {
- $speedControl.mouseenter();
- expect($speedControl).toHaveClass('is-opened');
- $speedControl.mouseleave();
- expect($speedControl).not.toHaveClass('is-opened');
- });
-
- it('do not close the speed menu on mouseleave if a speed '
- + 'entry has focus', function() {
- // Open speed meenu. Focus is on last speed entry.
- $speedControl.trigger(keyPressEvent(KEY.ENTER));
- $speedControl.mouseenter().mouseleave();
- expect($speedControl).toHaveClass('is-opened');
- });
-
- it('close the speed menu on outside click', function() {
- $speedControl.trigger(keyPressEvent(KEY.ENTER));
- $(window).click();
- expect($speedControl).not.toHaveClass('is-opened');
- });
-
- it('open the speed menu on ENTER keydown', function() {
- $speedControl.trigger(keyPressEvent(KEY.ENTER));
- expect($speedControl).toHaveClass('is-opened');
- expect(speedEntries.last()).toBeFocused();
- });
-
- it('open the speed menu on SPACE keydown', function() {
- $speedControl.trigger(keyPressEvent(KEY.SPACE));
- expect($speedControl).toHaveClass('is-opened');
- expect(speedEntries.last()).toBeFocused();
- });
-
- it('open the speed menu on UP keydown', function() {
- $speedControl.trigger(keyPressEvent(KEY.UP));
- expect($speedControl).toHaveClass('is-opened');
- expect(speedEntries.last()).toBeFocused();
- });
-
- it('close the speed menu on ESCAPE keydown', function() {
- $speedControl.trigger(keyPressEvent(KEY.ESCAPE));
- expect($speedControl).not.toHaveClass('is-opened');
- });
-
- it('UP and DOWN keydown function as expected on speed entries',
- function() {
- var speed_0_75 = speedEntries.filter(':contains("0.75x")'),
- speed_1_0 = speedEntries.filter(':contains("1.0x")');
-
- // First open menu
- $speedControl.trigger(keyPressEvent(KEY.UP));
- expect(speed_0_75).toBeFocused();
-
- speed_0_75.trigger(keyPressEvent(KEY.UP));
- expect(speed_1_0).toBeFocused();
-
- speed_1_0.trigger(keyPressEvent(KEY.DOWN));
- expect(speed_0_75).toBeFocused();
- });
-
- it('ESC keydown on speed entry closes menu', function() {
- // First open menu. Focus is on last speed entry.
- $speedControl.trigger(keyPressEvent(KEY.UP));
- speedEntries.last().trigger(keyPressEvent(KEY.ESCAPE));
-
- // Menu is closed and focus has been returned to speed
- // control.
- expect($speedControl).not.toHaveClass('is-opened');
- expect($speedButton).toBeFocused();
- });
-
- it('ENTER keydown on speed entry selects 2.0x speed and closes menu',
- function() {
- // First open menu.
- $speedControl.trigger(keyPressEvent(KEY.UP));
- // Focus on 2.0x speed
- speedEntries.eq(0).focus();
- speedEntries.eq(0).trigger(keyPressEvent(KEY.ENTER));
-
- // Menu is closed, focus has been returned to speed
- // control and video speed is 2.0x.
- expect($speedButton).toBeFocused();
- expect($('.video-speeds li[data-speed="2.0"]'))
- .toHaveClass('is-active');
- expect($('.speeds .value')).toHaveHtml('2.0x');
- });
-
- it('SPACE keydown on speed entry selects 0.75x speed and closes menu',
- function() {
- // First open menu.
- $speedControl.trigger(keyPressEvent(KEY.UP));
- // Focus on 0.75x speed
- speedEntries.eq(4).focus();
- speedEntries.eq(4).trigger(keyPressEvent(KEY.SPACE));
-
- // Menu is closed, focus has been returned to speed
- // control and video speed is 0.75x.
- expect($speedButton).toBeFocused();
- expect($('.video-speeds li[data-speed="0.75"]'))
- .toHaveClass('is-active');
- expect($('.speeds .value')).toHaveHtml('0.75x');
- });
- });
- });
-
- describe('changeVideoSpeed', function() {
- // This is an unnecessary test. The internal browser API, and
- // YouTube API detect (and do not do anything) if there is a
- // request for a speed that is already set.
- //
- // describe("when new speed is the same") ...
-
- describe('when new speed is not the same', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- state.videoSpeedControl.setSpeed(1.0);
- });
-
- it('trigger speedChange event', function() {
- spyOnEvent(state.el, 'speedchange');
-
- $('li[data-speed="0.75"] .speed-option').click();
- expect('speedchange').toHaveBeenTriggeredOn(state.el);
- expect(state.videoSpeedControl.currentSpeed).toEqual('0.75');
- });
- });
- });
-
- describe('onSpeedChange', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- $('li[data-speed="1.0"]').addClass('is-active').attr('aria-pressed', 'true');
- state.videoSpeedControl.setSpeed(0.75);
- });
-
- it('set the new speed as active', function() {
- expect($('li[data-speed="1.0"]')).not.toHaveClass('is-active');
- expect($('li[data-speed="1.0"] .speed-option').attr('aria-pressed')).not.toEqual('true');
-
- expect($('li[data-speed="0.75"]')).toHaveClass('is-active');
- expect($('li[data-speed="0.75"] .speed-option').attr('aria-pressed')).toEqual('true');
-
- expect($('.speeds .speed-button .value')).toHaveHtml('0.75x');
- });
- });
-
- it('can destroy itself', function() {
- state = jasmine.initializePlayer();
- state.videoSpeedControl.destroy();
- expect(state.videoSpeedControl).toBeUndefined();
- expect($('.video-speeds')).not.toExist();
- expect($('.speed-button')).not.toExist();
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_storage_spec.js b/xmodule/js/spec/video/video_storage_spec.js
deleted file mode 100644
index 4d8ecaa57a26..000000000000
--- a/xmodule/js/spec/video/video_storage_spec.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// eslint-disable-next-line no-shadow-restricted-names
-(function(require, define, undefined) {
- require(
- ['video/00_video_storage.js'],
- function(VideoStorage) {
- describe('VideoStorage', function() {
- var namespace = 'test_storage',
- id = 'video_id';
-
- afterEach(function() {
- VideoStorage(namespace, id).clear();
- });
-
- describe('initialize', function() {
- it('with namespace and id', function() {
- var storage = VideoStorage(namespace, id);
-
- expect(window[namespace]).toBeDefined();
- expect(window[namespace][id]).toBeDefined();
- });
-
- it('without namespace and id', function() {
- spyOn(Number.prototype, 'toString').and.returnValue('0.abcdedg');
- var storage = VideoStorage();
-
- expect(window.VideoStorage).toBeDefined();
- expect(window.VideoStorage.abcdedg).toBeDefined();
- });
- });
-
- describe('methods: ', function() {
- var data, storage;
-
- beforeEach(function() {
- data = {
- item_2: 'value_2'
- };
- data[id] = {
- item_1: 'value_1'
- };
-
- window[namespace] = data;
- storage = VideoStorage(namespace, id);
- });
-
- it('setItem', function() {
- var expected = $.extend(true, {}, data, {item_4: 'value_4'});
-
- expected[id].item_3 = 'value_3';
- storage.setItem('item_3', 'value_3', true);
- storage.setItem('item_4', 'value_4');
- expect(window[namespace]).toEqual(expected);
- });
-
- it('getItem', function() {
- // eslint-disable-next-line no-shadow
- var data = window[namespace],
- getItem = storage.getItem;
-
- expect(getItem('item_1', true)).toBe(data[id].item_1);
- expect(getItem('item_2')).toBe(data.item_2);
- expect(getItem('item_3')).toBeUndefined();
- });
-
- it('removeItem', function() {
- // eslint-disable-next-line no-shadow
- var data = window[namespace],
- removeItem = storage.removeItem;
-
- removeItem('item_1', true);
- removeItem('item_2');
- expect(data[id].item_1).toBeUndefined();
- expect(data.item_2).toBeUndefined();
- });
-
- it('clear', function() {
- var expected = {};
-
- expected[id] = {};
- storage.clear();
- expect(window[namespace]).toEqual(expected);
- });
- });
- });
- });
-}(require, define));
diff --git a/xmodule/js/spec/video/video_transcript_feedback_spec.js b/xmodule/js/spec/video/video_transcript_feedback_spec.js
deleted file mode 100644
index dde494937a1a..000000000000
--- a/xmodule/js/spec/video/video_transcript_feedback_spec.js
+++ /dev/null
@@ -1,271 +0,0 @@
-(function() {
- // eslint-disable-next-line lines-around-directive
- 'use strict';
-
- describe('VideoTranscriptFeedback', function() {
- var state;
- var videoId = "365b710a-6dd6-11ee-b962-0242ac120002";
- var userId = 1;
- var currentLanguage = "en";
- var getAITranscriptUrl = '/video-transcript' + '?transcript_language=' + currentLanguage + '&video_id=' + videoId;
- var getTranscriptFeedbackUrl = '/transcript-feedback' + '?transcript_language=' + currentLanguage + '&video_id=' + videoId + '&user_id=' + userId;
- var sendTranscriptFeedbackUrl = '/transcript-feedback/';
-
- beforeEach(function() {
- state = jasmine.initializePlayer('video_transcript_feedback.html');
- });
-
- afterEach(function() {
- $('source').remove();
- state.storage.clear();
- if (state.videoPlayer) {
- state.videoPlayer.destroy();
- }
- });
-
- describe('initialize', function() {
- it('instantiates widget and handlers along with necessary data', function() {
- spyOn(state.videoTranscriptFeedback, 'loadAndSetVisibility').and.callFake(function() {
- return true;
- });
- spyOn(state.videoTranscriptFeedback, 'bindHandlers').and.callFake(function() {
- return true;
- });
- state.videoTranscriptFeedback.initialize();
-
- expect(state.videoTranscriptFeedback.videoId).toEqual(videoId);
- expect(state.videoTranscriptFeedback.userId).toEqual(userId);
- expect(state.videoTranscriptFeedback.currentTranscriptLanguage).toEqual(currentLanguage);
- expect(state.videoTranscriptFeedback.loadAndSetVisibility).toHaveBeenCalled();
- expect(state.videoTranscriptFeedback.bindHandlers).toHaveBeenCalled();
- });
- });
-
- describe('should show widget', function() {
- it('checks if transcript was AI generated', function() {
- spyOn(state.videoTranscriptFeedback, 'loadAndSetVisibility').and.callThrough();
- state.videoTranscriptFeedback.loadAndSetVisibility();
-
- var getAITranscriptCall = $.ajax.calls.all().find(function(call) {
- return call.args[0].url.match(/.+video-transcript.+$/);
- });
-
- expect(state.videoTranscriptFeedback.loadAndSetVisibility).toHaveBeenCalled();
- expect(getAITranscriptCall.args[0].url).toEqual(state.videoTranscriptFeedback.aiTranslationsUrl + getAITranscriptUrl);
- expect(getAITranscriptCall.args[0].type).toEqual('GET');
- expect(getAITranscriptCall.args[0].async).toEqual(false);
- expect(getAITranscriptCall.args[0].success).toEqual(jasmine.any(Function));
- expect(getAITranscriptCall.args[0].error).toEqual(jasmine.any(Function));
- });
- it('shows widget if transcript is AI generated', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- expect($('.wrapper-transcript-feedback')[0]).toExist();
- });
- it('hides widget if transcript is not AI generated', function() {
- state.videoTranscriptFeedback.videoId = 'notAIGenerated';
- state.videoTranscriptFeedback.loadAndSetVisibility();
- expect($('.wrapper-transcript-feedback')[0]).toExist();
- expect($('.wrapper-transcript-feedback')[0].style.display).toEqual('none');
- });
- it('hides widget if transcript is AI generated but is still in progress', function() {
- state.videoTranscriptFeedback.videoId = 'inProgress';
- state.videoTranscriptFeedback.loadAndSetVisibility();
- expect($('.wrapper-transcript-feedback')[0]).toExist();
- expect($('.wrapper-transcript-feedback')[0].style.display).toEqual('none');
- });
- it('hides widget if query for transcript AI generated fails', function() {
- state.videoTranscriptFeedback.videoId = 'error';
- state.videoTranscriptFeedback.loadAndSetVisibility();
- expect($('.wrapper-transcript-feedback')[0]).toExist();
- expect($('.wrapper-transcript-feedback')[0].style.display).toEqual('none');
- });
- it('checks if feedback exists for AI generated transcript', function() {
- spyOn(state.videoTranscriptFeedback, 'getFeedbackForCurrentTranscript').and.callThrough();
- state.videoTranscriptFeedback.loadAndSetVisibility();
-
- var getTranscriptFeedbackCall = $.ajax.calls.all().find(function(call) {
- return call.args[0].url.match(/.+transcript-feedback.+$/);
- });
-
- expect(state.videoTranscriptFeedback.getFeedbackForCurrentTranscript).toHaveBeenCalled();
- expect(getTranscriptFeedbackCall.args[0].url).toEqual(state.videoTranscriptFeedback.aiTranslationsUrl + getTranscriptFeedbackUrl);
- expect(getTranscriptFeedbackCall.args[0].type).toEqual('GET');
- expect(getTranscriptFeedbackCall.args[0].success).toEqual(jasmine.any(Function));
- expect(getTranscriptFeedbackCall.args[0].error).toEqual(jasmine.any(Function));
- });
- });
-
- describe('get feedback for current transcript', function() {
- it('marks thumbs up button if feedback exists and it is positive', function() {
- state.videoTranscriptFeedback.getFeedbackForCurrentTranscript();
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-o-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(true);
- });
- it('marks thumbs down button if feedback exists and it is negative', function() {
- state.videoTranscriptFeedback.videoId = 'negative';
- state.videoTranscriptFeedback.getFeedbackForCurrentTranscript();
-
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-o-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(false);
- });
- it('marks thumbs up buttons as empty if feedback does not exist', function() {
- state.videoTranscriptFeedback.videoId = 'none';
- state.videoTranscriptFeedback.getFeedbackForCurrentTranscript();
-
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-o-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-o-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(null);
- });
- it('marks thumbs up buttons as empty if query fails', function() {
- state.videoTranscriptFeedback.videoId = 'error';
- state.videoTranscriptFeedback.getFeedbackForCurrentTranscript();
-
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-o-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-o-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(null);
- });
- });
-
- describe('onHideLanguageMenu', function() {
- it('calls loadAndSetVisibility if language changed', function() {
- state.videoTranscriptFeedback.currentTranscriptLanguage = 'es';
- spyOn(state.videoTranscriptFeedback, 'loadAndSetVisibility').and.callThrough();
- state.el.trigger('language_menu:hide', {
- id: 'id',
- code: 'code',
- language: 'en',
- duration: 10
- });
- expect(state.videoTranscriptFeedback.loadAndSetVisibility).toHaveBeenCalled();
- });
- it('does not call loadAndSetVisibility if language did not change', function() {
- state.videoTranscriptFeedback.currentTranscriptLanguage = 'en';
- spyOn(state.videoTranscriptFeedback, 'loadAndSetVisibility').and.callThrough();
- state.el.trigger('language_menu:hide', {
- id: 'id',
- code: 'code',
- language: 'en',
- duration: 10
- });
- expect(state.videoTranscriptFeedback.loadAndSetVisibility).not.toHaveBeenCalled();
- });
- });
-
- describe('clicking on thumbs up button', function() {
- it('sends positive feedback if there is no current feedback', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = undefined;
- spyOn(state.videoTranscriptFeedback, 'sendFeedbackForCurrentTranscript').and.callFake(function() {
- return true;
- });
- var thumbsUpButton = $('.thumbs-up-btn');
- thumbsUpButton.trigger('click');
- expect(state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript).toHaveBeenCalledWith(true);
- });
- it('sends empty feedback if there is a current positive feedback', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = true;
- spyOn(state.videoTranscriptFeedback, 'sendFeedbackForCurrentTranscript').and.callFake(function() {
- return true;
- });
- var thumbsUpButton = $('.thumbs-up-btn');
- thumbsUpButton.trigger('click');
- expect(state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript).toHaveBeenCalledWith(null);
- });
- });
-
- describe('clicking on thumbs down button', function() {
- it('sends negative feedback if there is no current feedback', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = undefined;
- spyOn(state.videoTranscriptFeedback, 'sendFeedbackForCurrentTranscript').and.callFake(function() {
- return true;
- });
- var thumbsDownButton = $('.thumbs-down-btn');
- thumbsDownButton.trigger('click');
- expect(state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript).toHaveBeenCalledWith(false);
- });
- it('sends empty feedback if there is a current negative feedback', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = false;
- spyOn(state.videoTranscriptFeedback, 'sendFeedbackForCurrentTranscript').and.callFake(function() {
- return true;
- });
- var thumbsDownButton = $('.thumbs-down-btn');
- thumbsDownButton.trigger('click');
- expect(state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript).toHaveBeenCalledWith(null);
- });
- });
-
- describe('calling send transcript feedback', function() {
- it('sends proper request to ai translation service', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = undefined;
- state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript(true);
- var sendTranscriptFeedbackCall = $.ajax.calls.all().find(function(call) {
- return call.args[0].url.match(/.+transcript-feedback.+$/) && call.args[0].type === 'POST';
- });
-
- expect(sendTranscriptFeedbackCall.args[0].url).toEqual(state.videoTranscriptFeedback.aiTranslationsUrl + sendTranscriptFeedbackUrl);
- expect(sendTranscriptFeedbackCall.args[0].type).toEqual('POST');
- expect(sendTranscriptFeedbackCall.args[0].dataType).toEqual('json');
- expect(sendTranscriptFeedbackCall.args[0].data).toEqual({
- transcript_language: currentLanguage,
- video_id: videoId,
- user_id: userId,
- value: true,
- });
- expect(sendTranscriptFeedbackCall.args[0].success).toEqual(jasmine.any(Function));
- expect(sendTranscriptFeedbackCall.args[0].error).toEqual(jasmine.any(Function));
- });
- it('marks thumbs up button as selected if response is positive', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = undefined;
- state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript(true);
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-o-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(true);
- });
- it('marks thumbs down button as selected if response is negative', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = undefined;
- state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript(false);
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-o-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(false);
- });
- it('unselects thumbs buttons if response is empty', function() {
- state.videoTranscriptFeedback.loadAndSetVisibility();
- state.videoTranscriptFeedback.currentFeedback = true;
- state.videoTranscriptFeedback.sendFeedbackForCurrentTranscript(null);
- var thumbsUpIcon = $('.thumbs-up-icon')[0];
- var thumbsDownIcon = $('.thumbs-down-icon')[0];
-
- expect(thumbsUpIcon.classList).toContain('fa-thumbs-o-up');
- expect(thumbsDownIcon.classList).toContain('fa-thumbs-o-down');
- expect(state.videoTranscriptFeedback.currentFeedback).toEqual(null);
- });
- });
- });
-}).call(this);
diff --git a/xmodule/js/spec/video/video_volume_control_spec.js b/xmodule/js/spec/video/video_volume_control_spec.js
deleted file mode 100644
index c869316031b1..000000000000
--- a/xmodule/js/spec/video/video_volume_control_spec.js
+++ /dev/null
@@ -1,326 +0,0 @@
-(function() {
- 'use strict';
-
- describe('VideoVolumeControl', function() {
- var state, oldOTBD, volumeControl;
-
- var KEY = $.ui.keyCode,
-
- keyPressEvent = function(key) {
- return $.Event('keydown', {keyCode: key});
- };
-
- beforeEach(function() {
- oldOTBD = window.onTouchBasedDevice;
- window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
- .and.returnValue(null);
- });
-
- afterEach(function() {
- $('source').remove();
- window.onTouchBasedDevice = oldOTBD;
- state.storage.clear();
- state.videoPlayer.destroy();
- });
-
- it('Volume level has correct value even if cookie is broken', function() {
- $.cookie.and.returnValue('broken_cookie');
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- expect(volumeControl.volume).toEqual(100);
- });
-
- describe('constructor', function() {
- beforeEach(function() {
- spyOn($.fn, 'slider').and.callThrough();
- $.cookie.and.returnValue('75');
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- it('initialize volume to 75%', function() {
- expect(volumeControl.volume).toEqual(75);
- });
-
- it('render the volume control', function() {
- expect($('.volume')).toExist();
- });
-
- it('create the slider', function() {
- expect($.fn.slider.calls.argsFor(2)).toEqual([{
- orientation: 'vertical',
- range: 'min',
- min: 0,
- max: 100,
- slide: jasmine.any(Function)
- }]);
- expect($.fn.slider).toHaveBeenCalledWith(
- 'value', volumeControl.volume
- );
- });
-
- it('add ARIA attributes to live region', function() {
- var $liveRegion = $('.video-live-region');
-
- expect($liveRegion).toHaveAttrs({
- 'aria-live': 'polite'
- });
- });
-
- it('add ARIA attributes to volume control', function() {
- var $button = $('.volume .control');
-
- expect($button).toHaveAttrs({
- 'aria-disabled': 'false'
- });
- });
-
- it('bind the volume control', function() {
- var $button = $('.volume .control');
-
- expect($button).toHandle('keydown');
- expect($button).toHandle('mousedown');
- expect($('.volume')).not.toHaveClass('is-opened');
-
- $('.volume').mouseenter();
- expect($('.volume')).toHaveClass('is-opened');
-
- $('.volume').mouseleave();
- expect($('.volume')).not.toHaveClass('is-opened');
- });
- });
-
- describe('setVolume', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
-
- jasmine.addMatchers({
- assertLiveRegionState: function() {
- return {
- compare: function(actual, volume, expectation) {
- var $region = $('.video-live-region');
-
- var getExpectedText = function(text) {
- return text + ' Volume.';
- };
-
- actual.setVolume(volume, true, true);
- return {
- pass: $region.text() === getExpectedText(expectation)
- };
- }
- };
- }
- });
- });
-
- it('update is not called, if new volume equals current', function() {
- volumeControl.volume = 60;
- spyOn(volumeControl, 'updateSliderView');
- volumeControl.setVolume(60, false, true);
- expect(volumeControl.updateSliderView).not.toHaveBeenCalled();
- });
-
- it('volume is changed on sliding', function() {
- volumeControl.onSlideHandler(null, {value: 99});
- expect(volumeControl.volume).toBe(99);
- });
-
- describe('when the new volume is more than 0', function() {
- beforeEach(function() {
- volumeControl.setVolume(60, false, true);
- });
-
- it('set the player volume', function() {
- expect(volumeControl.volume).toEqual(60);
- });
-
- it('remove muted class', function() {
- expect($('.volume')).not.toHaveClass('is-muted');
- });
- });
-
- describe('when the new volume is more than 0, but was 0', function() {
- it('remove muted class', function() {
- volumeControl.setVolume(0, false, true);
- expect($('.volume')).toHaveClass('is-muted');
- state.el.trigger('volumechange', [20]);
- expect($('.volume')).not.toHaveClass('is-muted');
- });
- });
-
- describe('when the new volume is 0', function() {
- beforeEach(function() {
- volumeControl.setVolume(0, false, true);
- });
-
- it('set the player volume', function() {
- expect(volumeControl.volume).toEqual(0);
- });
-
- it('add muted class', function() {
- expect($('.volume')).toHaveClass('is-muted');
- });
- });
-
- it('when the new volume is Muted', function() {
- expect(volumeControl).assertLiveRegionState(0, 'Muted');
- });
-
- it('when the new volume is in ]0,20]', function() {
- expect(volumeControl).assertLiveRegionState(10, 'Very low');
- });
-
- it('when the new volume is in ]20,40]', function() {
- expect(volumeControl).assertLiveRegionState(30, 'Low');
- });
-
- it('when the new volume is in ]40,60]', function() {
- expect(volumeControl).assertLiveRegionState(50, 'Average');
- });
-
- it('when the new volume is in ]60,80]', function() {
- expect(volumeControl).assertLiveRegionState(70, 'Loud');
- });
-
- it('when the new volume is in ]80,100[', function() {
- expect(volumeControl).assertLiveRegionState(90, 'Very loud');
- });
-
- it('when the new volume is Maximum', function() {
- expect(volumeControl).assertLiveRegionState(100, 'Maximum');
- });
- });
-
- describe('increaseVolume', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- it('volume is increased correctly', function() {
- var $button = $('.volume .control');
- volumeControl.volume = 60;
-
- // adjust the volume
- $button.focus();
- $button.trigger(keyPressEvent(KEY.UP));
- expect(volumeControl.volume).toEqual(80);
- });
-
- it('volume level is not changed if it is already max', function() {
- volumeControl.volume = 100;
- volumeControl.increaseVolume();
- expect(volumeControl.volume).toEqual(100);
- });
- });
-
- describe('decreaseVolume', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- it('volume is decreased correctly', function() {
- var $button = $('.volume .control');
- volumeControl.volume = 60;
-
- // adjust the volume
- $button.focus();
- $button.trigger(keyPressEvent(KEY.DOWN));
- expect(volumeControl.volume).toEqual(40);
- });
-
- it('volume level is not changed if it is already min', function() {
- volumeControl.volume = 0;
- volumeControl.decreaseVolume();
- expect(volumeControl.volume).toEqual(0);
- });
- });
-
- describe('toggleMute', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- describe('when the current volume is more than 0', function() {
- beforeEach(function() {
- volumeControl.volume = 60;
- volumeControl.button.trigger('mousedown');
- });
-
- it('save the previous volume', function() {
- expect(volumeControl.storedVolume).toEqual(60);
- });
-
- it('set the player volume', function() {
- expect(volumeControl.volume).toEqual(0);
- });
- });
-
- describe('when the current volume is 0', function() {
- beforeEach(function() {
- volumeControl.volume = 0;
- volumeControl.storedVolume = 60;
- volumeControl.button.trigger('mousedown');
- });
-
- it('set the player volume to previous volume', function() {
- expect(volumeControl.volume).toEqual(60);
- });
- });
- });
-
- describe('keyDownHandler', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- var assertVolumeIsNotChanged = function(eventObject) {
- volumeControl.volume = 60;
- state.el.trigger(jQuery.Event('keydown', eventObject));
- expect(volumeControl.volume).toEqual(60);
- };
-
- it('nothing happens if ALT+keyUp are pushed down', function() {
- assertVolumeIsNotChanged({
- keyCode: KEY.UP,
- altKey: true
- });
- });
-
- it('nothing happens if SHIFT+keyUp are pushed down', function() {
- assertVolumeIsNotChanged({
- keyCode: KEY.UP,
- shiftKey: true
- });
- });
-
- it('nothing happens if SHIFT+keyDown are pushed down', function() {
- assertVolumeIsNotChanged({
- keyCode: KEY.DOWN,
- shiftKey: true
- });
- });
- });
-
- describe('keyDownButtonHandler', function() {
- beforeEach(function() {
- state = jasmine.initializePlayer();
- volumeControl = state.videoVolumeControl;
- });
-
- it('nothing happens if ALT+ENTER are pushed down', function() {
- var isMuted = volumeControl.getMuteStatus();
- $('.volume .control').trigger(jQuery.Event('keydown', {
- keyCode: KEY.ENTER,
- altKey: true
- }));
- expect(volumeControl.getMuteStatus()).toEqual(isMuted);
- });
- });
- });
-}).call(this);