playable
Version:
Video player based on HTML5Video
157 lines • 8.22 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 loading_cover_1 = (0, tslib_1.__importDefault)(require("./loading-cover"));
var constants_1 = require("../../../constants");
describe('LoadingCover', function () {
var testkit;
var loadingCover;
var engine;
var eventEmitter;
var emitSpy;
beforeEach(function () {
testkit = (0, testkit_1.default)();
engine = testkit.getModule('engine');
eventEmitter = testkit.getModule('eventEmitter');
testkit.registerModule('loadingCover', loading_cover_1.default);
loadingCover = testkit.getModule('loadingCover');
emitSpy = sinon.spy(eventEmitter, 'emitAsync');
});
afterEach(function () {
eventEmitter.emitAsync.restore();
});
describe('constructor', function () {
it('should create instance ', function () {
(0, chai_1.expect)(loadingCover).to.exist;
(0, chai_1.expect)(loadingCover.view).to.exist;
});
});
describe('instance', function () {
describe('public API', function () {
it('should have method for getting view node', function () {
var getElementSpy = sinon.spy(loadingCover.view, 'getElement');
loadingCover.getElement();
(0, chai_1.expect)(getElementSpy.called).to.be.true;
});
it('should have method for setting cover', function () {
var url = 'url';
var setCoverSpy = sinon.spy(loadingCover.view, 'setCover');
loadingCover.setLoadingCover(url);
(0, chai_1.expect)(setCoverSpy.calledWith(url)).to.be.true;
});
it('should have method for showing loader', function () {
var showSpy = sinon.spy(loadingCover.view, 'show');
loadingCover.show();
(0, chai_1.expect)(emitSpy.calledWith(constants_1.UIEvent.LOADING_COVER_SHOW)).to.be.true;
(0, chai_1.expect)(showSpy.called).to.be.true;
(0, chai_1.expect)(loadingCover.isHidden).to.be.false;
});
it('should have method for hiding loader', function () {
loadingCover.show();
var hideSpy = sinon.spy(loadingCover.view, 'hide');
loadingCover.hide();
(0, chai_1.expect)(emitSpy.calledWith(constants_1.UIEvent.LOADING_COVER_HIDE)).to.be.true;
(0, chai_1.expect)(hideSpy.called).to.be.true;
(0, chai_1.expect)(loadingCover.isHidden).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:
loadingCover.show();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.UPLOAD_SUSPEND)];
case 1:
_a.sent();
(0, chai_1.expect)(loadingCover.isHidden).to.be.true;
return [2 /*return*/];
}
});
});
});
describe('signifying state change', function () {
var showSpy;
var hideSpy;
beforeEach(function () {
showSpy = sinon.spy(loadingCover, 'show');
hideSpy = sinon.spy(loadingCover, 'hide');
});
afterEach(function () {
loadingCover.show.restore();
loadingCover.hide.restore();
});
it('should be proper if next state is EngineState.LOAD_STARTED', 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:
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.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:
engine._output._stateEngine._isMetadataLoaded = true;
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.WAITING,
})];
case 1:
_a.sent();
(0, chai_1.expect)(showSpy.called).to.be.false;
engine._output._stateEngine._isMetadataLoaded = false;
engine.setPreload('auto');
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.WAITING,
})];
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 () {
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.READY_TO_PLAY,
})];
case 1:
_a.sent();
(0, chai_1.expect)(hideSpy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
});
});
});
});
//# sourceMappingURL=loading-cover.spec.js.map