UNPKG

playable

Version:

Video player based on HTML5Video

146 lines 6.87 kB
"use strict"; 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 constants_1 = require("../../../constants"); describe('Overlay', function () { var testkit; var overlay = {}; var eventEmitter = {}; var eventEmitterSpy = null; var mainUIBlock; var disableShowingContentSpy; var enableShowingContentSpy; var loader; var loaderShowSpy; var loaderHideSpy; beforeEach(function () { testkit = (0, testkit_1.default)(); }); describe('constructor', function () { beforeEach(function () { overlay = testkit.getModule('overlay'); }); it('should create instance ', function () { (0, chai_1.expect)(overlay).to.exist; (0, chai_1.expect)(overlay.view).to.exist; }); }); describe("check Loader's and MainUIBlock's API usage", function () { beforeEach(function () { overlay = testkit.getModule('overlay'); mainUIBlock = testkit.getModule('mainUIBlock'); enableShowingContentSpy = sinon.spy(mainUIBlock, 'enableShowingContent'); loader = testkit.getModule('loader'); loaderShowSpy = sinon.spy(loader, 'show'); eventEmitter = testkit.getModule('eventEmitter'); }); it("if Overlay's \"_hideContent\" method invokes external API", function () { return (0, tslib_1.__awaiter)(void 0, 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.PLAY_REQUESTED, })]; case 1: _a.sent(); (0, chai_1.expect)(loaderShowSpy.called).to.be.true; (0, chai_1.expect)(enableShowingContentSpy.called).to.be.true; return [2 /*return*/]; } }); }); }); }); describe("check Loader's and MainUIBlock's API usage v2", function () { beforeEach(function () { overlay = testkit.getModule('overlay'); mainUIBlock = testkit.getModule('mainUIBlock'); disableShowingContentSpy = sinon.spy(mainUIBlock, 'disableShowingContent'); loader = testkit.getModule('loader'); loaderHideSpy = sinon.spy(loader, 'hide'); eventEmitter = testkit.getModule('eventEmitter'); }); it("if Overlay's \"_showContent\" method invokes external API", function () { return (0, tslib_1.__awaiter)(void 0, 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.SRC_SET, })]; case 1: _a.sent(); (0, chai_1.expect)(loaderHideSpy.called).to.be.true; (0, chai_1.expect)(disableShowingContentSpy.called).to.be.true; return [2 /*return*/]; } }); }); }); }); describe('instance callbacks to controls', function () { beforeEach(function () { overlay = testkit.getModule('overlay'); eventEmitter = testkit.getModule('eventEmitter'); eventEmitterSpy = sinon.spy(eventEmitter, 'emitAsync'); }); afterEach(function () { eventEmitter.emitAsync.restore(); }); it('should emit ui event on play', function () { var callback = sinon.stub(overlay._engine, 'play'); overlay._playVideo(); (0, chai_1.expect)(callback.called).to.be.true; (0, chai_1.expect)(eventEmitterSpy.calledWith(constants_1.UIEvent.PLAY_OVERLAY_CLICK)).to.be.true; overlay._engine.play.restore(); }); }); describe('instance', function () { beforeEach(function () { overlay = testkit.getModule('overlay'); eventEmitter = testkit.getModule('eventEmitter'); }); it('should react on video playback state changed on play', function () { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var callback, hideSpy; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: callback = sinon.spy(overlay, '_updatePlayingState'); hideSpy = sinon.spy(overlay, '_hideContent'); overlay._bindEvents(); return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, { nextState: constants_1.EngineState.PLAY_REQUESTED, })]; case 1: _a.sent(); (0, chai_1.expect)(callback.called).to.be.true; (0, chai_1.expect)(hideSpy.called).to.be.true; return [2 /*return*/]; } }); }); }); it('should react on video playback state changed on end', function () { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var callback, showSpy; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: callback = sinon.spy(overlay, '_updatePlayingState'); showSpy = sinon.spy(overlay, '_showContent'); overlay._bindEvents(); return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, { nextState: constants_1.EngineState.ENDED, })]; case 1: _a.sent(); (0, chai_1.expect)(callback.called).to.be.true; (0, chai_1.expect)(showSpy.called).to.be.true; return [2 /*return*/]; } }); }); }); }); }); //# sourceMappingURL=overlay.spec.js.map