diff --git a/common/static/common/js/karma.common.conf.js b/common/static/common/js/karma.common.conf.js index 16501f47ad55..b49db1298d87 100644 --- a/common/static/common/js/karma.common.conf.js +++ b/common/static/common/js/karma.common.conf.js @@ -332,7 +332,11 @@ function getBaseConfig(config, useRequireJs) { base: 'Firefox', prefs: { 'app.update.auto': false, - 'app.update.enabled': false + 'app.update.enabled': false, + 'media.autoplay.default': 0, // allow autoplay + 'media.autoplay.blocking_policy': 0, // disable autoplay blocking + 'media.autoplay.allow-extension-background-pages': true, + 'media.autoplay.enabled.user-gestures-needed': false, } }, ChromeDocker: { diff --git a/package.json b/package.json index db433985b60d..7b2eb98930d8 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "watch-sass": "scripts/watch_sass.sh", "test": "npm run test-jest && npm run test-karma", "test-jest": "jest", - "test-karma": "npm run test-karma-vanilla && npm run test-karma-require && echo 'WARNING: Skipped broken webpack tests. For details, see: https://github.com/openedx/edx-platform/issues/35956'", + "test-karma": "npm run test-karma-vanilla && npm run test-karma-require && npm run test-xmodule-webpack && echo 'WARNING: Skipped broken webpack tests. For details, see: https://github.com/openedx/edx-platform/issues/35956'", "test-karma-vanilla": "npm run test-cms-vanilla && npm run test-xmodule-vanilla && npm run test-common-vanilla", "test-karma-require": "npm run test-cms-require && npm run test-common-require", "test-karma-webpack": "npm run test-cms-webpack && npm run test-lms-webpack && npm run test-xmodule-webpack", diff --git a/webpack.common.config.js b/webpack.common.config.js index 3854eb3937a0..f6fd4fa357f2 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -671,9 +671,11 @@ module.exports = Merge.merge({ $: 'jQuery', backbone: 'Backbone', canvas: 'canvas', + fs: 'fs', gettext: 'gettext', jquery: 'jQuery', logger: 'Logger', + path: 'path', underscore: '_', URI: 'URI', XBlockToXModuleShim: 'XBlockToXModuleShim', diff --git a/xmodule/assets/video/public/js/04_video_control.js b/xmodule/assets/video/public/js/04_video_control.js index efac9368b5ce..d928aeb6b895 100644 --- a/xmodule/assets/video/public/js/04_video_control.js +++ b/xmodule/assets/video/public/js/04_video_control.js @@ -2,7 +2,6 @@ import * as Time from './utils/time.js'; - // VideoControl module. let VideoControl = function(state) { let dfd = $.Deferred(); diff --git a/xmodule/js/karma_runner_webpack.js b/xmodule/js/karma_runner_webpack.js index 6dfee7db9e7d..d00be7111757 100644 --- a/xmodule/js/karma_runner_webpack.js +++ b/xmodule/js/karma_runner_webpack.js @@ -27,12 +27,16 @@ import '../../common/static/common/js/spec_helpers/jasmine-waituntil.js'; import '../../common/static/common/js/spec_helpers/jasmine-extensions.js'; import '../../common/static/common/js/vendor/sinon.js'; +import HtmlUtils from 'edx-ui-toolkit/js/utils/html-utils'; +import StringUtils from 'edx-ui-toolkit/js/utils/string-utils'; + + // These libraries are used by the tests (and the code under test) // but not explicitly imported import 'jquery.ui'; // These -import './src/video/10_main.js'; +import '../assets/video/public/js/10_main.js'; import './spec/helper.js'; import './spec/video_helper.js'; @@ -71,11 +75,18 @@ import './spec/video/video_transcript_feedback_spec.js'; import './spec/video/video_volume_control_spec.js'; import './spec/time_spec.js'; + // overwrite the loaded method and manually start the karma after a delay // Somehow the code initialized in jQuery's onready doesn't get called before karma auto starts // eslint-disable-next-line no-unused-expressions 'use strict'; + +window._ = _; +window.edx = window.edx || {}; +window.edx.HtmlUtils = HtmlUtils; +window.edx.StringUtils = StringUtils; + window.__karma__.loaded = function() { setTimeout(function() { window.__karma__.start(); diff --git a/xmodule/js/karma_xmodule_webpack.conf.js b/xmodule/js/karma_xmodule_webpack.conf.js index e0abad75a8ba..dc5fd4812f59 100644 --- a/xmodule/js/karma_xmodule_webpack.conf.js +++ b/xmodule/js/karma_xmodule_webpack.conf.js @@ -23,8 +23,8 @@ var options = { specFiles: [], fixtureFiles: [ - {pattern: 'fixtures/*.*'}, - {pattern: 'fixtures/hls/**/*.*'} + {pattern: path.join(__dirname, 'fixtures/*.*')}, + {pattern: path.join(__dirname, 'fixtures/hls/**/*.*')} ], runFiles: [ diff --git a/xmodule/js/spec/helper.js b/xmodule/js/spec/helper.js index caeb270a072a..96ad60ce1978 100644 --- a/xmodule/js/spec/helper.js +++ b/xmodule/js/spec/helper.js @@ -255,7 +255,8 @@ } jasmine.stubRequests(); - state = new window.Video('#example'); + let runtime = jasmine.createSpyObj('TestRuntime', ['handlerUrl']); + state = new window.Video(runtime, '#example'); state.resizer = (function() { var methods = [ diff --git a/xmodule/js/spec/time_spec.js b/xmodule/js/spec/time_spec.js index 5e2d2b882506..94cdf8e952dd 100644 --- a/xmodule/js/spec/time_spec.js +++ b/xmodule/js/spec/time_spec.js @@ -1,6 +1,6 @@ 'use strict'; -import * as Time from 'time.js'; +import * as Time from '../../assets/video/public/js/utils/time.js'; describe('Time', function() { describe('format', function() { diff --git a/xmodule/js/spec/video/async_process_spec.js b/xmodule/js/spec/video/async_process_spec.js index b74579db3914..c7ae1d8f76dc 100644 --- a/xmodule/js/spec/video/async_process_spec.js +++ b/xmodule/js/spec/video/async_process_spec.js @@ -1,81 +1,77 @@ -(function(require) { - require( - ['video/00_async_process.js'], - function(AsyncProcess) { - var getArrayNthLength = function(n, multiplier) { - var result = [], - mul = multiplier || 1; +import AsyncProcess from '../../../assets/video/public/js/00_async_process.js'; - for (var i = 0; i < n; i++) { - result[i] = i * mul; - } +let getArrayNthLength = function(n, multiplier) { + let result = [], + mul = multiplier || 1; - return result; - }, - items = getArrayNthLength(1000); + for (let i = 0; i < n; i++) { + result[i] = i * mul; + } - describe('AsyncProcess', function() { - it('Array is processed successfully', function(done) { - var processedArray, - expectedArray = getArrayNthLength(1000, 2), - process = function(item) { - return 2 * item; - }; + return result; +}, +items = getArrayNthLength(1000); - AsyncProcess.array(items, process).done(function(result) { - processedArray = result; - }); +describe('AsyncProcess', function() { + it('Array is processed successfully', function(done) { + var processedArray, + expectedArray = getArrayNthLength(1000, 2), + process = function(item) { + return 2 * item; + }; - jasmine.waitUntil(function() { - return processedArray; - }).then(function() { - expect(processedArray).toEqual(expectedArray); - }).always(done); - }); + AsyncProcess.array(items, process).done(function(result) { + processedArray = result; + }); - it('If non-array is passed, error callback is called', function(done) { - var isError, - process = function() {}; + jasmine.waitUntil(function() { + return processedArray; + }).then(function() { + expect(processedArray).toEqual(expectedArray); + }).always(done); + }); - AsyncProcess.array('string', process).fail(function() { - isError = true; - }); + it('If non-array is passed, error callback is called', function(done) { + var isError, + process = function() {}; - jasmine.waitUntil(function() { - return isError; - }).then(function() { - expect(isError).toBeTruthy(); - }).always(done); - }); + AsyncProcess.array('string', process).fail(function() { + isError = true; + }); - it('If an empty array is passed, returns initial array', function(done) { - var processedArray, - process = function() {}; + jasmine.waitUntil(function() { + return isError; + }).then(function() { + expect(isError).toBeTruthy(); + }).always(done); + }); - AsyncProcess.array([], process).done(function(result) { - processedArray = result; - }); + it('If an empty array is passed, returns initial array', function(done) { + var processedArray, + process = function() {}; - jasmine.waitUntil(function() { - return processedArray; - }).then(function() { - expect(processedArray).toEqual([]); - }).always(done); - }); + AsyncProcess.array([], process).done(function(result) { + processedArray = result; + }); - it('If no process function passed, returns initial array', function(done) { - var processedArray; + jasmine.waitUntil(function() { + return processedArray; + }).then(function() { + expect(processedArray).toEqual([]); + }).always(done); + }); - AsyncProcess.array(items).done(function(result) { - processedArray = result; - }); + it('If no process function passed, returns initial array', function(done) { + var processedArray; - jasmine.waitUntil(function() { - return processedArray; - }).then(function() { - expect(processedArray).toEqual(items); - }).always(done); - }); - }); + AsyncProcess.array(items).done(function(result) { + processedArray = result; }); -}(require)); + + jasmine.waitUntil(function() { + return processedArray; + }).then(function() { + expect(processedArray).toEqual(items); + }).always(done); + }); +}); diff --git a/xmodule/js/spec/video/initialize_spec.js b/xmodule/js/spec/video/initialize_spec.js index 0ce88aa2758a..119a9b2565dc 100644 --- a/xmodule/js/spec/video/initialize_spec.js +++ b/xmodule/js/spec/video/initialize_spec.js @@ -1,330 +1,324 @@ -(function(require) { - 'use strict'; +import Initialize from '../../../assets/video/public/js/01_initialize.js'; - require( - ['video/01_initialize.js'], - function(Initialize) { - describe('Initialize', function() { - var state = {}; +describe('Initialize', function() { + var state = {}; - afterEach(function() { - 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('getCurrentLanguage', function() { + var msg; - 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); - }); - }); - }); + beforeEach(function() { + state.config = {}; + state.config.transcriptLanguages = { + de: 'German', + en: 'English', + uk: 'Ukrainian' + }; + }); - 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'); - }); - }); - }); + 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; - 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)); - }); - }); - }); + 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); - describe('setPlayerMode', function() { - beforeEach(function() { - state = { - currentPlayerMode: 'flash' - }; - }); + expect(expected).toEqual('abcdefghijkl'); + }); + }); - it('updates player mode', function() { - var setPlayerMode = Initialize.prototype.setPlayerMode; + 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); - setPlayerMode.call(state, 'html5'); - expect(state.currentPlayerMode).toBe('html5'); - setPlayerMode.call(state, 'flash'); - expect(state.currentPlayerMode).toBe('flash'); - }); + expect(expected).toEqual('cogebirgzzM'); + }); + }); - it('sets default mode if passed is not supported', function() { - var setPlayerMode = Initialize.prototype.setPlayerMode; + 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'); - setPlayerMode.call(state, '77html77'); - expect(state.currentPlayerMode).toBe('html5'); - }); + 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('getPlayerMode', function() { - beforeEach(function() { - state = { - currentPlayerMode: 'flash' - }; - }); + describe('HTML5', function() { + beforeEach(function() { + state = { + speeds: ['0.75', '1.0', '1.25', '1.50', '2.0'], + storage: jasmine.createSpyObj('storage', ['setItem']) + }; + }); - it('returns current player mode', function() { - var getPlayerMode = Initialize.prototype.getPlayerMode, - actual = getPlayerMode.call(state); + describe('when 0.75 speed is available', function() { + beforeEach(function() { + Initialize.prototype.setSpeed.call(state, '0.75'); + }); - expect(actual).toBe(state.currentPlayerMode); - }); + it('set new speed', function() { + expect(state.speed).toEqual(0.75); }); + }); - 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('when 2.0 speed is available', function() { + beforeEach(function() { + Initialize.prototype.setSpeed.call(state, '2.0'); }); - 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(); - }); + 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 index 231daddff878..a00154bfeed5 100644 --- a/xmodule/js/spec/video/iterator_spec.js +++ b/xmodule/js/spec/video/iterator_spec.js @@ -1,105 +1,99 @@ -(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(); - }); +import Iterator from '../../../assets/video/public/js/00_iterator.js'; + +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'); }); }); -}(require)); + }); + + 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(); + }); +}); diff --git a/xmodule/js/spec/video/resizer_spec.js b/xmodule/js/spec/video/resizer_spec.js index 583b5e7bb308..827a9fb5d22c 100644 --- a/xmodule/js/spec/video/resizer_spec.js +++ b/xmodule/js/spec/video/resizer_spec.js @@ -1,270 +1,265 @@ -(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(); - }); +import Resizer from '../../../assets/video/public/js/00_resizer.js'; +import _ from 'underscore'; + +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); - }); + resizer = new Resizer(config); + }); - it('callbacks are called', function() { - $.each(spiesList, function(index, spy) { - resizer.callbacks.add(spy); - }); + it('callbacks are called', function() { + $.each(spiesList, function(index, spy) { + resizer.callbacks.add(spy); + }); - resizer.align(); + resizer.align(); - $.each(spiesList, function(index, spy) { - expect(spy).toHaveBeenCalled(); - }); - }); + $.each(spiesList, function(index, spy) { + expect(spy).toHaveBeenCalled(); + }); + }); - it('callback called just once', function() { - resizer.callbacks.once(spiesList[0]); + it('callback called just once', function() { + resizer.callbacks.once(spiesList[0]); - resizer - .align() - .alignByHeightOnly(); + resizer + .align() + .alignByHeightOnly(); - expect(spiesList[0].calls.count()).toEqual(1); - }); + expect(spiesList[0].calls.count()).toEqual(1); + }); - it('all callbacks are removed', function() { - $.each(spiesList, function(index, spy) { - resizer.callbacks.add(spy); - }); + it('all callbacks are removed', function() { + $.each(spiesList, function(index, spy) { + resizer.callbacks.add(spy); + }); - resizer.callbacks.removeAll(); - resizer.align(); + resizer.callbacks.removeAll(); + resizer.align(); - $.each(spiesList, function(index, spy) { - expect(spy).not.toHaveBeenCalled(); - }); - }); + $.each(spiesList, function(index, spy) { + expect(spy).not.toHaveBeenCalled(); + }); + }); - it('specific callback is removed', function() { - $.each(spiesList, function(index, spy) { - resizer.callbacks.add(spy); - }); + it('specific callback is removed', function() { + $.each(spiesList, function(index, spy) { + resizer.callbacks.add(spy); + }); - resizer.callbacks.remove(spiesList[1]); - resizer.align(); + resizer.callbacks.remove(spiesList[1]); + resizer.align(); - expect(spiesList[1]).not.toHaveBeenCalled(); - }); + 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 = {}; + 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'); + spyOn(console, 'error'); - $.each(methods, function(index, methodName) { - resizer.callbacks[methodName](arg); - expect(console.error).toHaveBeenCalledWith(errorMessage); - // reset spy - console.log.calls.reset(); - }); - }); + $.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; + describe('Delta', function() { + var resizer; - beforeEach(function() { - resizer = new Resizer(config); - }); + beforeEach(function() { + resizer = new Resizer(config); + }); - it('adding delta align correctly by height', function() { - var delta = 100, - expectedHeight = $container.height() + delta, - realHeight; + it('adding delta align correctly by height', function() { + var delta = 100, + expectedHeight = $container.height() + delta, + realHeight; - resizer - .delta.add(delta, 'height') - .setMode('height'); + resizer + .delta.add(delta, 'height') + .setMode('height'); - realHeight = $element.height(); + realHeight = $element.height(); - expect(realHeight).toBe(expectedHeight); - }); + expect(realHeight).toBe(expectedHeight); + }); - it('adding delta align correctly by width', function() { - var delta = 100, - expectedWidth = $container.width() + delta, - realWidth; + it('adding delta align correctly by width', function() { + var delta = 100, + expectedWidth = $container.width() + delta, + realWidth; - resizer - .delta.add(delta, 'width') - .setMode('width'); + resizer + .delta.add(delta, 'width') + .setMode('width'); - realWidth = $element.width(); + realWidth = $element.width(); - expect(realWidth).toBe(expectedWidth); - }); + expect(realWidth).toBe(expectedWidth); + }); - it('substract delta align correctly by height', function() { - var delta = 100, - expectedHeight = $container.height() - delta, - realHeight; + it('substract delta align correctly by height', function() { + var delta = 100, + expectedHeight = $container.height() - delta, + realHeight; - resizer - .delta.substract(delta, 'height') - .setMode('height'); + resizer + .delta.substract(delta, 'height') + .setMode('height'); - realHeight = $element.height(); + realHeight = $element.height(); - expect(realHeight).toBe(expectedHeight); - }); + expect(realHeight).toBe(expectedHeight); + }); - it('substract delta align correctly by width', function() { - var delta = 100, - expectedWidth = $container.width() - delta, - realWidth; + it('substract delta align correctly by width', function() { + var delta = 100, + expectedWidth = $container.width() - delta, + realWidth; - resizer - .delta.substract(delta, 'width') - .setMode('width'); + resizer + .delta.substract(delta, 'width') + .setMode('width'); - realWidth = $element.width(); + realWidth = $element.width(); - expect(realWidth).toBe(expectedWidth); - }); + expect(realWidth).toBe(expectedWidth); + }); - it('reset delta', function() { - var delta = 100, - expectedWidth = $container.width(), - realWidth; + it('reset delta', function() { + var delta = 100, + expectedWidth = $container.width(), + realWidth; - resizer - .delta.substract(delta, 'width') - .delta.reset() - .setMode('width'); + resizer + .delta.substract(delta, 'width') + .delta.reset() + .setMode('width'); - realWidth = $element.width(); + realWidth = $element.width(); - expect(realWidth).toBe(expectedWidth); - }); - }); - }); + expect(realWidth).toBe(expectedWidth); }); -}(require)); + }); +}); diff --git a/xmodule/js/spec/video/sjson_spec.js b/xmodule/js/spec/video/sjson_spec.js index bbcd8878d999..1d62887d3964 100644 --- a/xmodule/js/spec/video/sjson_spec.js +++ b/xmodule/js/spec/video/sjson_spec.js @@ -1,67 +1,63 @@ -(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)); +import Sjson from '../../../assets/video/public/js/00_sjson.js'; + +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); + }); +}); diff --git a/xmodule/js/spec/video/video_autoadvance_spec.js b/xmodule/js/spec/video/video_autoadvance_spec.js index 88a59be0e544..8c47c40c33f4 100644 --- a/xmodule/js/spec/video/video_autoadvance_spec.js +++ b/xmodule/js/spec/video/video_autoadvance_spec.js @@ -67,6 +67,11 @@ spyOnEvent($nextButton, 'click'); expect('click').not.toHaveBeenTriggeredOn($nextButton); + // Spy on window.parent.postMessage and make it trigger a click + spyOn(window.parent, 'postMessage').and.callFake(function() { + $nextButton.trigger('click'); + }); + state.el.trigger('ended'); jasmine.clock().tick(2); @@ -101,7 +106,7 @@ state.el.trigger('ended'); jasmine.clock().tick(2); - // still not auto-clicked + // still not auto-clicked (auto-advance is disabled) expect('click').not.toHaveBeenTriggeredOn($nextButton); }); }); diff --git a/xmodule/js/spec/video/video_caption_spec.js b/xmodule/js/spec/video/video_caption_spec.js index 43b2bfcb3c82..757267a3a587 100644 --- a/xmodule/js/spec/video/video_caption_spec.js +++ b/xmodule/js/spec/video/video_caption_spec.js @@ -447,10 +447,10 @@ $(this).trigger('mousedown'); expect(state.videoCaption.captionMouseDown).toHaveBeenCalled(); - $(this).trigger('focus'); + $(this).trigger('focusin'); expect(state.videoCaption.captionFocus).toHaveBeenCalled(); - $(this).trigger('blur'); + $(this).trigger('focusout'); expect(state.videoCaption.captionBlur).toHaveBeenCalled(); $(this).trigger('keydown'); @@ -1245,7 +1245,7 @@ beforeEach(function() { state.videoCaption.isMouseFocus = false; $('.subtitles li span[data-index=0]').trigger( - jQuery.Event('focus') + jQuery.Event('focusin') ); }); @@ -1353,25 +1353,25 @@ state = jasmine.initializePlayer(); Caption = state.videoCaption; }) - + it('not shown when captions are not ai generated', () => { Caption.updateGoogleDisclaimer(BASE_CAPTIONS) - expect(state.shouldShowGoogleDisclaimer).toBe(false); + expect(Caption.shouldShowGoogleDisclaimer).toBe(false); }); it('not shown when captions are not generated by gcp', () => { Caption.updateGoogleDisclaimer(makeCaptions('someoneElse')) - expect(state.shouldShowGoogleDisclaimer).toBe(false); + expect(Caption.shouldShowGoogleDisclaimer).toBe(false); }); it('shown when captions are generated by gcp', () => { Caption.updateGoogleDisclaimer(makeCaptions('gcp')) - expect(state.shouldShowGoogleDisclaimer).toBe(true); + expect(Caption.shouldShowGoogleDisclaimer).toBe(true); }); it('shown when captions have no provider', () => { Caption.updateGoogleDisclaimer(makeCaptions()) - expect(state.shouldShowGoogleDisclaimer).toBe(true); + expect(Caption.shouldShowGoogleDisclaimer).toBe(true); }); }); }); diff --git a/xmodule/js/spec/video/video_control_spec.js b/xmodule/js/spec/video/video_control_spec.js index 49326290716b..e1d7ce703a16 100644 --- a/xmodule/js/spec/video/video_control_spec.js +++ b/xmodule/js/spec/video/video_control_spec.js @@ -57,7 +57,7 @@ return isFinite(duration) && duration > 0 && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 1:00'); + expect(expectedValue).toHaveText('0:00 / 1:00'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -85,7 +85,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:15 / 1:00'); + expect(expectedValue).toHaveText('0:05 / 1:00'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(15); @@ -115,7 +115,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 1:00'); + expect(expectedValue).toHaveText('0:00 / 1:00'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -145,7 +145,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 1:00'); + expect(expectedValue).toHaveText('0:00 / 1:00'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -175,7 +175,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 1:00'); + expect(expectedValue).toHaveText('0:00 / 1:00'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -187,22 +187,29 @@ describe('constructor with end-time', function() { it('displays the correct time when startTime and endTime are specified', function(done) { + let duration; state = jasmine.initializePlayer({ start: 10, end: 20 }); spyOn(state.videoPlayer, 'duration').and.returnValue(60); - state.videoControl.updateVcrVidTime({ - time: 15, - duration: 60 - }); - jasmine.waitUntil(function() { - var expectedValue = $('.video-controls').find('.vidtime'); - return expectedValue.text().indexOf('0:05 / 0:20') !== -1; // Expecting 15 seconds - 10 seconds = 5 seconds + duration = state.videoPlayer.duration(); + return isFinite(duration) && duration > 0 && isFinite(state.videoPlayer.startTime); }).then(function() { - expect($('.video-controls').find('.vidtime')).toHaveText('0:05 / 0:20'); + // Update the video control time display + state.videoControl.updateVcrVidTime({ + time: 15, + duration: 60 + }); + + jasmine.waitUntil(function() { + var expectedValue = $('.video-controls').find('.vidtime'); + return expectedValue.text().indexOf('0:05 / 0:10') !== -1; // Expecting 15 seconds - 10 seconds = 5 seconds + }).then(function() { + expect($('.video-controls').find('.vidtime')).toHaveText('0:05 / 0:10'); + }).always(done); }).always(done); }); @@ -380,7 +387,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 0:20'); + expect(expectedValue).toHaveText('0:00 / 0:10'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -411,7 +418,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:15 / 0:20'); + expect(expectedValue).toHaveText('0:05 / 0:10'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(15); @@ -442,7 +449,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 0:20'); + expect(expectedValue).toHaveText('0:00 / 0:10'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -473,7 +480,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 0:20'); + expect(expectedValue).toHaveText('0:00 / 0:10'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); @@ -504,7 +511,7 @@ && isFinite(state.videoPlayer.startTime); }).then(function() { expectedValue = $('.video-controls').find('.vidtime'); - expect(expectedValue).toHaveText('0:10 / 0:20'); + expect(expectedValue).toHaveText('0:00 / 0:10'); expectedValue = sliderEl.slider('option', 'value'); expect(expectedValue).toBe(10); diff --git a/xmodule/js/spec/video/video_events_plugin_spec.js b/xmodule/js/spec/video/video_events_plugin_spec.js index ac809d054edc..80c551bcf82c 100644 --- a/xmodule/js/spec/video/video_events_plugin_spec.js +++ b/xmodule/js/spec/video/video_events_plugin_spec.js @@ -11,7 +11,6 @@ import '../helper.js'; beforeEach(function() { spyOn(Logger, 'log'); - spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); }); afterEach(function() { @@ -32,232 +31,244 @@ import '../helper.js'; }); }); - 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 + describe('getCurrentTime method', function() { + it('returns current time adjusted by startTime if video starts from a subsection', function() { + state.videoPlayer.currentTime = 120; + state.config.startTime = 30; + expect(state.videoEventsPlugin.getCurrentTime()).toBe(90); // 120 - 30 = 90 }); - 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('returns 0 if currentTime is undefined', function() { + state.config.startTime = 30; // Start time is irrelevant since current time is undefined + state.videoPlayer.currentTime = undefined; + expect(state.videoEventsPlugin.getCurrentTime()).toBe(0); }); - }); - 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('returns unadjusted current time if startTime is not defined', function() { + state.videoPlayer.currentTime = 60; + expect(state.videoEventsPlugin.getCurrentTime()).toBe(60); // Returns current time as is }); }); - 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(); - }); + describe('log method', function() { + + it('logs event with adjusted duration when startTime and endTime are defined', function() { + state.config.startTime = 30; + state.config.endTime = 150; + state.duration = 200; - 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(); - }); + state.videoEventsPlugin.log('test_event', {}); - 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(Logger.log).toHaveBeenCalledWith('test_event', { + id: 'id', + code: this.code, + duration: 120, // 150 - 30 = 120 + }); }); - 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 + it('can emit "play_video" event when emitPlayVideoEvent is true', function() { + state.videoEventsPlugin.emitPlayVideoEvent = true; + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + 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(); }); - 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 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 "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 "pause_video" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + 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 "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 "complete_video" event when video is marked as complete', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('complete'); + expect(Logger.log).toHaveBeenCalledWith('complete_video', { + id: 'id', + code: this.code, + currentTime: 10, + 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 "speed_change_video" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + 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 "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 "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 "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 "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 "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 "stop_video" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + 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 "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 emit "skip_video" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('skip', [false]); + expect(Logger.log).toHaveBeenCalledWith('skip_video', { + id: 'id', + code: this.code, + currentTime: 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 + it('can emit "do_not_show_again_video" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('skip', [true]); + expect(Logger.log).toHaveBeenCalledWith('do_not_show_again_video', { + id: 'id', + code: this.code, + currentTime: 10, + duration: this.duration + }); }); - }); - describe('getCurrentTime method', function() { - it('returns current time adjusted by startTime if video starts from a subsection', function() { - spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(120); - state.config.startTime = 30; - expect(state.videoEventsPlugin.getCurrentTime()).toBe(90); // 120 - 30 = 90 + 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('returns 0 if currentTime is undefined', function() { - spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(undefined); - state.config.startTime = 30; // Start time is irrelevant since current time is undefined - expect(state.videoEventsPlugin.getCurrentTime()).toBe(0); + 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('returns unadjusted current time if startTime is not defined', function() { - spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(60); - expect(state.videoEventsPlugin.getCurrentTime()).toBe(60); // Returns current time as is + it('can emit "show_transcript" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('transcript:show'); + expect(Logger.log).toHaveBeenCalledWith('show_transcript', { + id: 'id', + code: this.code, + current_time: 10, + duration: this.duration + }); }); - }); - describe('log method', function() { - it('logs event with adjusted duration when startTime and endTime are defined', function() { - state.config.startTime = 30; - state.config.endTime = 150; - state.duration = 200; + it('can emit "hide_transcript" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('transcript:hide'); + expect(Logger.log).toHaveBeenCalledWith('hide_transcript', { + id: 'id', + code: this.code, + current_time: 10, + duration: this.duration + }); + }); - state.videoEventsPlugin.log('test_event', {}); + it('can emit "edx.video.closed_captions.shown" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + 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 + }); + }); - expect(Logger.log).toHaveBeenCalledWith('test_event', { + it('can emit "edx.video.closed_captions.hidden" event', function() { + spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); + state.el.trigger('captions:hide'); + expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.hidden', { id: 'id', code: this.code, - duration: 120, // 150 - 30 = 120 + 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 }); }); diff --git a/xmodule/js/spec/video/video_focus_grabber_spec.js b/xmodule/js/spec/video/video_focus_grabber_spec.js index 9aca50e97cad..a927022510c7 100644 --- a/xmodule/js/spec/video/video_focus_grabber_spec.js +++ b/xmodule/js/spec/video/video_focus_grabber_spec.js @@ -18,7 +18,8 @@ jasmine.stubRequests(); loadFixtures('video_html5.html'); - state = new Video('#example'); + let runtime = jasmine.createSpyObj('TestRuntime', ['handlerUrl']); + state = new Video(runtime, '#example'); spyOnEvent(state.el, 'mousemove'); spyOn(state.focusGrabber, 'disableFocusGrabber').and.callThrough(); diff --git a/xmodule/js/spec/video/video_player_spec.js b/xmodule/js/spec/video/video_player_spec.js index 4845fc80fa1d..f964ef259076 100644 --- a/xmodule/js/spec/video/video_player_spec.js +++ b/xmodule/js/spec/video/video_player_spec.js @@ -1,12 +1,12 @@ /* global YT */ -// eslint-disable-next-line no-shadow-restricted-names -(function(require, define, undefined) { +import VideoPlayer from "../../../assets/video/public/js/03_video_player.js"; +import HLS from 'hls'; +import _ from 'underscore'; + +(function() { 'use strict'; - require( - ['video/03_video_player.js', 'hls', 'underscore'], - function(VideoPlayer, HLS, _) { describe('VideoPlayer', function() { var STATUS = window.STATUS, state, @@ -1097,5 +1097,5 @@ }); }); }); - }); -}(require, define)); + +}).call(this); diff --git a/xmodule/js/spec/video/video_progress_slider_spec.js b/xmodule/js/spec/video/video_progress_slider_spec.js index 5f91fc6e4216..531ce9bd27ff 100644 --- a/xmodule/js/spec/video/video_progress_slider_spec.js +++ b/xmodule/js/spec/video/video_progress_slider_spec.js @@ -153,8 +153,7 @@ spyOn(state.videoPlayer, 'onSlideSeek').and.callThrough(); }); - // Disabled 12/30/13 due to flakiness in master - xit('freeze the slider', function() { + it('freeze the slider', function() { state.videoProgressSlider.onSlide( jQuery.Event('slide'), {value: 20} ); @@ -162,8 +161,7 @@ expect(state.videoProgressSlider.frozen).toBeTruthy(); }); - // Disabled 12/30/13 due to flakiness in master - xit('trigger seek event', function() { + it('trigger seek event', function() { state.videoProgressSlider.onSlide( jQuery.Event('slide'), {value: 20} ); @@ -185,8 +183,7 @@ jasmine.clock().uninstall(); }); - // Disabled 12/30/13 due to flakiness in master - xit('freeze the slider', function() { + it('freeze the slider', function() { state.videoProgressSlider.onStop( jQuery.Event('stop'), {value: 20} ); @@ -194,8 +191,7 @@ expect(state.videoProgressSlider.frozen).toBeTruthy(); }); - // Disabled 12/30/13 due to flakiness in master - xit('trigger seek event', function() { + it('trigger seek event', function() { state.videoProgressSlider.onStop( jQuery.Event('stop'), {value: 20} ); @@ -203,8 +199,7 @@ expect(state.videoPlayer.onSlideSeek).toHaveBeenCalled(); }); - // Disabled 12/30/13 due to flakiness in master - xit('set timeout to unfreeze the slider', function() { + it('set timeout to unfreeze the slider', function() { state.videoProgressSlider.onStop( jQuery.Event('stop'), {value: 20} ); @@ -259,14 +254,14 @@ 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'); - + state.videoProgressSlider.handle.trigger('focus'); expect('focus').toHaveBeenTriggeredOn( state.videoProgressSlider.handle ); diff --git a/xmodule/js/spec/video/video_save_state_plugin_spec.js b/xmodule/js/spec/video/video_save_state_plugin_spec.js index 55c07bb06797..74fefa3200e6 100644 --- a/xmodule/js/spec/video/video_save_state_plugin_spec.js +++ b/xmodule/js/spec/video/video_save_state_plugin_spec.js @@ -1,4 +1,4 @@ -import * as Time from 'time.js'; +import * as Time from '../../../assets/video/public/js/utils/time.js'; // eslint-disable-next-line no-shadow-restricted-names (function(undefined) { diff --git a/xmodule/js/spec/video/video_speed_control_spec.js b/xmodule/js/spec/video/video_speed_control_spec.js index 279ecc19aeec..604ff6c50220 100644 --- a/xmodule/js/spec/video/video_speed_control_spec.js +++ b/xmodule/js/spec/video/video_speed_control_spec.js @@ -85,7 +85,8 @@ + 'entry has focus', function() { // Open speed meenu. Focus is on last speed entry. $speedControl.trigger(keyPressEvent(KEY.ENTER)); - $speedControl.mouseenter().mouseleave(); + $speedControl.mouseenter(); + expect(speedEntries.last()).toBeFocused(); expect($speedControl).toHaveClass('is-opened'); }); diff --git a/xmodule/js/spec/video/video_storage_spec.js b/xmodule/js/spec/video/video_storage_spec.js index 4d8ecaa57a26..5caf77b98542 100644 --- a/xmodule/js/spec/video/video_storage_spec.js +++ b/xmodule/js/spec/video/video_storage_spec.js @@ -1,86 +1,81 @@ -// 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); - }); - }); - }); +import VideoStorage from '../../../assets/video/public/js/00_video_storage.js'; + +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)); + }); +});