Files
edx-platform/xmodule/js/spec/video/video_storage_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

82 lines
2.4 KiB
JavaScript

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);
});
});
});