playable
Version:
Video player based on HTML5Video
220 lines • 11.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
require("jsdom-global/register");
var chai_1 = require("chai");
var sinon = (0, tslib_1.__importStar)(require("sinon"));
var testkit_1 = (0, tslib_1.__importDefault)(require("../../../testkit"));
var loader_1 = require("./loader");
var constants_1 = require("../../../constants");
describe('Loader', function () {
var loader;
var testkit;
var engine;
var eventEmitter;
var emitSpy;
describe('constructor', function () {
beforeEach(function () {
testkit = (0, testkit_1.default)();
});
it('should create instance ', function () {
loader = testkit.getModule('loader');
(0, chai_1.expect)(loader).to.exist;
(0, chai_1.expect)(loader.view).to.exist;
});
});
describe('instance', function () {
beforeEach(function () {
testkit = (0, testkit_1.default)();
loader = testkit.getModule('loader');
engine = testkit.getModule('engine');
eventEmitter = testkit.getModule('eventEmitter');
emitSpy = sinon.spy(eventEmitter, 'emitAsync');
});
afterEach(function () {
eventEmitter.emitAsync.restore();
});
describe('public API', function () {
it('should have method for showing loader', function () {
var showSpy = sinon.spy(loader.view, 'showContent');
loader._showContent();
(0, chai_1.expect)(emitSpy.calledWith(constants_1.UIEvent.LOADER_SHOW)).to.be.true;
(0, chai_1.expect)(showSpy.called).to.be.true;
(0, chai_1.expect)(loader.isHidden).to.be.false;
});
it('should have method for hiding loader', function () {
loader._showContent();
var hideSpy = sinon.spy(loader.view, 'hideContent');
loader._hideContent();
(0, chai_1.expect)(emitSpy.calledWith(constants_1.UIEvent.LOADER_HIDE)).to.be.true;
(0, chai_1.expect)(hideSpy.called).to.be.true;
(0, chai_1.expect)(loader.isHidden).to.be.true;
});
it('should have method for schedule delayed show', function () {
var setTimeoutSpy = sinon.spy(window, 'setTimeout');
loader.startDelayedShow();
(0, chai_1.expect)(setTimeoutSpy.calledWith(loader._showContent, loader_1.DELAYED_SHOW_TIMEOUT)).to.be.true;
(0, chai_1.expect)(loader.isDelayedShowScheduled).to.be.true;
setTimeoutSpy.restore();
});
it('should have method for unschedule delayed show', function () {
loader.startDelayedShow();
var clearTimeoutSpy = sinon.spy(window, 'clearTimeout');
loader.stopDelayedShow();
(0, chai_1.expect)(clearTimeoutSpy.called).to.be.true;
(0, chai_1.expect)(loader.isDelayedShowScheduled).to.be.false;
clearTimeoutSpy.restore();
});
it('should stop previous scheduled show if you trigger schedule', function () {
var stopSpy = sinon.spy(loader, 'stopDelayedShow');
loader.startDelayedShow();
loader.startDelayedShow();
(0, chai_1.expect)(stopSpy.calledOnce).to.be.true;
});
});
describe('reaction to event', function () {
it('should be proper if event is VideoEvent.UPLOAD_SUSPEND', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
loader.show();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.UPLOAD_SUSPEND)];
case 1:
_a.sent();
(0, chai_1.expect)(loader.isHidden).to.be.true;
return [2 /*return*/];
}
});
});
});
describe('signifying state change', function () {
var delayedShowSpy;
var stopDelayedShowSpy;
beforeEach(function () {
delayedShowSpy = sinon.spy(loader, 'startDelayedShow');
stopDelayedShowSpy = sinon.spy(loader, 'stopDelayedShow');
});
afterEach(function () {
loader.startDelayedShow.restore();
loader.stopDelayedShow.restore();
});
it('should be proper if next state is EngineState.SEEK_IN_PROGRESS', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.SEEK_IN_PROGRESS,
})];
case 1:
_a.sent();
(0, chai_1.expect)(delayedShowSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should be proper if next state is EngineState.WAITING', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.WAITING,
})];
case 1:
_a.sent();
(0, chai_1.expect)(delayedShowSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should be proper if next state is EngineState.LOAD_STARTED', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var showSpy;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
showSpy = sinon.spy(loader, '_showContent');
engine.setPreload('none');
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.LOAD_STARTED,
})];
case 1:
_a.sent();
(0, chai_1.expect)(showSpy.called).to.be.false;
engine.setPreload('auto');
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.LOAD_STARTED,
})];
case 2:
_a.sent();
(0, chai_1.expect)(showSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should be proper if next state is EngineState.READY_TO_PLAY', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var hideSpy;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
hideSpy = sinon.spy(loader, '_hideContent');
loader._showContent();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.READY_TO_PLAY,
})];
case 1:
_a.sent();
(0, chai_1.expect)(hideSpy.called).to.be.true;
(0, chai_1.expect)(stopDelayedShowSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should be proper if next state is EngineState.PLAYING', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var hideSpy;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
hideSpy = sinon.spy(loader, '_hideContent');
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.PLAYING,
})];
case 1:
_a.sent();
(0, chai_1.expect)(hideSpy.called).to.be.true;
(0, chai_1.expect)(stopDelayedShowSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should be proper if next state is EngineState.PAUSED', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var hideSpy;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
hideSpy = sinon.spy(loader, '_hideContent');
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.PAUSED,
})];
case 1:
_a.sent();
(0, chai_1.expect)(hideSpy.called).to.be.true;
(0, chai_1.expect)(stopDelayedShowSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
});
});
});
});
//# sourceMappingURL=loader.spec.js.map