Files
edx-platform/xmodule/js/spec/video/async_process_spec.js
Muhammad Farhan Khan 5c759f1e13 refactor: Update and migrate Video Block JS files into xmodule/assets
- Move Video Block JS files from xmodule/js/src/video/ to xmodule/assets/video/public/js/ 
- Update JavaScript files from  RequireJS to ES6 import/export
- test: Enable and fix Karma Js tests for Video XBlock (#37351)

---------

Co-authored-by: salmannawaz <salman.nawaz@arbisoft.com>
2025-10-07 19:01:50 +05:00

78 lines
2.1 KiB
JavaScript

import AsyncProcess from '../../../assets/video/public/js/00_async_process.js';
let getArrayNthLength = function(n, multiplier) {
let result = [],
mul = multiplier || 1;
for (let 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);
});
});