UNPKG

playable

Version:

Video player based on HTML5Video

128 lines 5.97 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 desktop_1 = (0, tslib_1.__importDefault)(require("./desktop")); var testkit_1 = require("../../testkit"); describe('DesktopFullScreen', function () { var callback = sinon.spy(); var element; var fullScreen; var fullScreenFn = { requestFullscreen: 'requestFullscreen', exitFullscreen: 'exitFullscreen', fullscreenElement: 'fullscreenElement', fullscreenEnabled: 'fullscreenEnabled', fullscreenchange: 'fullscreenchange', fullscreenerror: 'fullscreenerror', }; beforeEach(function () { element = document.createElement('div'); fullScreen = new desktop_1.default(element, callback); fullScreen._fullscreenFn = fullScreenFn; }); afterEach(function () { callback.resetHistory(); }); describe('enable state', function () { it('should return true in native state is true', function () { document[fullScreenFn.fullscreenEnabled] = true; (0, chai_1.expect)(fullScreen.isEnabled).to.be.true; }); it('should return false in native state is false', function () { document[fullScreenFn.fullscreenEnabled] = false; (0, chai_1.expect)(fullScreen.isEnabled).to.be.false; }); }); describe('full screen state', function () { it('should return true in native state is true', function () { document[fullScreenFn.fullscreenElement] = true; (0, chai_1.expect)(fullScreen.isInFullScreen).to.be.true; }); it('should return false in native state is false', function () { document[fullScreenFn.fullscreenElement] = false; (0, chai_1.expect)(fullScreen.isInFullScreen).to.be.false; }); }); describe('method for entering full screen', function () { describe('with usage of native method', function () { describe('if it enabled', function () { beforeEach(function () { document[fullScreenFn.fullscreenEnabled] = true; }); describe('on Safari 5.1', function () { beforeEach(function () { element[fullScreenFn.requestFullscreen] = sinon.spy(); (0, testkit_1.setProperty)(navigator, 'userAgent', '5.1 Safari'); }); afterEach(function () { (0, testkit_1.resetProperty)(navigator, 'userAgent'); }); it('should call it without arguments', function () { fullScreen.request(); (0, chai_1.expect)(element[fullScreenFn.requestFullscreen].calledWithExactly()) .to.be.true; }); }); describe('on not Safari 5.1', function () { beforeEach(function () { element[fullScreenFn.requestFullscreen] = sinon.spy(); }); it('should call it with true if ALLOW_KEYBOARD_INPUT is true', function () { Element.ALLOW_KEYBOARD_INPUT = true; fullScreen.request(); (0, chai_1.expect)(element[fullScreenFn.requestFullscreen].calledWithExactly(true)).to.be.true; }); it('should call it with false if ALLOW_KEYBOARD_INPUT is false', function () { Element.ALLOW_KEYBOARD_INPUT = false; fullScreen.request(); (0, chai_1.expect)(element[fullScreenFn.requestFullscreen].calledWithExactly(false)).to.be.true; }); }); }); describe('if it disabled', function () { beforeEach(function () { document[fullScreenFn.fullscreenEnabled] = false; element[fullScreenFn.requestFullscreen] = sinon.spy(); }); it('should not call it', function () { fullScreen.request(); (0, chai_1.expect)(element[fullScreenFn.requestFullscreen].called).to.be.false; }); }); }); }); describe('method for exit full screen', function () { it('should use native method', function () { document[fullScreenFn.fullscreenEnabled] = true; document[fullScreenFn.exitFullscreen] = sinon.spy(); fullScreen.exit(); (0, chai_1.expect)(document[fullScreenFn.exitFullscreen].called).to.be.true; }); it('should do nothing if not enabled', function () { document[fullScreenFn.fullscreenEnabled] = false; document[fullScreenFn.exitFullscreen] = sinon.spy(); fullScreen.exit(); (0, chai_1.expect)(document[fullScreenFn.exitFullscreen].called).to.be.false; }); }); describe('due to reaction on native full screen change', function () { it('should call callback', function () { var changeEvent = new Event(fullScreenFn.fullscreenchange); document.dispatchEvent(changeEvent); (0, chai_1.expect)(callback.called).to.be.true; }); }); describe('destroy method', function () { it('should clear on event listeners', function () { var changeEvent = new Event(fullScreenFn.fullscreenchange); document[fullScreenFn.fullscreenEnabled] = true; fullScreen.destroy(); element.dispatchEvent(changeEvent); (0, chai_1.expect)(callback.called).to.be.false; }); }); }); //# sourceMappingURL=desktop.spec.js.map