UNPKG

playable

Version:

Video player based on HTML5Video

117 lines 5.54 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 chrome_1 = (0, tslib_1.__importDefault)(require("./chrome")); var safari_1 = (0, tslib_1.__importDefault)(require("./safari")); var picture_in_picture_1 = (0, tslib_1.__importDefault)(require("./picture-in-picture")); var testkit_1 = (0, tslib_1.__importStar)(require("../../testkit")); var constants_1 = require("../../constants"); var mockedPictureInPictureHelper = { isInPictureInPicture: false, isEnabled: true, request: sinon.spy(), exit: sinon.spy(), destroy: sinon.spy(), reset: function () { this.isInFullScreen = false; this.isEnabled = true; this.request.resetHistory(); this.exit.resetHistory(); this.destroy.resetHistory(); }, }; describe('PictureInPicture', function () { var testkit; var pictureInPicture; var eventEmitter; beforeEach(function () { testkit = (0, testkit_1.default)(); testkit.registerModule('pictureInPicture', picture_in_picture_1.default); eventEmitter = testkit.getModule('eventEmitter'); pictureInPicture = testkit.getModule('pictureInPicture'); }); describe('chosen helper', function () { afterEach(function () { (0, testkit_1.resetProperty)(navigator, 'userAgent'); }); it('should be for desktop if not on iOS', function () { (0, testkit_1.setProperty)(navigator, 'userAgent', 'chrome'); pictureInPicture = testkit.getModule('pictureInPicture'); (0, chai_1.expect)(pictureInPicture._helper instanceof chrome_1.default).to.be .true; }); it('should be for iPhone', function () { (0, testkit_1.setProperty)(navigator, 'userAgent', 'safari'); pictureInPicture = testkit.getModule('pictureInPicture'); (0, chai_1.expect)(pictureInPicture._helper instanceof safari_1.default).to.be .true; }); }); describe('after helper chosen', function () { beforeEach(function () { pictureInPicture._helper = mockedPictureInPictureHelper; }); afterEach(function () { mockedPictureInPictureHelper.reset(); }); describe('enable state', function () { it('should be based on helper state and config', function () { (0, chai_1.expect)(pictureInPicture.isEnabled).to.be.true; mockedPictureInPictureHelper.isEnabled = false; (0, chai_1.expect)(pictureInPicture.isEnabled).to.be.false; }); it('should return false in disabled flag passed in config', function () { mockedPictureInPictureHelper.isEnabled = true; pictureInPicture._isEnabled = false; (0, chai_1.expect)(pictureInPicture.isEnabled).to.be.false; }); }); describe('full screen state', function () { it('should return state of helper', function () { mockedPictureInPictureHelper.isInPictureInPicture = true; (0, chai_1.expect)(pictureInPicture.isInPictureInPicture).to.be.true; }); it('should return false if disabled', function () { mockedPictureInPictureHelper.isEnabled = false; mockedPictureInPictureHelper.isInPictureInPicture = true; (0, chai_1.expect)(pictureInPicture.isInPictureInPicture).to.be.false; }); }); describe('method for entering full screen', function () { it("should call helper's method for request full screen", function () { pictureInPicture.enterPictureInPicture(); (0, chai_1.expect)(mockedPictureInPictureHelper.request.called).to.be.true; }); it('should do nothing if full screen is not enable', function () { mockedPictureInPictureHelper.isEnabled = false; pictureInPicture.enterPictureInPicture(); (0, chai_1.expect)(mockedPictureInPictureHelper.request.called).to.be.false; }); }); describe('method for exiting full screen', function () { it("should call helper's method for request full screen", function () { pictureInPicture.exitPictureInPicture(); (0, chai_1.expect)(mockedPictureInPictureHelper.exit.called).to.be.true; }); it('should do nothing if full screen is not enable', function () { mockedPictureInPictureHelper.isEnabled = false; pictureInPicture.exitPictureInPicture(); (0, chai_1.expect)(mockedPictureInPictureHelper.exit.called).to.be.false; }); }); describe('due to reaction on fullscreen change', function () { it('should trigger proper event', function () { var spy = sinon.spy(eventEmitter, 'emitAsync'); mockedPictureInPictureHelper.isInPictureInPicture = true; pictureInPicture._onChange(); (0, chai_1.expect)(spy.calledWith(constants_1.UIEvent.PICTURE_IN_PICTURE_STATUS_CHANGE)).to.be .true; eventEmitter.emitAsync.restore(); }); }); }); }); //# sourceMappingURL=picture-in-picture.spec.js.map