diff --git a/karma.conf.js b/karma.conf.js index 6b4f6df95..2a3ff9171 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,6 +18,14 @@ module.exports = function (config) { { pattern: 'tests/index.js', watched: false + }, + { + pattern: 'tests/assets/mov_bbb.mp4', + included: false + }, + { + pattern: 'tests/assets/audios.mp4', + included: false } ], diff --git a/src/common/ads/prebid-manager.ts b/src/common/ads/prebid-manager.ts index 1282f4892..97bfaceed 100644 --- a/src/common/ads/prebid-manager.ts +++ b/src/common/ads/prebid-manager.ts @@ -1,6 +1,6 @@ import { getLogger, Utils } from '@playkit-js/playkit-js'; import { KPAdPrebidConfig, KPPrebidConfig } from '../../types/ads/prebid-config'; -import { DefferedPromise } from '../../types/utils/deffered-promise'; +import { DeferredPromise } from '../../types/utils/deferred-promise'; const AD_REQUEST_TIMEOUT = 4000; @@ -36,7 +36,7 @@ class PrebidManager { * @private * @memberof PrebidManager */ - private _loadPromise: DefferedPromise; + private _loadPromise: DeferredPromise; constructor(config?: KPPrebidConfig) { this._loadPromise = Utils.Object.defer(); diff --git a/src/types/utils/deffered-promise.ts b/src/types/utils/deferred-promise.ts similarity index 83% rename from src/types/utils/deffered-promise.ts rename to src/types/utils/deferred-promise.ts index e1c448871..3d874178e 100644 --- a/src/types/utils/deffered-promise.ts +++ b/src/types/utils/deferred-promise.ts @@ -1,4 +1,4 @@ -export type DefferedPromise = { +export type DeferredPromise = { resolve: (value?: any | PromiseLike) => void; reject: (reason?: any) => void; catch: (param: () => any) => void; diff --git a/tests/e2e/common/ads/ads-controller.spec.ts b/tests/e2e/common/ads/ads-controller.spec.ts new file mode 100644 index 000000000..9e0b01bc4 --- /dev/null +++ b/tests/e2e/common/ads/ads-controller.spec.ts @@ -0,0 +1,1003 @@ +// import SourcesConfig from '../../configs/sources.json'; +// import {getConfigStructure} from '../../../utils/test-utils'; +// import {KalturaPlayer as Player} from '../../../../src/kaltura-player'; +// import {CustomEventType, AdEventType, Error, FakeEvent, Utils} from '@playkit-js/playkit-js'; +// import * as sinon from 'sinon'; +// +// describe('AdsController', () => { +// let config, player, sandbox; +// +// before(() => { +// config = getConfigStructure(); +// }); +// +// beforeEach(() => { +// player = new Player(config); +// sandbox = sinon.createSandbox(); +// }); +// +// afterEach(() => { +// player.destroy(); +// sandbox.restore(); +// }); +// +// describe('advertising config', () => { +// it('Should fire AD_MANIFEST_LOADED with the uniq and valid breaks only', done => { +// const fakeCtrl = { +// playAdNow: () => {} +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.addEventListener(AdEventType.AD_MANIFEST_LOADED, event => { +// try { +// event.payload.adBreaksPosition.should.deep.equal(['0%', 0, 2, '50%', 1, -1, '100%']); +// done(); +// } catch (e) { +// done(e); +// } +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {percentage: 0, ads: [{}]}, +// {position: 0, ads: [{}]}, +// {position: '1', ads: [{}]}, +// {position: 1, ads: []}, +// {position: 2, ads: [{}]}, +// {position: 2, ads: [{}]}, +// {percentage: 50, ads: [{}]}, +// {position: 1, ads: [{}]}, +// {position: -1, ads: [{}]}, +// {percentage: 100, ads: [{}]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// }); +// +// it('Should not fire AD_MANIFEST_LOADED for empty list', done => { +// const fakeCtrl = { +// playAdNow: () => {} +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.addEventListener(AdEventType.AD_MANIFEST_LOADED, () => { +// done(new Error('Should not fireAD_MANIFEST_LOADED')); +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: '1', ads: [{}]}, +// {position: 1, ads: []} +// ] +// } +// }); +// setTimeout(done); +// }); +// +// it('Should play pre-roll, 2 mid-rolls and post-roll by position', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[2]}, +// {position: -1, ads: adBreaks[3]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should play pre-roll, 2 mid-rolls and post-roll by percentage', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {percentage: 0, ads: adBreaks[0]}, +// {percentage: 25, ads: adBreaks[1]}, +// {percentage: 50, ads: adBreaks[2]}, +// {percentage: 100, ads: adBreaks[3]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should play 5 mid-rolls by every', done => { +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// adBreakIndex++; +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal([{url: ['MID_ROLL']}]); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{every: 1, ads: [{url: ['MID_ROLL']}]}] +// } +// }); +// player.addEventListener(CustomEventType.PLAYBACK_ENDED, () => { +// try { +// adBreakIndex.should.equal(5); +// player._adsController._configAdBreaks.length.should.equal(5); +// done(); +// } catch (e) { +// done(e); +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should play pre-roll, mid-rolls and post-roll by mix position, percentage and every', done => { +// const adBreaks = [ +// [{url: ['PRE_ROLL_1']}, {url: ['PRE_ROLL_1']}], +// [{url: ['MID_ROLL_1']}], +// [{url: ['MID_ROLL_2']}], +// [{url: ['MID_ROLL_3']}], +// [{url: ['MID_ROLL_3']}], +// [{url: ['POST_ROLL']}] +// ]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 0, ads: [adBreaks[0][0]]}, +// {percentage: 0, ads: [adBreaks[0][1]]}, +// {percentage: 25, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[2]}, +// {every: 2.5, ads: adBreaks[3]}, +// {percentage: 100, ads: adBreaks[5]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should skip the first mid-roll (snap-back)', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[1]}, +// {position: -1, ads: adBreaks[2]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.currentTime = 2; +// }); +// player.play(); +// }); +// +// it('Should fire PLAYBACK_ENDED when snap-back after post-roll finished', done => { +// const adBreaks = [[{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 1; +// const fakeCtrl = { +// done: true, +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// setTimeout(() => player.dispatchEvent(new FakeEvent(AdEventType.ADS_COMPLETED))); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 1, ads: adBreaks[0]}, +// {position: 2, ads: adBreaks[1]}, +// {position: -1, ads: adBreaks[2]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.PLAYBACK_ENDED, () => { +// done(); +// }); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.currentTime = 2; +// }); +// player.play(); +// }); +// +// it('Should fire PLAYBACK_ENDED when snap-back after post-roll failed', done => { +// const adBreaks = [[{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 1; +// const fakeCtrl = { +// done: true, +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// player._adsController._adPlayed = true; +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// setTimeout(() => player.dispatchEvent(new FakeEvent(AdEventType.AD_ERROR, {severity: 2}))); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 1, ads: adBreaks[0]}, +// {position: 2, ads: adBreaks[1]}, +// {position: -1, ads: adBreaks[2]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.PLAYBACK_ENDED, () => { +// done(); +// }); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.currentTime = 2; +// }); +// player.play(); +// }); +// +// it('Should not play skipped mid-roll (snap-back) on replay', done => { +// const adBreaks = [[{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}]]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[1]); +// } catch (e) { +// done(new Error('Should not play skipped mid-roll')); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 2, ads: adBreaks[0]}, +// {position: 3, ads: adBreaks[1]} +// ] +// } +// }); +// let firstPlay = true; +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.PLAYBACK_ENDED, () => { +// if (firstPlay) { +// player.play(); +// firstPlay = false; +// } else { +// done(); +// } +// }); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.currentTime = 4; +// }); +// player.play(); +// }); +// +// it('Should play the in reverse (snap-back)', done => { +// const adBreaks = [ +// [{url: ['PRE_ROLL']}], +// [{url: ['MID_ROLL_3']}], +// [{url: ['MID_ROLL_2']}], +// [{url: ['MID_ROLL_1']}], +// [{url: ['MID_ROLL_4']}], +// [{url: ['POST_ROLL']}] +// ]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === 2) { +// player.currentTime = 2.5; +// } +// if (adBreakIndex === 3) { +// player.currentTime = 0; +// } +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[3]}, +// {position: 2, ads: adBreaks[2]}, +// {position: 3, ads: adBreaks[1]}, +// {position: 4, ads: adBreaks[4]}, +// {position: -1, ads: adBreaks[5]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.currentTime = 3; +// }); +// player.play(); +// }); +// +// it('Should skip the pre-roll and first mid-roll as playback.startTime configured', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 2; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// playback: { +// startTime: 1 +// }, +// advertising: { +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[2]}, +// {position: -1, ads: adBreaks[3]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should skip the pre-roll and first mid-roll as playAdsAfterTime configured', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 2; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// playAdsAfterTime: 1, +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[2]}, +// {position: -1, ads: adBreaks[3]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should not skip even playback.startTime since playAdsAfterTime configured', done => { +// const adBreaks = [[{url: ['PRE_ROLL']}], [{url: ['MID_ROLL_1']}], [{url: ['MID_ROLL_2']}], [{url: ['POST_ROLL']}]]; +// let adBreakIndex = 0; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[adBreakIndex]); +// adBreakIndex++; +// if (adBreakIndex === adBreaks.length) { +// done(); +// } +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// playback: { +// startTime: 1 +// }, +// advertising: { +// playAdsAfterTime: -1, +// adBreaks: [ +// {position: 0, ads: adBreaks[0]}, +// {position: 1, ads: adBreaks[1]}, +// {position: 2, ads: adBreaks[2]}, +// {position: -1, ads: adBreaks[3]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should unify 2 pre-rolls', done => { +// const adBreaks = [[{url: ['PRE_ROLL_1']}, {url: ['PRE_ROLL_2']}]]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[0]); +// done(); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 0, ads: [adBreaks[0][0]]}, +// {position: 0, ads: [adBreaks[0][1]]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should unify 2 mid-rolls', done => { +// const adBreaks = [[{url: ['MID_ROLL_1']}, {url: ['MID_ROLL_2']}]]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[0]); +// done(); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 2, ads: [adBreaks[0][0]]}, +// {position: 2, ads: [adBreaks[0][1]]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should unify 2 post-rolls', done => { +// const adBreaks = [[{url: ['POST_ROLL_1']}, {url: ['POST_ROLL_2']}]]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// player._adsController && (player._adsController._adIsLoading = false); +// ads.should.deep.equal(adBreaks[0]); +// done(); +// } catch (e) { +// done(e); +// } +// }, +// onPlaybackEnded: () => { +// return Promise.resolve(); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: -1, ads: [adBreaks[0][0]]}, +// {position: -1, ads: [adBreaks[0][1]]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should ignore ad break positioned out of the duration', done => { +// const fakeCtrl = { +// playAdNow: () => { +// done(new Error('Should not play an out of range ad break')); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 10, ads: [{url: ['MID_ROLL_1']}]}] +// } +// }); +// player.addEventListener(CustomEventType.PLAYBACK_ENDED, () => { +// try { +// player._adsController._configAdBreaks.every(adBreak => adBreak.played).should.be.true; +// done(); +// } catch (e) { +// done(e); +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// +// it('Should validate only one time is configured', done => { +// const fakeCtrl = { +// playAdNow: () => {} +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.addEventListener(AdEventType.AD_MANIFEST_LOADED, event => { +// try { +// event.payload.adBreaksPosition.should.deep.equal([10, '60%', '5s', 0.5, 1, '80%', 2]); +// } catch (e) { +// done(e); +// } +// }); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// try { +// (!!player._adsController._configAdBreaks[0].position).should.be.true; +// (!!player._adsController._configAdBreaks[0].percentage).should.be.false; +// (!!player._adsController._configAdBreaks[0].every).should.be.false; +// +// (!!player._adsController._configAdBreaks[1].position).should.be.true; +// (!!player._adsController._configAdBreaks[1].percentage).should.be.false; +// (!!player._adsController._configAdBreaks[1].every).should.be.false; +// +// (!!player._adsController._configAdBreaks[2].position).should.be.true; +// (!!player._adsController._configAdBreaks[2].percentage).should.be.false; +// (!!player._adsController._configAdBreaks[2].every).should.be.false; +// +// (!!player._adsController._configAdBreaks[3].position).should.be.true; +// (!!player._adsController._configAdBreaks[3].percentage).should.be.true; +// (!!player._adsController._configAdBreaks[3].every).should.be.false; +// +// (!!player._adsController._configAdBreaks[4].position).should.be.true; +// (!!player._adsController._configAdBreaks[4].percentage).should.be.true; +// (!!player._adsController._configAdBreaks[4].every).should.be.false; +// +// (!!player._adsController._configAdBreaks[5].position).should.be.true; +// (!!player._adsController._configAdBreaks[5].percentage).should.be.false; +// (!!player._adsController._configAdBreaks[5].every).should.be.true; +// +// (!!player._adsController._configAdBreaks[6].position).should.be.true; +// (!!player._adsController._configAdBreaks[6].percentage).should.be.false; +// (!!player._adsController._configAdBreaks[6].every).should.be.false; +// done(); +// } catch (e) { +// done(e); +// } +// }); +// player.configure({ +// advertising: { +// adBreaks: [ +// {position: 10, ads: [{url: ['']}]}, +// {percentage: 60, ads: [{url: ['']}]}, +// {every: 5, ads: [{url: ['']}]}, +// {position: 0.5, percentage: 50, ads: [{url: ['']}]}, +// {position: 1, every: 15, ads: [{url: ['']}]}, +// {percentage: 80, every: 10, ads: [{url: ['']}]}, +// {position: 2, percentage: 60, every: 20, ads: [{url: ['']}]} +// ] +// } +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.play(); +// }); +// }); +// +// describe('playAdNow', () => { +// it('Should play pre-roll', done => { +// const preroll = [{url: ['PRE_ROLL']}]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// ads.should.deep.equal(preroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.ads.playAdNow(preroll); +// }); +// +// it('Should play mid-roll', done => { +// const midroll = [{url: ['MID_ROLL']}]; +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// ads.should.deep.equal(midroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player.ads.playAdNow(midroll); +// }); +// player.play(); +// }); +// +// it('Should not play mid-roll while ad break', done => { +// const midroll = [{url: ['MID_ROLL']}]; +// const fakeCtrl = { +// playAdNow: () => { +// done(new Error('Should not play ad while ad break')); +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.setMedia({sources: SourcesConfig.Mp4}); +// player.addEventListener(CustomEventType.FIRST_PLAY, () => { +// player._adsController._adBreak = true; +// player.ads.playAdNow(midroll); +// setTimeout(done); +// }); +// player.play(); +// }); +// }); +// +// describe('Prebid', () => { +// const preroll = [{url: ['PREBID_PRE_ROLL', 'PRE_ROLL'], prebid: {}}]; +// const midroll = [{url: ['PREBID_MID_ROLL', 'MID_ROLL'], prebid: {}}]; +// +// before(() => { +// config = Utils.Object.mergeDeep({}, getConfigStructure(), { +// advertising: { +// prebid: {libUrl: 'dummyUrl'} +// }, +// plugins: { +// ima: {} +// } +// }); +// }); +// +// it('Should play Prebid as pre-roll', done => { +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// (player.currentTime === 0).should.be.true; +// ads.should.deep.equal(preroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 0, ads: [{url: ['PRE_ROLL'], prebid: {}}]}] +// } +// }); +// sandbox.stub(player._adsController._prebidManager, '_isPrebidSDKLibLoaded').callsFake(function () { +// return true; +// }); +// sandbox.stub(player._adsController._prebidManager, 'load').callsFake(function () { +// return Promise.resolve([{vastUrl: 'PREBID_PRE_ROLL'}]); +// }); +// player.setMedia({sources: SourcesConfig.Mp4, session: {}, plugins: {}}); +// player.play(); +// }); +// +// it('Should Prebid delay pre-roll until Prebid loaded', done => { +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// (player.currentTime === 0).should.be.true; +// ads.should.deep.equal(preroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 0, ads: [{url: ['PRE_ROLL'], prebid: {}}]}] +// } +// }); +// sandbox.stub(player._adsController._prebidManager, '_isPrebidSDKLibLoaded').callsFake(function () { +// return true; +// }); +// sandbox.stub(player._adsController._prebidManager, '_loadPrebidSDKLib').callsFake(function () { +// return new Promise(resolve => { +// setTimeout(() => { +// resolve([{vastUrl: 'PREBID_PRE_ROLL'}]); +// }, 3000); +// }); +// }); +// sandbox.stub(player._adsController._prebidManager, 'load').callsFake(function () { +// return Promise.resolve([{vastUrl: 'PREBID_PRE_ROLL'}]); +// }); +// player.setMedia({sources: SourcesConfig.Mp4, session: {}, plugins: {}}); +// player.play(); +// }); +// +// it('Should Prebid delay pre-roll until Prebid ad loaded', done => { +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// (player.currentTime === 0).should.be.true; +// ads.should.deep.equal(preroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 0, ads: [{url: ['PRE_ROLL'], prebid: {}}]}] +// } +// }); +// sandbox.stub(player._adsController._prebidManager, '_isPrebidSDKLibLoaded').callsFake(function () { +// return true; +// }); +// sandbox.stub(player._adsController._prebidManager, 'load').callsFake(function () { +// return new Promise(resolve => { +// setTimeout(() => { +// resolve([{vastUrl: 'PREBID_PRE_ROLL'}]); +// }, 3000); +// }); +// }); +// player.setMedia({sources: SourcesConfig.Mp4, session: {}, plugins: {}}); +// player.play(); +// }); +// +// it('Should play Prebid as mid-roll', done => { +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// (Math.floor(player.currentTime) === 2).should.be.true; +// ads.should.deep.equal(midroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 2, ads: [{url: ['MID_ROLL'], prebid: {}}]}] +// } +// }); +// sandbox.stub(player._adsController._prebidManager, '_isPrebidSDKLibLoaded').callsFake(function () { +// return true; +// }); +// sandbox.stub(player._adsController._prebidManager, 'load').callsFake(function () { +// return Promise.resolve([{vastUrl: 'PREBID_MID_ROLL'}]); +// }); +// player.setMedia({sources: SourcesConfig.Mp4, session: {}, plugins: {}}); +// player.play(); +// }); +// +// it('Should delay play Prebid mid-roll until it loaded', done => { +// const fakeCtrl = { +// playAdNow: ads => { +// try { +// (Math.floor(player.currentTime) > 2).should.be.true; +// ads.should.deep.equal(midroll); +// done(); +// } catch (e) { +// done(e); +// } +// } +// }; +// sandbox.stub(player._controllerProvider, 'getAdsControllers').callsFake(function () { +// return [fakeCtrl]; +// }); +// player.configure({ +// advertising: { +// adBreaks: [{position: 2, ads: [{url: ['MID_ROLL'], prebid: {}}]}] +// } +// }); +// sandbox.stub(player._adsController._prebidManager, '_isPrebidSDKLibLoaded').callsFake(function () { +// return true; +// }); +// sandbox.stub(player._adsController._prebidManager, 'load').callsFake(function () { +// return new Promise(resolve => { +// setTimeout(() => { +// resolve([{vastUrl: 'PREBID_MID_ROLL'}]); +// }, 5000); +// }); +// }); +// player.setMedia({sources: SourcesConfig.Mp4, session: {}, plugins: {}}); +// player.play(); +// }); +// }); +// }); diff --git a/tests/e2e/common/cuepoints/cuepoint-manager.spec.js b/tests/e2e/common/cuepoints/cuepoint-manager.spec.js new file mode 100644 index 000000000..902d6db43 --- /dev/null +++ b/tests/e2e/common/cuepoints/cuepoint-manager.spec.js @@ -0,0 +1,68 @@ +import {expect} from 'chai'; +import SourcesConfig from '../../configs/sources.json'; +import {getConfigStructure} from '../../../utils/test-utils'; +import {KalturaPlayer as Player} from '../../../../src/kaltura-player'; +import {CuePointManager} from '../../../../src/common/cuepoint/cuepoint-manager'; + +describe('CuePointManager', () => { + let config, player, sandbox; + + before(() => { + config = getConfigStructure(); + }); + + beforeEach(() => { + player = new Player(config); + sandbox = sinon.createSandbox(); + }); + + afterEach(() => { + player.destroy(); + sandbox.restore(); + }); + + it('should get cue-point manager', function () { + expect(player.cuePointManager).instanceOf(CuePointManager); + }); + + it('should create and add text-track', function () { + player.setMedia({sources: SourcesConfig.Mp4}); + expect(player.cuePointManager._textTrack).to.eql(null); + player.cuePointManager.addCuePoints([]); + player.ready().then(() => { + expect(player.cuePointManager._textTrack).instanceOf(TextTrack); + }); + }); + + it('should add/get/remove/clear-all cue points', function () { + const cuePoints = [ + { + id: 'test-id-1', + startTime: 1, + endTime: 6 + }, + { + id: 'test-id-2', + startTime: 6, + endTime: 10 + }, + { + id: 'test-id-3', + startTime: 10, + endTime: 15 + } + ]; + player.setMedia({sources: SourcesConfig.Mp4}); + player.ready().then(() => { + expect(player.cuePointManager.getAllCuePoints().length).eql(0); + player.cuePointManager.addCuePoints(cuePoints); + expect(player.cuePointManager.getAllCuePoints().length).eql(3); + const cuePoint = player.cuePointManager._getTextTrackCueById('test-id-1'); + expect(cuePoint.id).to.eql('test-id-1'); + player.cuePointManager._removeTextTrackCue(cuePoint); + expect(player.cuePointManager.getAllCuePoints().length).eql(2); + player.cuePointManager._clearAllTextTrackCues(); + expect(player.cuePointManager.getAllCuePoints().length).eql(0); + }); + }); +}); diff --git a/tests/e2e/common/playlist/playlist-manager.spec.js b/tests/e2e/common/playlist/playlist-manager.spec.js new file mode 100644 index 000000000..825e6335a --- /dev/null +++ b/tests/e2e/common/playlist/playlist-manager.spec.js @@ -0,0 +1,671 @@ +import {KalturaPlayer} from '../../../../src/kaltura-player'; +import {PlaylistManager} from '../../../../src/common/playlist/playlist-manager'; +import * as MediaMockData from '../../mock-data/media'; +import * as PlaylistMockData from '../../mock-data/playlist'; +import {FakeEvent} from '@playkit-js/playkit-js'; +import {PlaylistEventType} from '../../../../src/common/playlist/playlist-event-type'; +import {PluginManager} from '../../../../src/common/plugins'; +import ColorsPlugin from '../plugin/test-plugins/colors-plugin'; + +describe('PlaylistManager', function () { + let kalturaPlayer, playlistManager, sandbox; + const config = { + ui: {}, + plugins: {}, + advertising: { + adBreaks: [] + }, + provider: {}, + playback: { + autoplay: true + } + }; + + before(function () { + sandbox = sinon.createSandbox(); + kalturaPlayer = new KalturaPlayer(config); + }); + + beforeEach(function () { + playlistManager = new PlaylistManager(kalturaPlayer, config); + }); + + afterEach(function () { + playlistManager.reset(); + playlistManager = null; + kalturaPlayer._eventManager.removeAll(); + kalturaPlayer.reset(); + }); + + describe('configure', function () { + it('should create a playlist manager with default values', function () { + playlistManager._player.should.exist; + playlistManager._eventManager.should.exist; + playlistManager._playlist.should.exist; + playlistManager._options.autoContinue.should.be.true; + playlistManager._options.loop.should.be.false; + playlistManager._countdown.duration.should.equal(10); + playlistManager._countdown.showing.should.be.true; + playlistManager._playerOptions.should.exist; + playlistManager._mediaInfoList.length.should.equal(0); + }); + + it('should do nothing for empty config', function () { + playlistManager.configure(); + }); + + it('should update config', function () { + playlistManager.configure({ + id: '1234', + options: {autoContinue: false}, + countdown: {duration: 20, showing: false, timeToShow: 50} + }); + playlistManager._playlist.id.should.equal('1234'); + playlistManager._options.autoContinue.should.be.false; + playlistManager._countdown.duration.should.equal(20); + playlistManager._countdown.showing.should.be.false; + playlistManager._countdown.timeToShow.should.equal(50); + }); + + it('should load playlist by config and fire event', function () { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_LOADED, event => { + event.payload.playlist.id.should.equal('b1234'); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should not load playlist by config and fire event is no items', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_LOADED, () => { + done(new Error('fail')); + }); + playlistManager.configure(); + done(); + }); + + it('should not load playlist by config and fire event is no sources', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_LOADED, () => { + done(new Error('fail')); + }); + playlistManager.configure({items: [{}]}); + done(); + }); + + it('should update the media info list', function () { + playlistManager.configure(PlaylistMockData.playlistByConfig, {entries: ['abc', {entryId: '123'}]}); + playlistManager._mediaInfoList.length.should.equal(3); + playlistManager._mediaInfoList[0].entryId.should.equal('id1'); + playlistManager._mediaInfoList[1].entryId.should.equal('123'); + playlistManager._mediaInfoList[2].entryId.should.equal('id3'); + }); + + it('should play the first item', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + done(); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should play next on ended when auto continue is true', function (done) { + let eventCounter = 0; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + eventCounter++; + if (eventCounter === 2) { + done(); + } + playlistManager._options.autoContinue = true; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should play next on ended when loop is true', function (done) { + let eventCounter = 0; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + eventCounter++; + if (eventCounter === 2) { + done(); + } + playlistManager._options.autoContinue = false; + playlistManager._options.loop = true; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should not play next on ended when auto continue and loop is false', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + done(); + playlistManager._options.autoContinue = false; + playlistManager._options.loop = false; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should not play next on ended when ui is enabled', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + done(); + playlistManager._options.autoContinue = true; + playlistManager._options.loop = true; + playlistManager._playerOptions.ui.disable = false; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should play next on ended when ui is enabled but countdown is hidden', function (done) { + let eventCounter = 0; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + eventCounter++; + if (eventCounter === 2) { + done(); + } + playlistManager._options.autoContinue = true; + playlistManager._options.loop = true; + playlistManager._playerOptions.ui.disable = false; + playlistManager._countdown.showing = false; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should fire playlist ended event', function (done) { + let onItemChanged = () => { + playlistManager._options.autoContinue = true; + playlistManager._options.loop = true; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ENDED, () => { + kalturaPlayer._eventManager.unlisten(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + done(); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should play in loop when loop is true', function (done) { + let onItemChanged = () => { + playlistManager._options.autoContinue = false; + playlistManager._options.loop = true; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ENDED, () => { + kalturaPlayer._eventManager.unlisten(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, e => { + e.payload.index.should.equal(0); + done(); + }); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should not play in loop when loop is false', function (done) { + let onItemChanged = () => { + playlistManager._options.autoContinue = true; + playlistManager._options.loop = false; + playlistManager._playerOptions.ui.disable = true; + kalturaPlayer.dispatchEvent(new FakeEvent(kalturaPlayer.Event.Core.PLAYBACK_ENDED)); + }; + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ENDED, () => { + kalturaPlayer._eventManager.unlisten(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, onItemChanged); + done(); + kalturaPlayer._eventManager.listen(kalturaPlayer, kalturaPlayer.Event.Playlist.PLAYLIST_ITEM_CHANGED, () => { + done(new Error('fail')); + }); + }); + playlistManager.configure(PlaylistMockData.playlistByConfig); + }); + + it('should set the configured sources.options for all items', function () { + kalturaPlayer.configure({sources: {options: {forceRedirectExternalStreams: true, redirectExternalStreamsHandler: () => 1}}}); + playlistManager.configure({items: [{sources: {}}, {sources: {}}]}); + playlistManager.items.forEach(item => item.sources.options.forceRedirectExternalStreams.should.be.true); + playlistManager.items.forEach(item => (item.sources.options.redirectExternalStreamsHandler() === 1).should.be.true); + }); + + it('should prefer the item configuration before the sources.options', function () { + kalturaPlayer.configure({sources: {options: {forceRedirectExternalStreams: true, redirectExternalStreamsHandler: () => 1}}}); + playlistManager.configure({ + items: [{sources: {options: {forceRedirectExternalStreams: false}}}, {sources: {options: {redirectExternalStreamsHandler: () => 2}}}] + }); + playlistManager.items[0].sources.options.forceRedirectExternalStreams.should.be.false; + playlistManager.items[1].sources.options.forceRedirectExternalStreams.should.be.true; + (playlistManager.items[0].sources.options.redirectExternalStreamsHandler() === 1).should.be.true; + (playlistManager.items[1].sources.options.redirectExternalStreamsHandler() === 2).should.be.true; + }); + }); + + describe('load', function () { + it('should merge the playlist data and config', function () { + const playlistConfig = { + options: { + autoContinue: false + }, + countdown: { + timeToShow: 30, + duration: 20, + showing: false + }, + items: [ + { + config: { + countdown: { + timeToShow: 40, + duration: 5, + showing: true + } + } + }, + { + sources: { + hls: [{url: 'source_url'}], + poster: 'poster_url', + dvr: true + } + } + ] + }; + playlistManager.load(PlaylistMockData.playlistByID, playlistConfig, {entries: [{entryId: '123'}]}); + playlistManager._playlist.id.should.equal('0_wckoqjnn'); + playlistManager._playlist.metadata.name.should.equal('Playlist_VOD_Only'); + playlistManager._playlist.poster.should.equal('http://cdntesting.qa.mkaltura.com/p/1091/sp/0/thumbnail/entry_id/0_wckoqjnn/version/100162'); + playlistManager._playlist.items[0]._sources.id.should.equal('0_fu4ifhie'); + playlistManager._playlist.items[0]._config.countdown.timeToShow.should.be.equal(40); + playlistManager._playlist.items[0]._config.countdown.duration.should.be.equal(5); + playlistManager._playlist.items[0]._config.countdown.showing.should.be.true; + playlistManager._playlist.items[1]._sources.id.should.equal('0_15xrxwvo'); + playlistManager._playlist.items[1]._sources.hls[0].url.should.equal('source_url'); + playlistManager._playlist.items[1]._sources.poster.should.equal('poster_url'); + playlistManager._playlist.items[1]._sources.dvr.should.be.true; + (playlistManager._playlist.items[1]._config === undefined).should.be.true; + playlistManager._options.autoContinue.should.be.false; + playlistManager._countdown.timeToShow.should.be.equal(30); + playlistManager._countdown.duration.should.be.equal(20); + playlistManager._countdown.showing.should.be.false; + playlistManager._mediaInfoList[0].entryId.should.equal('123'); + }); + }); + + describe('reset', function () { + it('should reset but keep the previous config', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + hls: [{url: 'source_url'}], + poster: 'poster_url', + dvr: true + } + } + ], + options: {autoContinue: false}, + countdown: {duration: 20, showing: false, timeToShow: 50} + }); + playlistManager._playlist.id.should.equal('1234'); + playlistManager._playlist.items.length.should.equal(1); + playlistManager._mediaInfoList.length.should.equal(1); + playlistManager._options.autoContinue.should.be.false; + playlistManager._countdown.duration.should.equal(20); + playlistManager._countdown.showing.should.be.false; + playlistManager._countdown.timeToShow.should.equal(50); + playlistManager.reset(); + playlistManager._playlist.id.should.equal(''); + playlistManager._playlist.items.length.should.equal(0); + playlistManager._mediaInfoList.length.should.equal(0); + playlistManager._options.autoContinue.should.be.false; + playlistManager._countdown.duration.should.equal(20); + playlistManager._countdown.showing.should.be.false; + }); + }); + + describe('get next', function () { + it('should get the second item', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + playlistManager.next.sources.id.should.equal('id2'); + playlistManager.next.index.should.equal(1); + }); + + it('should get null when in the last item and loop is false', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + playlistManager.playNext(); + (playlistManager.next === null).should.be.true; + }); + + it('should get the first item when in the last item and loop is true', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ], + options: { + loop: true + } + }); + playlistManager.playNext(); + playlistManager.next.sources.id.should.equal('id1'); + playlistManager.next.index.should.equal(0); + }); + }); + + describe('get prev', function () { + it('should get the first item', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + playlistManager.playNext(); + playlistManager.prev.sources.id.should.equal('id1'); + playlistManager.prev.index.should.equal(0); + }); + + it('should get null when in the first item', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + (playlistManager.prev === null).should.be.true; + }); + }); + + describe('get current', function () { + it('should get the first item', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + playlistManager.current.sources.id.should.equal('id1'); + playlistManager.current.index.should.equal(0); + }); + + it('should get the second item', function () { + playlistManager.configure({ + id: '1234', + items: [ + { + sources: { + id: 'id1' + } + }, + { + sources: { + id: 'id2' + } + } + ] + }); + playlistManager.playNext(); + playlistManager.current.sources.id.should.equal('id2'); + playlistManager.current.index.should.equal(1); + }); + }); + + describe('playNext', function () { + before(function () { + sinon.stub(kalturaPlayer, 'loadMedia').callsFake(function ({entryId}) { + return Promise.resolve(MediaMockData.MediaConfig[entryId]); + }); + }); + + beforeEach(function () { + playlistManager.load(PlaylistMockData.playlistByEntryList); + }); + + after(function () { + sandbox.restore(); + kalturaPlayer.loadMedia.restore(); + }); + + it('should call playNext automatically once the playlist loaded', function (done) { + kalturaPlayer._eventManager.listen(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + done(); + }); + }); + + it.skip('should call playNext programmatically', function (done) { + let eventCounter = 0; + kalturaPlayer._eventManager.listen(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + if (eventCounter === 2) { + done(); + } + eventCounter++; + playlistManager.playNext(); + }); + }); + }); + + describe('playPrev', function () { + before(function () { + sinon.stub(kalturaPlayer, 'loadMedia').callsFake(function ({entryId}) { + return Promise.resolve(MediaMockData.MediaConfig[entryId]); + }); + }); + + beforeEach(function () { + playlistManager.load(PlaylistMockData.playlistByEntryList); + }); + + after(function () { + sandbox.restore(); + kalturaPlayer.loadMedia.restore(); + }); + + it('should call playPrev programmatically', function (done) { + let eventCounter = -1; + kalturaPlayer._eventManager.listen(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + eventCounter++; + switch (eventCounter) { + case 0: { + playlistManager.playNext(); + break; + } + case 1: { + playlistManager.playPrev(); + break; + } + case 2: { + done(); + } + } + }); + }); + }); + + describe('playItem', function () { + before(function () { + sinon.stub(kalturaPlayer, 'loadMedia').callsFake(function ({entryId}) { + return Promise.resolve(MediaMockData.MediaConfig[entryId]); + }); + }); + + beforeEach(function () { + playlistManager.load(PlaylistMockData.playlistByEntryList); + }); + + after(function () { + sandbox.restore(); + kalturaPlayer.loadMedia.restore(); + }); + + it('should call playItem programmatically', function (done) { + let eventCounter = -1; + kalturaPlayer._eventManager.listen(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + eventCounter++; + switch (eventCounter) { + case 0: { + playlistManager.playItem(1); + break; + } + case 1: { + playlistManager.playItem(0); + break; + } + case 2: { + done(); + } + } + }); + }); + }); + + describe('provider plugins', function () { + before(function () { + PluginManager.register('colors', ColorsPlugin); + sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function (info) { + const mediaConfig = MediaMockData.MediaConfig[info.entryId]; + return Promise.resolve(mediaConfig); + }); + }); + + beforeEach(function () { + kalturaPlayer.configure({ + plugins: { + colors: { + someProp1: 'app_prop1', + someProp2: '' + } + } + }); + playlistManager.load(PlaylistMockData.playlistByEntryListWithPlugins); + }); + + after(function () { + sandbox.restore(); + kalturaPlayer._provider.getMediaConfig.restore(); + }); + + it("should apply the app's plugin config before the provider's and reset the provider's on change media", function (done) { + kalturaPlayer._eventManager.listenOnce(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + try { + kalturaPlayer.config.plugins.colors.favouriteColor.should.equals('green'); + kalturaPlayer.config.plugins.colors.someProp1.should.equals('app_prop1'); + kalturaPlayer.config.plugins.colors.someProp2.should.equals(''); + kalturaPlayer._eventManager.listenOnce(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + try { + kalturaPlayer.config.plugins.colors.favouriteColor.should.equals('green'); + kalturaPlayer.config.plugins.colors.someProp1.should.equals('app_prop1'); + kalturaPlayer.config.plugins.colors.someProp2.should.equals('prop2'); + kalturaPlayer._eventManager.listenOnce(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + try { + kalturaPlayer.config.plugins.colors.favouriteColor.should.equals('green'); + kalturaPlayer.config.plugins.colors.someProp1.should.equals('app_prop1'); + kalturaPlayer.config.plugins.colors.someProp2.should.equals(''); + kalturaPlayer._eventManager.listenOnce(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + try { + kalturaPlayer.config.plugins.colors.favouriteColor.should.equals('green'); + kalturaPlayer.config.plugins.colors.someProp1.should.equals('app_prop1'); + kalturaPlayer.config.plugins.colors.someProp2.should.equals('prop2'); + kalturaPlayer._eventManager.listenOnce(kalturaPlayer, PlaylistEventType.PLAYLIST_ITEM_CHANGED, () => { + try { + kalturaPlayer.config.plugins.colors.favouriteColor.should.equals('green'); + kalturaPlayer.config.plugins.colors.someProp1.should.equals('app_prop1'); + kalturaPlayer.config.plugins.colors.someProp2.should.equals(''); + done(); + } catch (e) { + done(e); + } + }); + kalturaPlayer._reset = false; + playlistManager.playPrev(); + } catch (e) { + done(e); + } + }); + kalturaPlayer._reset = false; + playlistManager.playPrev(); + } catch (e) { + done(e); + } + }); + kalturaPlayer._reset = false; + playlistManager.playNext(); + } catch (e) { + done(e); + } + }); + kalturaPlayer._reset = false; + playlistManager.playNext(); + } catch (e) { + done(e); + } + }); + }); + }); +}); diff --git a/tests/e2e/common/plugin/base-plugin.spec.ts b/tests/e2e/common/plugin/base-plugin.spec.ts new file mode 100644 index 000000000..fb53f915e --- /dev/null +++ b/tests/e2e/common/plugin/base-plugin.spec.ts @@ -0,0 +1,69 @@ +import {BasePlugin} from '../../../../src'; + +describe('BasePlugin', () => { + let basePlugin; + let config = {x: 1, y: 2}; + + beforeEach(() => { + // @ts-ignore + basePlugin = BasePlugin.createPlugin('basePlugin', {}, config); + }); + + afterEach(() => { + basePlugin = null; + }); + + it('should create all BasePlugin properties', () => { + basePlugin.logger.should.exist; + basePlugin.player.should.exist; + basePlugin.name.should.exist; + basePlugin.eventManager.should.exist; + basePlugin.config.should.deep.equal(config); + }); + + it('should return the plugin name', () => { + basePlugin.getName().should.equal('basePlugin'); + }); + + it('should return the plugin config', () => { + basePlugin.getConfig().should.deep.equal(config); + }); + + it('should return copy of the plugin config', () => { + basePlugin.getConfig().x = 100; + basePlugin.getConfig().y = 200; + basePlugin.getConfig().x.should.equals(1); + basePlugin.getConfig().y.should.equals(2); + }); + + it('should return the config attribute value', () => { + basePlugin.getConfig('x').should.deep.equal(1); + }); + + it('should update the plugin config', () => { + let update = {y: 'hello'}; + basePlugin.updateConfig(update); + basePlugin.getConfig().should.deep.equal({x: 1, y: 'hello'}); + }); + + it('should throw isValid() exception', () => { + let exceptionOccurred = false; + try { + // @ts-ignore + BasePlugin.isValid(); + } catch (e) { + e.code.should.equals(7004); + e.data.should.equals('isValid()'); + exceptionOccurred = true; + } + exceptionOccurred.should.be.true; + }); + + it('should run super destroy()', () => { + basePlugin.destroy(); + }); + + it('should run super reset()', () => { + basePlugin.reset(); + }); +}); diff --git a/tests/e2e/common/plugin/plugin-manager.spec.ts b/tests/e2e/common/plugin/plugin-manager.spec.ts new file mode 100644 index 000000000..bf67e71a3 --- /dev/null +++ b/tests/e2e/common/plugin/plugin-manager.spec.ts @@ -0,0 +1,169 @@ +// @ts-nocheck +import {PluginManager} from '../../../../src/common/plugins'; +import ColorsPlugin from './test-plugins/colors-plugin'; +import NumbersPlugin from './test-plugins/numbers-plugin'; + +/** + * @returns {void} + */ +function registerAll() { + PluginManager.register('numbers', NumbersPlugin); + PluginManager.register('colors', ColorsPlugin); +} + +/** + * @returns {void} + */ +function unRegisterAll() { + PluginManager.unRegister('numbers'); + PluginManager.unRegister('colors'); +} + +describe('PluginManager.registry', () => { + beforeEach(() => { + registerAll(); + }); + + afterEach(() => { + unRegisterAll(); + }); + + it("shouldn't register the plugin because handler is not a function", () => { + unRegisterAll(); + PluginManager.register('numbers', {}).should.be.false; + (PluginManager._registry.get('numbers') === undefined).should.be.true; + }); + + it("shouldn't register the plugin because handler isn't derived from BasePlugin", () => { + unRegisterAll(); + PluginManager.register('numbers', function () {}).should.be.false; + (PluginManager._registry.get('numbers') === undefined).should.be.true; + }); + + it('should register new plugins', () => { + PluginManager._registry.size.should.equal(2); + PluginManager._registry.should.be.instanceof(Map); + }); + + it('should not register plugins that already registered', () => { + PluginManager.register('numbers', NumbersPlugin).should.be.false; + PluginManager.register('colors', ColorsPlugin).should.be.false; + PluginManager._registry.size.should.equal(2); + }); + + it('should get() the correct handler', () => { + PluginManager._registry.get('colors').should.be.instanceof(Function); + PluginManager._registry.get('numbers').should.be.instanceof(Function); + }); + + it('should has() the correct plugins', () => { + PluginManager._registry.has('colors').should.be.true; + PluginManager._registry.has('numbers').should.be.true; + PluginManager._registry.has('bubbles').should.be.false; + }); + + it('should remove() the plugin from the registry', () => { + PluginManager.unRegister('colors'); + PluginManager._registry.has('colors').should.be.false; + PluginManager._registry.size.should.equal(1); + }); +}); + +describe('PluginManager.plugins', () => { + let pluginManager; + let sandbox; + + beforeEach(() => { + pluginManager = new PluginManager(); + sandbox = sinon.createSandbox(); + registerAll(); + }); + + afterEach(() => { + pluginManager = null; + sandbox.restore(); + unRegisterAll(); + }); + + it('should create all PluginManager properties', () => { + Object.keys(pluginManager._plugins).length.should.equal(0); + pluginManager._plugins.should.be.instanceof(Object); + }); + + it("should throw error when try to load() plugin who isn't registered", () => { + let exceptionOccurred = false; + try { + pluginManager.load('bubbles', {}, {}); + } catch (e) { + exceptionOccurred = true; + e.code.should.equals(7003); + } + exceptionOccurred.should.be.true; + }); + + it("shouldn't load() the plugin", () => { + sandbox.stub(ColorsPlugin, 'isValid').callsFake(function () { + return false; + }); + pluginManager.load('colors', {}, {}).should.be.false; + }); + + it("shouldn't load() the plugin, plugin is disabled in the config", () => { + pluginManager.load('colors', {}, {disable: true}).should.be.false; + }); + + it("shouldn't load() the plugin, plugin is disabled in the previous config", () => { + pluginManager.load('colors', {}, {disable: true}).should.be.false; + pluginManager.load('colors', {}).should.be.false; + }); + + it('should load() the plugin, plugin is enable after is disabled in the config', () => { + pluginManager.load('colors', {}, {disable: true}).should.be.false; + pluginManager.load('colors', {}, {disable: false}).should.be.true; + Object.keys(pluginManager._plugins).length.should.equal(1); + }); + + it('should load() the plugins', () => { + pluginManager.load('colors', {}, {}).should.be.true; + Object.keys(pluginManager._plugins).length.should.equal(1); + pluginManager.load('numbers', {}, {}).should.be.true; + Object.keys(pluginManager._plugins).length.should.equal(2); + }); + + it('should get() the correct plugin', () => { + pluginManager.load('colors', {}, {}).should.be.true; + pluginManager.load('numbers', {}, {}).should.be.true; + pluginManager.get('colors').should.be.instanceof(ColorsPlugin); + pluginManager.get('numbers').should.be.instanceof(NumbersPlugin); + }); + + it('should destroy() all the plugins', () => { + pluginManager.load('colors', {}, {}).should.be.true; + pluginManager.load('numbers', {}, {}).should.be.true; + let colorsPlugin = pluginManager.get('colors'); + let numbersPlugin = pluginManager.get('numbers'); + let destroyColorsSpy = sandbox.spy(colorsPlugin, 'destroy'); + let destroyNumbersSpy = sandbox.spy(numbersPlugin, 'destroy'); + pluginManager.destroy(); + destroyColorsSpy.should.have.been.calledOnce; + destroyNumbersSpy.should.have.been.calledOnce; + (pluginManager.get('colors') === undefined).should.be.true; + (pluginManager.get('numbers') === undefined).should.be.true; + Object.keys(pluginManager._plugins).length.should.equal(0); + }); + + it('should reset() all the plugins', () => { + pluginManager.load('colors', {}, {}).should.be.true; + pluginManager.load('numbers', {}, {}).should.be.true; + let colorsPlugin = pluginManager.get('colors'); + let numbersPlugin = pluginManager.get('numbers'); + let resetColorsSpy = sandbox.spy(colorsPlugin, 'reset'); + let resetNumbersSpy = sandbox.spy(numbersPlugin, 'reset'); + pluginManager.reset(); + resetColorsSpy.should.have.been.calledOnce; + resetNumbersSpy.should.have.been.calledOnce; + pluginManager.get('colors').should.exist; + pluginManager.get('numbers').should.exist; + Object.keys(pluginManager._plugins).length.should.equal(2); + }); +}); diff --git a/tests/e2e/common/plugin/plugins-config.spec.js b/tests/e2e/common/plugin/plugins-config.spec.js new file mode 100644 index 000000000..f7483a141 --- /dev/null +++ b/tests/e2e/common/plugin/plugins-config.spec.js @@ -0,0 +1,152 @@ +import {ConfigEvaluator, getEncodedReferrer} from '../../../../src/common/plugins'; + +let sandbox = sinon.createSandbox(); + +describe('evaluatePluginsConfig', () => { + let playerConfig, pluginsConfig, configEvaluator; + + const updatedArrayValue = [1, 'value', 0, true, false]; + const arrayValue = [...updatedArrayValue, '{{value}}']; + + beforeEach(() => { + playerConfig = { + targetId: 'myTargetId', + provider: { + partnerId: '1234' + } + }; + pluginsConfig = { + kava: { + myHandler: () => {}, + myUnevaluatedConfig: '{{abc}}', + myArray: arrayValue + } + }; + + configEvaluator = new ConfigEvaluator(); + }); + + it('should save the function after evaluatePluginsConfig called', () => { + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myHandler.should.exist; + pluginsConfig.kava.myHandler.should.be.instanceof(Function); + }); + + it('should evaluate plugins config', () => { + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.partnerId.should.exist; + pluginsConfig.kava.partnerId.should.equal(1234); + }); + + it('should remove unevaluated plugins config', () => { + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.should.not.have.property('myUnevaluatedConfig'); + }); + + it('should remove unevaluated plugins config from array', () => { + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.should.deep.equal(updatedArrayValue); + }); + + it('should handle class instances in plugin config', () => { + const map = new Map(); + + pluginsConfig.kava.myInstance = map; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myInstance.should.deep.equal(map); + }); + + it('should handle class instances inside array in plugin config', () => { + const map1 = new Map(); + const map2 = new Map(); + const instanceArrayValue = [map1, map2]; + + pluginsConfig.kava.myArray = instanceArrayValue; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.should.deep.equal(instanceArrayValue); + }); + + it('should handle functions arrays in plugin config', () => { + function function1() {} + function function2() {} + const functionArray = [function1, function2]; + + pluginsConfig.kava.myArray = [function1, function2]; + pluginsConfig.kava.myArray.should.deep.equal(functionArray); + }); + + it('should handle object arrays in plugin config', () => { + const objectArrayValue = arrayValue.map(item => { + return { + value: item + }; + }); + pluginsConfig.kava.myArray = objectArrayValue; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.length.should.equal(updatedArrayValue.length); + }); + + it('should handle nested arrays inside object array in plugin config', () => { + const objectArrayValue = [ + { + value: arrayValue + } + ]; + + pluginsConfig.kava.myArray = objectArrayValue; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.length.should.equal(1); + pluginsConfig.kava.myArray[0].value.length.should.equal(updatedArrayValue.length); + }); + + it('should handle nested functions inside object array in plugin config', () => { + function function1() {} + function function2() {} + const functionArray = [function1, function2]; + + pluginsConfig.kava.myArray = functionArray; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.should.deep.equal(functionArray); + }); + + it('should handle nested class instances inside object array in plugin config', () => { + const map1 = new Map(); + const map2 = new Map(); + const instanceArrayValue = [map1, map2]; + + pluginsConfig.kava.myArray = instanceArrayValue; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.myArray.should.deep.equal(instanceArrayValue); + }); + + it('should set playerVersion as productVersion from server', () => { + window.__kalturaplayerdata = {productVersion: '7.43.1'}; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.should.have.property('playerVersion'); + pluginsConfig.kava.playerVersion.should.equal('7.43.1'); + }); + + it('should set playerVersion as playerVersion', () => { + window.__kalturaplayerdata = {}; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.should.have.property('playerVersion'); + pluginsConfig.kava.playerVersion.should.equal(__VERSION__); + }); + + it('should sanitize the entryName', () => { + playerConfig.sources = {metadata: {name: 'invalid\tname'}}; + pluginsConfig.kava.entryName = '{{entryName}}'; + configEvaluator.evaluatePluginsConfig(pluginsConfig, playerConfig); + pluginsConfig.kava.should.have.property('entryName'); + pluginsConfig.kava.entryName.should.equal('invalidname'); + }); +}); + +describe('getEncodedReferrer', () => { + it('should encode the referrer', () => { + sandbox.stub(window.parent.document, 'URL').get(() => { + return 'http://localhost:3000/?debugKalturaPlayer'; + }); + getEncodedReferrer().should.be.equal('http%3A%2F%2Flocalhost%3A3000%2F%3FdebugKalturaPlayer'); + }); +}); diff --git a/tests/e2e/common/plugin/test-plugins/async-reject-plugin.ts b/tests/e2e/common/plugin/test-plugins/async-reject-plugin.ts new file mode 100644 index 000000000..315932295 --- /dev/null +++ b/tests/e2e/common/plugin/test-plugins/async-reject-plugin.ts @@ -0,0 +1,28 @@ +import {BasePlugin} from '../../../../../src'; +import {Utils} from '@playkit-js/playkit-js'; +import {KalturaPlayer} from '../../../../../src/kaltura-player'; +import {DeferredPromise} from '../../../../../src/types/utils/deferred-promise'; + +export default class AsyncRejectPlugin extends BasePlugin { + static DELAY_ASYNC = 300; + static isValid(): boolean { + return true; + } + + promise: DeferredPromise; + + constructor(name: string, player: KalturaPlayer, config: Object) { + super(name, player, config); + this.promise = Utils.Object.defer(); + setTimeout(() => { + this.promise.reject(); + }, AsyncRejectPlugin.DELAY_ASYNC); + } + + + // @ts-ignore + get ready(): Promise { + // @ts-ignore + return this.promise; + } +} diff --git a/tests/e2e/common/plugin/test-plugins/async-resolve-plugin.ts b/tests/e2e/common/plugin/test-plugins/async-resolve-plugin.ts new file mode 100644 index 000000000..c59d9ea51 --- /dev/null +++ b/tests/e2e/common/plugin/test-plugins/async-resolve-plugin.ts @@ -0,0 +1,25 @@ +import {BasePlugin} from '../../../../../src'; +import {Utils} from '@playkit-js/playkit-js'; +import {DeferredPromise} from '../../../../../src/types/utils/deferred-promise'; +import {KalturaPlayer} from '../../../../../src/kaltura-player'; + +export default class AsyncResolvePlugin extends BasePlugin { + static DELAY_ASYNC = 500; + static isValid(): boolean { + return true; + } + promise: DeferredPromise; + + constructor(name: string, player: KalturaPlayer, config: Object) { + super(name, player, config); + this.promise = Utils.Object.defer(); + setTimeout(() => { + this.promise.resolve(); + }, AsyncResolvePlugin.DELAY_ASYNC); + } + // @ts-ignore + get ready(): Promise { + // @ts-ignore + return this.promise; + } +} diff --git a/tests/e2e/common/plugin/test-plugins/colors-plugin.ts b/tests/e2e/common/plugin/test-plugins/colors-plugin.ts new file mode 100644 index 000000000..266a695bc --- /dev/null +++ b/tests/e2e/common/plugin/test-plugins/colors-plugin.ts @@ -0,0 +1,46 @@ +import {BasePlugin} from '../../../../../src'; +import {KalturaPlayer as Player} from '../../../../../src/kaltura-player'; + +export default class ColorsPlugin extends BasePlugin { + _favouriteColor: string = ''; + _size: number = 0; + _colors: Array = []; + + static defaultConfig: Object = { + size: 3, + favouriteColor: 'green' + }; + + static isValid(): boolean { + return true; + } + + constructor(name: string, player: Player, config: Object) { + super(name, player, config); + this._configure(); + this._setup(); + } + + _configure() { + this._size = this.config.size; + this._favouriteColor = this.config.favouriteColor; + this.logger.info('_configure', this.config); + } + + _setup() { + this._colors = [this._favouriteColor, 'blue', 'pink']; + this.logger.info('_setup', this._colors); + } + + destroy() { + this._colors = []; + this._favouriteColor = ''; + this._size = 0; + this.logger.info('destroy', this._colors, this._favouriteColor, this._size); + } + + reset() { + this._colors = ['pink']; + this._size = 1; + } +} diff --git a/tests/e2e/common/plugin/test-plugins/numbers-plugin.ts b/tests/e2e/common/plugin/test-plugins/numbers-plugin.ts new file mode 100644 index 000000000..cf55db1b9 --- /dev/null +++ b/tests/e2e/common/plugin/test-plugins/numbers-plugin.ts @@ -0,0 +1,54 @@ +import {BasePlugin} from '../../../../../src'; +import {KalturaPlayer as Player} from '../../../../../src/kaltura-player'; + +export default class NumbersPlugin extends BasePlugin { + _firstCellValue: number = 0; + _lastCellValue: number = 0; + _size: number = 0; + _numbers: Array = []; + + static defaultConfig: Object = { + size: 10, + firstCellValue: 4, + lastCellValue: 6 + }; + + static isValid(): boolean { + return true; + } + + constructor(name: string, player: Player, config: Object) { + super(name, player, config); + this._configure(); + this._setup(); + } + + _configure() { + this._size = this.config.size; + this._firstCellValue = this.config.firstCellValue; + this._lastCellValue = this.config.lastCellValue; + this.logger.info('_configure', this.config); + } + + _setup() { + this._numbers[0] = this._firstCellValue; + for (let i = 1; i < this._size - 1; i++) { + this._numbers[i] = (i * i) / 2; + } + this._numbers[this._size - 1] = this._lastCellValue; + this.logger.info('_setup', this._numbers); + } + + destroy() { + this._numbers = []; + this._firstCellValue = 0; + this._lastCellValue = 0; + this._size = 0; + this.logger.info('destroy', this._numbers, this._firstCellValue, this._lastCellValue, this._size); + } + + reset() { + this._numbers = [1, 2, 3]; + this._size = 3; + } +} diff --git a/tests/e2e/common/service-provider.spec.js b/tests/e2e/common/service-provider.spec.js new file mode 100644 index 000000000..3e0dba18b --- /dev/null +++ b/tests/e2e/common/service-provider.spec.js @@ -0,0 +1,38 @@ +import {ServiceProvider} from '../../../src/common/service-provider'; + +describe('ServiceProvider', () => { + const fakePlayer = { + addEventListener: () => {}, + removeEventListener: () => {}, + Event: { + Core: { + PLAYER_RESET: 'playerreset' + } + } + }; + let serviceProvider; + beforeEach(() => { + serviceProvider = new ServiceProvider(fakePlayer); + }); + afterEach(() => { + serviceProvider.destroy(); + }); + + it('should register custom service', function () { + serviceProvider.has('custom').should.be.false; + serviceProvider.register('custom', {key: 1}); + serviceProvider.has('custom').should.be.true; + serviceProvider.get('custom').key.should.equals(1); + }); + + it('should not register custom service if already registered', function () { + serviceProvider.register('custom', {key: 1}); + serviceProvider.register('custom', {key: 2}); + serviceProvider.get('custom').key.should.equals(1); + }); + + it('should call to service destroy on player destroy', function (done) { + serviceProvider.register('custom', {destroy: () => done()}); + serviceProvider.destroy(); + }); +}); diff --git a/tests/e2e/common/storage/storage-manager.spec.js b/tests/e2e/common/storage/storage-manager.spec.js new file mode 100644 index 000000000..502c68474 --- /dev/null +++ b/tests/e2e/common/storage/storage-manager.spec.js @@ -0,0 +1,162 @@ +import StorageManager from '../../../../src/common/storage/storage-manager'; +import StorageWrapper from '../../../../src/common/storage/storage-wrapper'; +import * as TestUtils from '../../../utils/test-utils'; +import {setup} from '../../../../src'; +import {FakeEvent} from '@playkit-js/playkit-js'; +import {setStorageTextStyle} from '../../../../src/common/utils/setup-helpers'; + +const targetId = 'player-placeholder_storage-manager.spec'; + +describe('StorageManager', function () { + let config, player, sandbox; + const partnerId = 1091; + const entryId = '0_wifqaipd'; + const env = { + cdnUrl: 'https://qa-apache-php7.dev.kaltura.com/', + serviceUrl: 'https://qa-apache-php7.dev.kaltura.com/api_v3' + }; + + beforeEach(function () { + TestUtils.createElement('DIV', targetId); + sandbox = sinon.createSandbox(); + config = { + targetId: targetId, + provider: { + partnerId: partnerId, + env + } + }; + }); + + afterEach(function () { + sandbox.restore(); + TestUtils.removeVideoElementsFromTestPage(); + TestUtils.removeElement(targetId); + window.localStorage.clear(); + }); + + it('should return it has no storage', function () { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + sandbox.stub(StorageWrapper, 'size').get(() => 0); + StorageManager.hasStorage().should.be.false; + }); + + it('should return it has storage', function () { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + sandbox.stub(StorageWrapper, 'size').get(() => 1); + StorageManager.hasStorage().should.be.true; + }); + + it('should return config for volume', function () { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + sandbox.stub(StorageWrapper, 'size').get(() => 1); + sandbox.stub(StorageWrapper, 'getItem').withArgs('volume').returns(1); + StorageManager.getStorageConfig().should.deep.equal({ + playback: { + volume: 1 + } + }); + }); + + it('should return config for all properties', function () { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + let getItemStub = sandbox.stub(StorageWrapper, 'getItem'); + getItemStub.withArgs('volume').returns(0.5); + getItemStub.withArgs('muted').returns(false); + getItemStub.withArgs('textLanguage').returns('heb'); + getItemStub.withArgs('audioLanguage').returns('eng'); + StorageManager.getStorageConfig().should.deep.equal({ + playback: { + volume: 0.5, + muted: false, + textLanguage: 'heb', + audioLanguage: 'eng' + } + }); + }); + + it.skip('should set muted to true/false depends on changed volume', function (done) { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + player = setup(config); + player.loadMedia({entryId: entryId}).then(() => { + try { + player.muted = true; + player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CLICKED_MUTE)); + StorageManager.getStorageConfig().playback.muted.should.be.true; + player.volume = 0.5; + player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CHANGED_VOLUME)); + StorageManager.getStorageConfig().playback.muted.should.be.false; + StorageManager.getStorageConfig().playback.volume.should.equals(0.5); + player.volume = 0; + player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CHANGED_VOLUME)); + StorageManager.getStorageConfig().playback.muted.should.be.true; + StorageManager.getStorageConfig().playback.volume.should.equals(0); + done(); + } catch (err) { + done(err); + } + }); + }); + + it('should set textStyle of player with textStyle from local storage', function () { + let player = { + config: { + disableUserCache: false + }, + textStyle: { + fontFamily: 'Verdana' + } + }; + sandbox.stub(StorageManager, 'getPlayerTextStyle').returns({fontFamily: 'Arial'}); + sandbox.stub(StorageManager, 'isLocalStorageAvailable').returns(true); + setStorageTextStyle(player); + player.textStyle.fontFamily.should.equal('Arial'); + }); + + it('should not change textStyle of player', function () { + let player = { + config: { + disableUserCache: true + }, + textStyle: { + fontFamily: 'Verdana' + } + }; + sandbox.stub(StorageManager, 'getPlayerTextStyle').returns({fontFamily: 'Arial'}); + sandbox.stub(StorageManager, 'isLocalStorageAvailable').returns(true); + setStorageTextStyle(player); + player.textStyle.fontFamily.should.equal('Verdana'); + }); + + it.skip('should set textLanguage depends on CC toggle', function (done) { + StorageWrapper._testForLocalStorage = () => (StorageWrapper._isLocalStorageAvailable = true); + player = setup(config); + player.loadMedia({entryId: entryId}).then(() => { + player.load(); + player.ready().then(() => { + try { + player.dispatchEvent(new FakeEvent(player.Event.UI.USER_SHOWED_CAPTIONS, {element: 'ClosedCaptions'})); + player.addEventListener(player.Event.TEXT_TRACK_CHANGED, event => { + const {selectedTextTrack} = event.payload; + setTimeout(() => { + try { + StorageManager.getStorageConfig().playback.textLanguage.should.be.equal(selectedTextTrack.language); + if (selectedTextTrack.language === 'off') { + done(); + return; + } + player.dispatchEvent(new FakeEvent(player.Event.UI.USER_HID_CAPTIONS, {element: 'ClosedCaptions'})); + player.hideTextTrack(); + } catch (err) { + done(err); + } + }); + }); + player.showTextTrack(); + } catch (err) { + done(err); + } + }); + }); + }); +}); diff --git a/tests/e2e/common/storage/storage-wrapper.spec.js b/tests/e2e/common/storage/storage-wrapper.spec.js new file mode 100644 index 000000000..865166806 --- /dev/null +++ b/tests/e2e/common/storage/storage-wrapper.spec.js @@ -0,0 +1,41 @@ +import StorageWrapper from '../../../../src/common/storage/storage-wrapper'; + +const STORAGE_PREFIX = __NAME__ + '_'; + +describe('StorageWrapper', function () { + afterEach(function () { + window.localStorage.clear(); + }); + + it('should have size of 0', function () { + StorageWrapper.size.should.equal(0); + }); + + it('should set an item in the local storage', function () { + if (StorageWrapper._isLocalStorageAvailable) { + // let key = 'test'; + StorageWrapper.setItem(key, 1); + StorageWrapper.size.should.equal(1); + window.localStorage[STORAGE_PREFIX + key].should.exist; + window.localStorage[STORAGE_PREFIX + key].should.equal('1'); + } + }); + + it('should get an item from the local storage', function () { + if (StorageWrapper._isLocalStorageAvailable) { + let key = 'test'; + StorageWrapper.setItem(key, 2); + StorageWrapper.size.should.equal(1); + let value = StorageWrapper.getItem(key); + value.should.equal(2); + } + }); + + it('should validate a wrong key', function (done) { + try { + StorageWrapper.setItem(2, 2); + } catch (e) { + done(); + } + }); +}); diff --git a/tests/e2e/common/thumbnail-manager.spec.js b/tests/e2e/common/thumbnail-manager.spec.js new file mode 100644 index 000000000..f357c11a8 --- /dev/null +++ b/tests/e2e/common/thumbnail-manager.spec.js @@ -0,0 +1,217 @@ +import {MediaType} from '@playkit-js/playkit-js'; +import {DefaultThumbnailConfig, ThumbnailManager} from '../../../src/common/thumbnail-manager'; +import * as TestUtils from '../../utils/test-utils'; +import {setup} from '../../../src'; +import {Images} from '../mock-data/images'; + +describe('ThumbnailManager', () => { + let thumbnailManager, fakePlayer, fakeMediaConfig, sandbox; + const thumbsSprite = Images.THUMBNAILS_SPRITE; + const fakeSeekbarConfig = { + thumbsSlices: 200, + thumbsWidth: 100 + }; + + beforeEach(() => { + sandbox = sinon.createSandbox(); + fakePlayer = { + config: { + ui: { + components: { + seekbar: {} + } + } + }, + getThumbnail: () => {}, + _localPlayer: { + getThumbnail: () => {} + }, + shouldAddKs: () => true + }; + fakeMediaConfig = { + sources: { + poster: '//my-thumb-service.com/p/1/thumbnail/entry_id/2/version/3', + type: MediaType.VOD + }, + session: { + ks: 'my-ks' + } + }; + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('should get thumbnail slices url with default params', () => { + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager + .getKalturaThumbnailConfig() + .thumbsSprite.should.equals( + `${fakeMediaConfig.sources.poster}/width/${DefaultThumbnailConfig.thumbsWidth}/vid_slices/${DefaultThumbnailConfig.thumbsSlices}/ks/${fakeMediaConfig.session.ks}` + ); + }); + + it('should get thumbnail slices url with the custom params', () => { + fakePlayer.config.ui = { + components: { + seekbar: { + ...fakeSeekbarConfig + } + } + }; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager + .getKalturaThumbnailConfig() + .thumbsSprite.should.equals( + `${fakeMediaConfig.sources.poster}/width/${fakeSeekbarConfig.thumbsWidth}/vid_slices/${fakeSeekbarConfig.thumbsSlices}/ks/${fakeMediaConfig.session.ks}` + ); + }); + + it('should get empty thumbnail slices url for non string given', () => { + fakeMediaConfig.sources.poster = null; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().thumbsSprite.should.equals(``); + }); + + it('should get empty thumbnail slices url for non valid string given', () => { + fakeMediaConfig.sources.poster = '//my-thumb-service.com/p/1/entry_id/2/version/3'; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().thumbsSprite.should.equals(``); + }); + + it('should get empty thumbnail slices url for live content', () => { + fakeMediaConfig.sources.type = MediaType.LIVE; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().thumbsSprite.should.equals(``); + }); + + it('should get empty thumbnail slices url for live content', () => { + fakeMediaConfig.sources.type = MediaType.LIVE; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().thumbsSprite.should.equals(``); + }); + + it('should return kaltura thumbnail', () => { + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + const spy = sandbox.spy(thumbnailManager, '_convertKalturaThumbnailToThumbnailInfo'); + thumbnailManager.getThumbnail(100); + spy.should.calledOnce; + }); + + it('should return thumbnail from core player', () => { + fakeMediaConfig.sources.poster = null; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + const spy = sandbox.spy(fakePlayer._localPlayer, 'getThumbnail'); + thumbnailManager.getThumbnail(100); + spy.should.calledOnce; + }); + + it('should return thumbnail height from image sprite', () => { + fakeMediaConfig.sources.poster = null; + fakePlayer.config.ui.components.seekbar.thumbsSprite = thumbsSprite; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager._thumbsHeight = 999; + const thumbInfo = thumbnailManager.getThumbnail(100); + thumbInfo.height.should.equal(999); + }); + + it('should set the configured thumbs sprite with default sizes', () => { + fakePlayer.config.ui.components.seekbar.thumbsSprite = thumbsSprite; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().should.deep.equal({ + thumbsSprite, + ...DefaultThumbnailConfig + }); + }); + + it('should set the configured thumbs sprite with configured sizes', () => { + const seekbarConfig = { + thumbsSlices: 200, + thumbsSprite, + thumbsWidth: 300 + }; + fakePlayer.config.ui.components.seekbar = seekbarConfig; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager.getKalturaThumbnailConfig().should.deep.equal({...seekbarConfig, ...DefaultThumbnailConfig}); + }); + + it('should set the backend thumbs sprite with default sizes', () => { + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + const config = thumbnailManager.getKalturaThumbnailConfig(); + config.thumbsSlices.should.equal(DefaultThumbnailConfig.thumbsSlices); + config.thumbsWidth.should.equal(DefaultThumbnailConfig.thumbsWidth); + }); + + it('should set the backend thumbs sprite with configured sizes', () => { + fakePlayer.config.ui.components.seekbar = { + thumbsSlices: 200, + thumbsWidth: 300 + }; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + const config = thumbnailManager.getKalturaThumbnailConfig(); + config.thumbsSlices.should.equal(200); + config.thumbsWidth.should.equal(300); + }); + + it('should get thumbnail slices url without ks', () => { + sandbox.stub(fakePlayer, 'shouldAddKs').returns(false); + delete DefaultThumbnailConfig.thumbsSprite; + thumbnailManager = new ThumbnailManager(fakePlayer, fakePlayer.config.ui, fakeMediaConfig); + thumbnailManager + .getKalturaThumbnailConfig() + .thumbsSprite.should.equals( + `${fakeMediaConfig.sources.poster}/width/${DefaultThumbnailConfig.thumbsWidth}/vid_slices/${DefaultThumbnailConfig.thumbsSlices}` + ); + }); + + describe('Poster Integration', function () { + const targetId = 'player-placeholder_ovp/thumbnail.spec'; + + let config, kalturaPlayer; + const myCustomPosterUrl = Images.POSTER; + const entryId = '0_hut6q26s'; + const partnerId = 1091; + const env = { + cdnUrl: 'http://qa-apache-php7.dev.kaltura.com/', + serviceUrl: 'http://qa-apache-php7.dev.kaltura.com/api_v3' + }; + + before(function () { + TestUtils.createElement('DIV', targetId); + }); + + beforeEach(function () { + config = { + targetId: targetId, + provider: { + partnerId: partnerId, + env: env + }, + sources: {} + }; + }); + + afterEach(function () { + kalturaPlayer.destroy(); + TestUtils.removeVideoElementsFromTestPage(); + }); + + after(function () { + TestUtils.removeElement(targetId); + }); + + it.skip('should create thumbnail url from provider poster not from configured poster', function (done) { + config.sources.poster = myCustomPosterUrl; + kalturaPlayer = setup(config); + kalturaPlayer.loadMedia({entryId: entryId}).then(() => { + try { + kalturaPlayer.getThumbnail().should.be.exist; + done(); + } catch (e) { + done(e); + } + }); + }); + }); +}); diff --git a/tests/e2e/common/utils/evaluate.spec.js b/tests/e2e/common/utils/evaluate.spec.js new file mode 100644 index 000000000..e6d0ae787 --- /dev/null +++ b/tests/e2e/common/utils/evaluate.spec.js @@ -0,0 +1,38 @@ +import evaluate from '../../../../src/common/utils/evaluate'; + +describe('evaluate', function () { + const dataObject = { + a: { + a1: '{{token1}}', + a2: '{{token2}}' + }, + b: { + b1: '{{token3}}', + b2: '{{token4}}' + } + }; + const template = JSON.stringify(dataObject); + const model = {token1: 1, token2: 2}; + const modelWithDoubleQuotes = {token1: 'my expression with "double quotes"', token2: 2}; + + it('should evaluate and replace template tokens which have model values', function () { + const evaluatedTemplate = evaluate(template, model); + const evaluatedDataObj = JSON.parse(evaluatedTemplate); + evaluatedDataObj.a.a1.should.be.equal('1'); + evaluatedDataObj.a.a2.should.be.equal('2'); + }); + + it("should evaluate and not replace template tokens which don't have model values", function () { + const evaluatedTemplate = evaluate(template, model); + const evaluatedDataObj = JSON.parse(evaluatedTemplate); + evaluatedDataObj.b.b1.should.be.equal('{{token3}}'); + evaluatedDataObj.b.b2.should.be.equal('{{token4}}'); + }); + + it('should escape model values which have double quotes', function () { + const evaluatedTemplate = evaluate(template, modelWithDoubleQuotes); + const evaluatedDataObj = JSON.parse(evaluatedTemplate); + evaluatedDataObj.a.a1.should.be.equal('my expression with "double quotes"'); + evaluatedDataObj.a.a2.should.be.equal('2'); + }); +}); diff --git a/tests/e2e/common/utils/kaltura-params.spec.js b/tests/e2e/common/utils/kaltura-params.spec.js new file mode 100644 index 000000000..8ad0ead9b --- /dev/null +++ b/tests/e2e/common/utils/kaltura-params.spec.js @@ -0,0 +1,232 @@ +import { + addClientTag, + addKalturaParams, + addReferrer, + getReferrer, + addUIConfId, + handleSessionId, + updateSessionIdInUrl +} from '../../../../src/common/utils/kaltura-params'; + +class Player { + set sessionId(s) { + this.config.session.id = s; + } +} + +let player = new Player(); + +describe('addKalturaParams', function () { + it('should add session id, referrer and client tag for playManifest source', function () { + let source1 = {url: 'a/b/c/playmanifest/source'}; + let source2 = {url: 'd/e/f/playmanifest/source?a'}; + player.config = {session: {}, sources: {progressive: [source1, source2]}}; + addKalturaParams(player, player.config); + source1.url.should.be.equal( + 'a/b/c/playmanifest/source?playSessionId=' + + player.config.session.id + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&clientTag=html5:v' + + __VERSION__ + ); + source2.url.should.be.equal( + 'd/e/f/playmanifest/source?a&playSessionId=' + + player.config.session.id + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&clientTag=html5:v' + + __VERSION__ + ); + }); + + it('should add session id, referrer and client tag for PLAYMANIFEST source', function () { + let source1 = {url: 'a/b/c/PLAYMANIFEST/source'}; + let source2 = {url: 'd/e/f/PLAYMANIFEST/source?a'}; + player.config = {session: {}, sources: {progressive: [source1, source2]}}; + addKalturaParams(player, player.config); + source1.url.should.be.equal( + 'a/b/c/PLAYMANIFEST/source?playSessionId=' + + player.config.session.id + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&clientTag=html5:v' + + __VERSION__ + ); + source2.url.should.be.equal( + 'd/e/f/PLAYMANIFEST/source?a&playSessionId=' + + player.config.session.id + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&clientTag=html5:v' + + __VERSION__ + ); + }); + + it('should add nothing for no playManifest source', function () { + let source1 = {url: 'a/b/c'}; + addKalturaParams(player, {sources: {progressive: [source1]}}); + player.config.session.id.should.be.exist; + source1.url.should.be.equal('a/b/c'); + }); + + it('should add nothing for no playManifest source', function () { + let source1 = {url: 'a/b/c/PLAYMANIFEST/source'}; + source1.localSource = true; + addKalturaParams(player, {sources: {dash: [source1]}}); + player.config.session.id.should.be.exist; + source1.url.should.be.equal('a/b/c/PLAYMANIFEST/source'); + }); + + it('should add session id, referrer and client tag for PLAYMANIFEST source and session id, referrer, client tag and uiconfid to udrm license', function () { + let source1 = { + url: 'a/b/c/PLAYMANIFEST/source', + drmData: [{licenseUrl: 'udrm.kaltura.com?custom_data=someData&signature=Sig'}] + }; + player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}}; + addKalturaParams(player, player.config); + source1.url.should.be.equal( + 'a/b/c/PLAYMANIFEST/source?playSessionId=' + + player.config.session.id + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&clientTag=html5:v' + + __VERSION__ + ); + + source1.drmData[0].licenseUrl.should.be.equal( + 'udrm.kaltura.com?custom_data=someData&signature=Sig&sessionId=' + + player.config.session.id + + '&clientTag=html5:v' + + __VERSION__ + + '&referrer=' + + btoa(getReferrer().substr(0, 1000)) + + '&uiConfId=123' + ); + }); + + it('should not add session id, referrer, client tag and uiconfid to other drm system', function () { + let source1 = { + url: 'a/b/c/PLAYMANIFEST/source', + drmData: [{licenseUrl: 'udrm.other.com?custom_data=someData&signature=Sig'}] + }; + player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}}; + addKalturaParams(player, player.config); + + source1.drmData[0].licenseUrl.should.be.equal('udrm.other.com?custom_data=someData&signature=Sig'); + }); + + it('should not add session id, referrer, client tag and uiconfid to other drm system', function () { + let source1 = { + url: 'a/b/c/PLAYMANIFEST/source', + drmData: [{licenseUrl: 'udrm.kaltura.com?custommm_data=someData&signature=Sig'}] + }; + player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}}; + addKalturaParams(player, player.config); + + source1.drmData[0].licenseUrl.should.be.equal('udrm.kaltura.com?custommm_data=someData&signature=Sig'); + }); +}); + +describe('handleSessionId', function () { + let sessionIdRegex = /(?:[a-z0-9]|-)*:(?:[a-z0-9]|-)*/i; + it('should add the player session id', function () { + player.config = {session: {}}; + handleSessionId(player, player.config); + sessionIdRegex.test(player.config.session.id).should.be.true; + }); + + it('should update the player session id', function () { + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + handleSessionId(player, player.config); + sessionIdRegex.test(player.config.session.id).should.be.true; + (player.config.session.id.indexOf('5cc03aa6-c58f-3220-b548-2a698aa54830:') > -1).should.be.true; + (player.config.session.id.indexOf('33e6d80e-63b3-108a-091d-ccc15998f85b') > -1).should.be.false; + }); +}); + +describe('updateSessionIdInUrl', function () { + it('should add session id to URL as first param', function () { + let source = {url: 'a/b/c/playmanifest/source'}; + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + source.url = updateSessionIdInUrl(source.url, player.config.session.id); + source.url.should.be.equal('a/b/c/playmanifest/source?playSessionId=' + player.config.session.id); + }); + + it('should add session id to URL as second param', function () { + let source = {url: 'a/b/c/playmanifest/source?a'}; + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + source.url = updateSessionIdInUrl(source.url, player.config.session.id); + source.url.should.be.equal('a/b/c/playmanifest/source?a&playSessionId=' + player.config.session.id); + }); + + it('should update session id in URL as first param', function () { + let source = {url: 'a/b/c/playmanifest/source?playSessionId=5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}; + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + source.url = updateSessionIdInUrl(source.url, player.config.session.id); + source.url.should.be.equal('a/b/c/playmanifest/source?playSessionId=' + player.config.session.id); + }); + + it('should update session id in URL as second param', function () { + let source = {url: 'a/b/c/playmanifest/source?a&playSessionId=5cc03aa6-c58f-3220-b548-2a698aa54830:b5391ed8-be5d-3a71-e157-f23a1b434121'}; + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + source.url = updateSessionIdInUrl(source.url, player.config.session.id); + source.url.should.be.equal('a/b/c/playmanifest/source?a&playSessionId=' + player.config.session.id); + }); + + it('should update session id in URL with param different than playSessionId', function () { + let source = {url: 'a/b/c/playmanifest/source?testId=5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}; + player.config = {session: {id: '5cc03aa6-c58f-3220-b548-2a698aa54830:33e6d80e-63b3-108a-091d-ccc15998f85b'}}; + source.url = updateSessionIdInUrl(source.url, player.config.session.id, 'testId='); + source.url.should.be.equal('a/b/c/playmanifest/source?testId=' + player.config.session.id); + }); +}); + +describe('addReferrer', function () { + it('should add referrer as first param', function () { + let source = {url: 'a/b/c/playmanifest/source'}; + player.config = {session: {}}; + source.url = addReferrer(source.url); + source.url.should.be.equal('a/b/c/playmanifest/source?referrer=' + btoa(getReferrer().substr(0, 1000))); + }); + + it('should add referrer as second param', function () { + let source = {url: 'a/b/c/playmanifest/source?a'}; + player.config = {session: {}}; + source.url = addReferrer(source.url); + source.url.should.be.equal('a/b/c/playmanifest/source?a&referrer=' + btoa(getReferrer().substr(0, 1000))); + }); +}); + +describe('addUIConfId', function () { + it('should add uiConfId as first param', function () { + let source = {url: 'a/b/c/playmanifest/source'}; + player.config = {provider: {uiConfId: 123}}; + source.url = addUIConfId(source.url, player.config); + source.url.should.be.equal('a/b/c/playmanifest/source?uiConfId=123'); + }); + + it('should add uiConfId as second param', function () { + let source = {url: 'a/b/c/playmanifest/source?a'}; + player.config = {provider: {uiConfId: 123}}; + source.url = addUIConfId(source.url, player.config); + source.url.should.be.equal('a/b/c/playmanifest/source?a&uiConfId=123'); + }); +}); + +describe('addClientTag', function () { + it('should add client tag as first param', function () { + let source = {url: 'a/b/c/playmanifest/source'}; + let productVersion = '7.37'; + player.config = {session: {}}; + source.url = addClientTag(source.url, productVersion); + source.url.should.be.equal('a/b/c/playmanifest/source?clientTag=html5:v' + productVersion); + }); + + it('should add client tag as second param', function () { + let source = {url: 'a/b/c/playmanifest/source?a'}; + player.config = {session: {}}; + source.url = addClientTag(source.url); + source.url.should.be.equal('a/b/c/playmanifest/source?a&clientTag=html5:v' + __VERSION__); + }); +}); diff --git a/tests/e2e/common/utils/setup-helpers.spec.js b/tests/e2e/common/utils/setup-helpers.spec.js new file mode 100644 index 000000000..9a9f9c517 --- /dev/null +++ b/tests/e2e/common/utils/setup-helpers.spec.js @@ -0,0 +1,438 @@ +import * as TestUtils from '../../../utils/test-utils'; +import {ValidationErrorType} from '../../../../src/common/utils/validation-error'; +import StorageManager from '../../../../src/common/storage/storage-manager'; +import * as SetupHelpers from '../../../../src/common/utils/setup-helpers'; +import {Env} from '@playkit-js/playkit-js'; +import {Images} from '../../mock-data/images'; + +const targetId = 'player-placeholder_setup-helpers.spec'; + +describe('error handling', function () { + it('should throw error because no config provided', function (done) { + try { + SetupHelpers.validateConfig(); + } catch (e) { + e.message.should.equal(ValidationErrorType.INITIAL_CONFIG_REQUIRED); + done(); + } + }); + + it('should throw error because no target id provided', function (done) { + try { + SetupHelpers.validateConfig({}); + } catch (e) { + e.message.should.equal(ValidationErrorType.TARGET_ID_REQUIRED); + done(); + } + }); + + it('should throw error because no DOM element found', function (done) { + try { + SetupHelpers.validateConfig({targetId: 'my-player-div'}); + } catch (e) { + e.message.should.equal(ValidationErrorType.DOM_ELEMENT_WITH_TARGET_ID_REQUIRED + 'my-player-div'); + done(); + } + }); + + describe('send beacon', function () { + beforeEach(function () { + sinon.spy(navigator, 'sendBeacon'); + }); + + afterEach(function () { + navigator.sendBeacon.restore(); + }); + + it('should emit a beacon when no partner id provided', function (done) { + const div = document.createElement('DIV'); + div.id = 'test-id'; + document.body.appendChild(div); + (navigator.sendBeacon.getCall(0) === null).should.be.true; + SetupHelpers.validateProviderConfig({targetId: div.id, provider: {}}); + document.body.removeChild(div); + navigator.sendBeacon + .getCall(0) + .args[0].should.include( + 'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&referrer' + ); + done(); + }); + + it('should emit a beacon when the default partner id provided', function (done) { + const div = document.createElement('DIV'); + div.id = 'test-id'; + document.body.appendChild(div); + (navigator.sendBeacon.getCall(0) === null).should.be.true; + SetupHelpers.validateProviderConfig({targetId: div.id, provider: {partnerId: 2504201}}); + document.body.removeChild(div); + navigator.sendBeacon + .getCall(0) + .args[0].should.include( + 'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&referrer' + ); + done(); + }); + + it('should the beacon include clientVer', function (done) { + const div = document.createElement('DIV'); + window.__kalturaplayerdata = {productVersion: '7.37'}; + div.id = 'test-id'; + document.body.appendChild(div); + (navigator.sendBeacon.getCall(0) === null).should.be.true; + SetupHelpers.validateProviderConfig({targetId: div.id, provider: {partnerId: 2504201}}); + document.body.removeChild(div); + navigator.sendBeacon + .getCall(0) + .args[0].should.include( + 'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&clientVer=7.37&referrer' + ); + done(); + }); + }); +}); + +describe('createKalturaPlayerContainer', function () { + beforeEach(function () { + TestUtils.createElement('DIV', targetId); + }); + + afterEach(function () { + TestUtils.removeElement(targetId); + }); + + it('should create kaltura player container', function () { + let containerId = SetupHelpers.createKalturaPlayerContainer(targetId); + let el = document.getElementById(containerId); + el.should.exist; + el.className.should.equal('kaltura-player-container'); + }); +}); + +describe('checkNativeHlsSupport', function () { + it('set preferNative to true if user preference was set to true', function () { + const playerConfig = { + playback: { + preferNative: { + hls: true + } + } + }; + SetupHelpers.checkNativeHlsSupport(playerConfig); + playerConfig.playback.preferNative.hls.should.be.true; + }); + + it('set preferNative to false if user preference was set to false', function () { + const playerConfig = { + playback: { + preferNative: { + hls: false + } + } + }; + SetupHelpers.checkNativeHlsSupport(playerConfig); + playerConfig.playback.preferNative.hls.should.be.false; + }); + + it('set preferNative to default value if user preference was not set 1', function () { + const playerConfig = {}; + SetupHelpers.checkNativeHlsSupport(playerConfig); + if (Env.isSafari || Env.isIOS) { + playerConfig.playback.preferNative.hls.should.be.true; + } else { + playerConfig.should.deep.equal({}); + } + }); + + it('set preferNative to default value if user preference was not set 2', function () { + const playerConfig = { + playback: {} + }; + SetupHelpers.checkNativeHlsSupport(playerConfig); + if (Env.isSafari || Env.isIOS) { + playerConfig.playback.preferNative.hls.should.be.true; + } else { + playerConfig.should.deep.equal({ + playback: {} + }); + } + }); + + it('set preferNative to default value if user preference was not set 3', function () { + const playerConfig = { + playback: { + preferNative: {} + } + }; + SetupHelpers.checkNativeHlsSupport(playerConfig); + if (Env.isSafari || Env.isIOS) { + playerConfig.playback.preferNative.hls.should.be.true; + } else { + playerConfig.should.deep.equal({ + playback: { + preferNative: {} + } + }); + } + }); +}); + +describe('setStorageConfig', function () { + let sandbox; + + beforeEach(() => { + sandbox = sinon.createSandbox(); + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('should merge the player and storage config with priority to the storage config', function () { + const config = { + player: { + playback: { + textLanguage: 'ita' + } + } + }; + const storageConfig = { + playback: { + textLanguage: 'eng', + audioLanguage: 'fra' + } + }; + sandbox.stub(StorageManager, 'isLocalStorageAvailable').callsFake(() => true); + sandbox.stub(StorageManager, 'hasStorage').callsFake(() => true); + sandbox.stub(StorageManager, 'getStorageConfig').callsFake(() => storageConfig); + SetupHelpers.setStorageConfig(config); + config.playback.textLanguage.should.equal('eng'); + config.playback.audioLanguage.should.equal('fra'); + }); + + it('should take the storage config in case no player config', function () { + const config = {player: {}}; + const storageConfig = { + playback: { + textLanguage: 'eng', + audioLanguage: 'fra' + } + }; + sandbox.stub(StorageManager, 'isLocalStorageAvailable').callsFake(() => true); + sandbox.stub(StorageManager, 'hasStorage').callsFake(() => true); + sandbox.stub(StorageManager, 'getStorageConfig').callsFake(() => storageConfig); + SetupHelpers.setStorageConfig(config); + config.playback.textLanguage.should.equal('eng'); + config.playback.audioLanguage.should.equal('fra'); + }); +}); + +describe('supportLegacyOptions', function () { + let sandbox; + const legacyOptions = { + targetId: 'player-placeholder', + player: { + dvr: false, + type: 'Live', + duration: 10000, + name: 'name', + playback: { + autoplay: false + }, + metadata: { + poster: Images.POSTER + } + }, + provider: { + partnerId: 1091 + }, + ui: { + components: { + seekbar: { + thumbsSprite: Images.THUMBNAILS_SPRITE + } + } + } + }; + + const duplicateOptions = { + targetId: 'player-placeholder', + sources: { + dvr: false + }, + player: { + dvr: true, + type: 'Live', + duration: 10000, + name: 'name', + playback: { + autoplay: false + }, + metadata: { + poster: Images.POSTER + } + }, + provider: { + partnerId: 1091 + }, + ui: { + components: { + seekbar: { + thumbsSprite: Images.THUMBNAILS_SPRITE + } + } + } + }; + + const options = { + targetId: 'player-placeholder', + sources: { + dvr: false, + type: 'Live', + duration: 10000, + poster: Images.POSTER, + metadata: { + name: 'name' + } + }, + playback: { + autoplay: false + }, + provider: { + partnerId: 1091 + }, + ui: { + components: { + seekbar: { + thumbsSprite: Images.THUMBNAILS_SPRITE + } + } + } + }; + + beforeEach(function () { + sandbox = sinon.createSandbox(); + }); + + afterEach(function () { + sandbox.restore(); + }); + + it('should transform options with the old structure', function () { + SetupHelpers.supportLegacyOptions(legacyOptions); + legacyOptions.should.deep.equal(options); + }); + + it('should not transform config with the new structure', function () { + SetupHelpers.supportLegacyOptions(options); + legacyOptions.should.deep.equal(options); + }); + + it('check method support duplicate configuration take the new configuration', function () { + SetupHelpers.supportLegacyOptions(duplicateOptions); + duplicateOptions.should.deep.equal(options); + }); +}); + +describe('plugins config', function () { + let sandbox, isIOS; + + beforeEach(function () { + isIOS = Env.isIOS; + sandbox = sinon.createSandbox(); + }); + + afterEach(function () { + Env.isIOS = isIOS; + sandbox.restore(); + }); + + it('should config bumper plugin according to the env and configuration', function () { + Env.isIOS = true; + const options = { + provider: { + partnerId: 1091 + }, + playback: { + playsinline: false + }, + plugins: { + bumper: {}, + imadai: {} + } + }; + const defaultOptions = SetupHelpers.getDefaultOptions(options); + defaultOptions.plugins.bumper.position.should.deep.equal([0]); + defaultOptions.plugins.bumper.disableMediaPreload.should.be.true; + defaultOptions.plugins.bumper.playOnMainVideoTag.should.be.true; + }); + + it('should not change the bumper plugin', function () { + Env.isIOS = true; + const options = { + provider: { + partnerId: 1091 + }, + playback: { + playsinline: false + }, + plugins: { + bumper: { + playOnMainVideoTag: false, + position: [0, -1], + disableMediaPreload: false + }, + imadai: {} + } + }; + const defaultOptions = SetupHelpers.getDefaultOptions(options); + defaultOptions.plugins.bumper.position.should.deep.equal([0, -1]); + defaultOptions.plugins.bumper.disableMediaPreload.should.be.false; + defaultOptions.plugins.bumper.playOnMainVideoTag.should.be.false; + }); +}); + +describe('ignoreServerConfig', function () { + it('should use server config if ignoreServerConfig flag is not true', function () { + const serverConfig = { + playback: { + mute: true + } + }; + TestUtils.setServerConfig(serverConfig); + + const options = { + provider: { + partnerId: 1091 + }, + playback: { + autoplay: true + } + }; + + const defaultOptions = SetupHelpers.getDefaultOptions(options); + defaultOptions.playback.mute.should.be.true; + }); + + it('should not use server config if ignoreServerConfig flag is true', function () { + const serverConfig = { + playback: { + mute: true + } + }; + TestUtils.setServerConfig(serverConfig); + + const options = { + provider: { + partnerId: 1091, + ignoreServerConfig: true + }, + playback: { + autoplay: true + } + }; + + const defaultOptions = SetupHelpers.getDefaultOptions(options); + defaultOptions.playback.should.not.have.property('mute'); + }); +}); diff --git a/tests/e2e/configs/plugins.json b/tests/e2e/configs/plugins.json new file mode 100644 index 000000000..16fa7d885 --- /dev/null +++ b/tests/e2e/configs/plugins.json @@ -0,0 +1,30 @@ +{ + "all_plugins_default_config": { + "plugins": { + "colors": {}, + "numbers": {} + }, + "all_plugins_custom_config": { + "plugins": { + "colors": { + "favouriteColor": "black" + }, + "numbers": { + "size": 25, + "firstCellValue": 100, + "lastCellValue": 200 + } + } + }, + "only_colors_plugin": { + "plugins": { + "colors": {} + } + }, + "only_numbers_plugin": { + "plugins": { + "numbers": {} + } + } + } +} diff --git a/tests/e2e/configs/sources.json b/tests/e2e/configs/sources.json new file mode 100644 index 000000000..0469bddfb --- /dev/null +++ b/tests/e2e/configs/sources.json @@ -0,0 +1,67 @@ +{ + "Hls": { + "hls": [ + { + "mimetype": "application/x-mpegurl", + "url": "http://cdnbakmi.kaltura.com/p/243342/sp/24334200/playManifest/entryId/0_uka1msg4/flavorIds/1_vqhfu6uy,1_80sohj7p/format/applehttp/protocol/http/a.m3u8" + } + ] + }, + "Mp4": { + "progressive": [ + { + "mimetype": "video/mp4", + "url": "/base/tests/assets/audios.mp4", + "id": "1_rsrdfext_10081,url" + } + ] + }, + "MultipleSources": { + "progressive": [ + { + "mimetype": "video/mp4", + "url": "./base/tests/assets/audios.mp4", + "id": "id1", + "width": 200, + "height": 100, + "bandwidth": 100000, + "label": "label1" + }, + { + "mimetype": "video/mp4", + "url": "/base/tests/assets/mov_bbb.mp4", + "id": "id2", + "width": 100, + "height": 50, + "bandwidth": 200000, + "label": "label2" + } + ] + }, + "UnknownMimetype": { + "progressive": [ + { + "mimetype": "someMimeType", + "url": "some/url", + "id": "someId" + } + ] + }, + "CorruptedUrl": { + "progressive": [ + { + "mimetype": "video/mp4", + "url": "some/corrupted/url", + "id": "1_rsrdfext_10081,url" + } + ] + }, + "Live": { + "hls": [ + { + "mimetype": "application/x-mpegurl", + "url": "http://wms.shared.streamshow.it/carinatv/carinatv/playlist.m3u8" + } + ] + } +} diff --git a/tests/e2e/kaltura-player.spec.js b/tests/e2e/kaltura-player.spec.js index 8cdeb066f..1f98e1b53 100644 --- a/tests/e2e/kaltura-player.spec.js +++ b/tests/e2e/kaltura-player.spec.js @@ -1,1274 +1,1274 @@ -// import {setup} from '../../src'; -// import * as TestUtils from '../utils/test-utils'; -// import * as MediaMockData from './mock-data/media'; -// import * as PlaylistMockData from './mock-data/playlist'; -// import {PluginManager} from '../../src/common/plugins'; -// import ColorsPlugin from './common/plugin/test-plugins/colors-plugin'; -// import NumbersPlugin from './common/plugin/test-plugins/numbers-plugin'; -// import {KalturaPlayer as Player} from '../../src/kaltura-player'; -// import SourcesConfig from './configs/sources'; -// import {EventType as CoreEventType, FakeEvent, Utils, EventManager} from '@playkit-js/playkit-js'; -// import AsyncResolvePlugin from './common/plugin/test-plugins/async-resolve-plugin'; -// import AsyncRejectPlugin from './common/plugin/test-plugins/async-reject-plugin'; -// import {Provider} from '@playkit-js/playkit-js-providers'; -// import {Images} from './mock-data/images'; -// -// const targetId = 'player-placeholder_kaltura-player.spec'; -// -// describe('kaltura player api', function () { -// let config, kalturaPlayer, sandbox; -// const partnerId = 1091; -// -// before(function () { -// TestUtils.createElement('DIV', targetId); -// }); -// -// beforeEach(function () { -// sandbox = sinon.createSandbox(); -// config = { -// targetId: targetId, -// provider: { -// partnerId: partnerId -// } -// }; -// }); -// -// afterEach(function () { -// sandbox.restore(); -// kalturaPlayer = null; -// TestUtils.removeVideoElementsFromTestPage(); -// }); -// -// after(function () { -// TestUtils.removeElement(targetId); -// }); -// -// describe('constructor', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// }); -// -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// it('config.sources should be an empty object if no configured', function () { -// kalturaPlayer.config.sources.should.be.exist; -// }); -// }); -// describe('media api', function () { -// describe('loadMedia', function () { -// const entryId = '0_wifqaipd'; -// -// beforeEach(function () { -// kalturaPlayer = setup(config); -// sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function (info) { -// const id = info.playlistId || info.entryId; -// return id -// ? Promise.resolve(MediaMockData.MediaConfig[id]) -// : Promise.reject({ -// success: false, -// data: 'Missing mandatory parameter' -// }); -// }); -// }); -// -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should get media by id from the provider and set it', function (done) { -// kalturaPlayer.loadMedia({playlistId: entryId}).then(mediaConfig => { -// mediaConfig.sources.id.should.equal(entryId); -// kalturaPlayer.config.sources.id.should.equal(entryId); -// done(); -// }); -// }); -// -// it('should reject and throw an error when the provider request failed', function (done) { -// let errorEventTriggered = false; -// kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { -// errorEventTriggered = true; -// }); -// kalturaPlayer.loadMedia({}).catch(error => { -// error.data.should.equal('Missing mandatory parameter'); -// error.success.should.be.false; -// errorEventTriggered.should.be.true; -// done(); -// }); -// }); -// -// it('should use the configured start time from loadMedia options', function (done) { -// kalturaPlayer.addEventListener(kalturaPlayer.Event.FIRST_PLAYING, () => { -// (kalturaPlayer.currentTime >= 10).should.be.true; -// done(); -// }); -// kalturaPlayer.loadMedia({entryId}, {startTime: 10}).then(() => kalturaPlayer.play()); -// }); -// -// it('should use the configured poster from loadMedia options', function (done) { -// const poster = Images.POSTER; -// kalturaPlayer.addEventListener(kalturaPlayer.Event.CHANGE_SOURCE_ENDED, () => { -// kalturaPlayer.poster.should.equal(poster); -// done(); -// }); -// kalturaPlayer.loadMedia({entryId}, {poster}); -// }); -// -// it('the reset stat should be false whenever an error occurs', function (done) { -// kalturaPlayer._reset.should.be.true; -// kalturaPlayer.loadMedia({}).catch(() => { -// kalturaPlayer._reset.should.be.false; -// done(); -// }); -// }); -// -// describe('maybeSetStreamPriority', function () { -// describe('media source mime type is video/youtube', function () { -// it('should add youtube to stream priority if not already set', function (done) { -// kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => { -// let hasYoutube = false; -// kalturaPlayer.config.playback.streamPriority.forEach(sp => { -// if (sp.engine === 'youtube') { -// hasYoutube = true; -// } -// }); -// try { -// hasYoutube.should.be.true; -// done(); -// } catch (e) { -// done("youtube engine wasn't added to stream priority list"); -// } -// }); -// }); -// it('should not add youtube to stream priority if already set', function (done) { -// kalturaPlayer.configure({ -// playback: { -// streamPriority: [ -// { -// engine: 'youtube', -// format: 'progressive' -// } -// ] -// } -// }); -// kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => { -// let hasYoutube = false; -// kalturaPlayer.config.playback.streamPriority.length.should.equal(1); -// kalturaPlayer.config.playback.streamPriority.forEach(sp => { -// if (sp.engine === 'youtube') { -// hasYoutube = true; -// } -// }); -// try { -// hasYoutube.should.be.true; -// done(); -// } catch (e) { -// done("youtube engine wasn't added to stream priority list"); -// } -// }); -// }); -// }); -// describe('media source mime type is not video/youtube', function () { -// it('should not add youtube to stream priority', function (done) { -// kalturaPlayer.loadMedia({entryId: entryId}).then(() => { -// let hasYoutube = false; -// kalturaPlayer.config.playback.streamPriority.forEach(sp => { -// if (sp.engine === 'youtube') { -// hasYoutube = true; -// } -// }); -// try { -// hasYoutube.should.be.false; -// done(); -// } catch (e) { -// done('youtube engine was added to stream priority list'); -// } -// }); -// }); -// }); -// }); -// }); -// describe('setMedia', function () { -// const mediaWithUserSession = { -// sources: { -// dash: [ -// { -// id: '0_nwkp7jtx_301,mpegdash', -// url: 'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_nwkp7jtx/protocol/http/format/mpegdash/flavorIds/0_iju7j519,0_98mlrldo,0_5hts3h5r,0_n6n76xp9/a.mpd', -// mimetype: 'application/dash+xml' -// } -// ] -// }, -// session: { -// isAnonymous: false, -// ks: 'test-ks' -// } -// }; -// describe('shouldAddKs', () => { -// describe('loadThumbnailWithKs is false', () => { -// beforeEach(() => { -// config.provider.loadThumbnailWithKs = false; -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// describe('session not set', () => { -// it('should return false when session not set', () => { -// kalturaPlayer.shouldAddKs().should.equals(false); -// }); -// }); -// describe('anonymous session', () => { -// it('should return false when loadThumbnailWithKs is false', () => { -// kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); -// kalturaPlayer.shouldAddKs().should.equals(false); -// kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(false); -// }); -// }); -// describe('user session', () => { -// it('should return false when loadThumbnailWithKs is false', () => { -// kalturaPlayer.setMedia(mediaWithUserSession); -// kalturaPlayer.shouldAddKs().should.equals(false); -// kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(false); -// }); -// }); -// }); -// -// describe('loadThumbnailWithKs is true', () => { -// beforeEach(() => { -// config.provider.loadThumbnailWithKs = true; -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// config.provider.loadThumbnailWithKs = false; -// kalturaPlayer.destroy(); -// }); -// describe('session not set', () => { -// it('should return false when session not set', () => { -// kalturaPlayer.shouldAddKs().should.equals(false); -// }); -// }); -// describe('anonymous session', () => { -// it('should return false for anonymous session when called without mediaConfig parameter', () => { -// kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); -// kalturaPlayer.shouldAddKs().should.equals(false); -// }); -// it('should return false for anonymous session when called with mediaConfig parameter', () => { -// kalturaPlayer.setMedia(mediaWithUserSession); -// kalturaPlayer.shouldAddKs(MediaMockData.MediaConfig['0_wifqaipd']).should.equals(false); -// }); -// }); -// describe('user session', () => { -// it('should return true for user session when called without mediaConfig parameter', () => { -// kalturaPlayer.setMedia(mediaWithUserSession); -// kalturaPlayer.shouldAddKs().should.equals(true); -// }); -// it('should return true for user session when called with mediaConfig parameter', () => { -// kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); -// kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(true); -// }); -// }); -// }); -// }); -// }); -// describe('selectedSource', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// }); -// -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should get the selectedSource', function (done) { -// kalturaPlayer.addEventListener(kalturaPlayer.Event.SOURCE_SELECTED, event => { -// kalturaPlayer.selectedSource.should.equal(event.payload.selectedSource[0]); -// done(); -// }); -// kalturaPlayer.setMedia({sources: SourcesConfig.Mp4}); -// kalturaPlayer.selectedSource.should.equal(kalturaPlayer.sources.progressive[0]); -// }); -// }); -// describe('setSourcesMetadata', function () { -// const entryId = '0_wifqaipd'; -// beforeEach(function () { -// kalturaPlayer = setup(config); -// sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function (info) { -// const id = info.playlistId || info.entryId; -// return id -// ? Promise.resolve(MediaMockData.MediaConfig[id]) -// : Promise.reject({ -// success: false, -// data: 'Missing mandatory parameter' -// }); -// }); -// }); -// -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should set the sources metadata with the provided epgId', done => { -// kalturaPlayer.loadMedia({entryId}).then(() => { -// kalturaPlayer.configure({sources: {metadata: {epgId: '54321'}}}); -// kalturaPlayer.setSourcesMetadata({epgId: '12345'}); -// try { -// kalturaPlayer.config.sources.metadata.epgId.should.equals('12345'); -// kalturaPlayer.sources.metadata.epgId.should.equals('12345'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// }); -// }); -// -// describe('playlist api', function () { -// describe('loadPlaylist', function () { -// const playlistId = '0_wckoqjnn'; -// -// beforeEach(function () { -// kalturaPlayer = setup(config); -// sinon.stub(kalturaPlayer._provider, 'getPlaylistConfig').callsFake(function (playlistInfo) { -// return playlistInfo.playlistId -// ? Promise.resolve(PlaylistMockData.playlistByID) -// : Promise.reject({success: false, data: 'Missing mandatory parameter'}); -// }); -// }); -// -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should get playlist by id from the provider and set it - without config', function (done) { -// kalturaPlayer.loadPlaylist({playlistId: playlistId}).then(playlistData => { -// playlistData.id.should.equal(playlistId); -// kalturaPlayer.playlist.id.should.equal(playlistData.id); -// done(); -// }); -// }); -// -// it('should get playlist by id from the provider and set it - with config', function (done) { -// kalturaPlayer.loadPlaylist({playlistId: playlistId}, {options: {autoContinue: false}}).then(playlistData => { -// playlistData.id.should.equal(playlistId); -// kalturaPlayer.playlist.id.should.equal(playlistData.id); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// done(); -// }); -// }); -// -// it('should reject and throw an error when the provider request failed', function (done) { -// let errorEventTriggered = false; -// kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { -// errorEventTriggered = true; -// }); -// kalturaPlayer.loadPlaylist({}).catch(error => { -// error.data.should.equal('Missing mandatory parameter'); -// error.success.should.be.false; -// errorEventTriggered.should.be.true; -// done(); -// }); -// }); -// }); -// -// describe('loadPlaylistByEntryList', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// sinon.stub(kalturaPlayer._provider, 'getEntryListConfig').callsFake(function (entryList) { -// return entryList.entries -// ? Promise.resolve(PlaylistMockData.playlistByEntryList) -// : Promise.reject({success: false, data: 'Missing mandatory parameter'}); -// }); -// }); -// -// afterEach(() => { -// kalturaPlayer.destroy(); -// }); -// -// it('should get playlist by entry list from the provider and set it - without config', function (done) { -// kalturaPlayer.loadPlaylistByEntryList({entries: ['0_nwkp7jtx', '0_wifqaipd']}).then(playlistData => { -// playlistData.id.should.equal('a1234'); -// kalturaPlayer.playlist.id.should.equal('a1234'); -// done(); -// }); -// }); -// -// it('should get playlist by entry list from the provider and set it- with config', function (done) { -// kalturaPlayer.loadPlaylistByEntryList({entries: ['0_nwkp7jtx', '0_wifqaipd']}, {options: {autoContinue: false}}).then(playlistData => { -// playlistData.id.should.equal('a1234'); -// kalturaPlayer.playlist.id.should.equal('a1234'); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// done(); -// }); -// }); -// -// it('should reject and throw an error when the provider request failed', function (done) { -// let errorEventTriggered = false; -// kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { -// errorEventTriggered = true; -// }); -// kalturaPlayer.loadPlaylistByEntryList({}).catch(error => { -// error.data.should.equal('Missing mandatory parameter'); -// error.success.should.be.false; -// errorEventTriggered.should.be.true; -// done(); -// }); -// }); -// }); -// -// describe('setPlaylist', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should set the playlist and evaluate the plugins - without config and entry list', function () { -// kalturaPlayer.setPlaylist(PlaylistMockData.playlistByEntryList); -// kalturaPlayer.config.plugins.kava.playlistId.should.equal('a1234'); -// kalturaPlayer.playlist.id.should.equal('a1234'); -// }); -// -// it('should set the playlist and evaluate the plugins - with config and entry list', function () { -// kalturaPlayer.setPlaylist(PlaylistMockData.playlistByEntryList, {options: {autoContinue: false}}, [ -// {entryId: '0_nwkp7jtx'}, -// {entryId: '0_wifqaipd'} -// ]); -// kalturaPlayer.config.plugins.kava.playlistId.should.equal('a1234'); -// kalturaPlayer.playlist.id.should.equal('a1234'); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// kalturaPlayer._playlistManager._mediaInfoList.length.should.equal(2); -// }); -// }); -// -// describe('load playlist by setup config', function () { -// beforeEach(function () { -// config.playlist = PlaylistMockData.playlistByConfig; -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should set the configured playlist', function () { -// kalturaPlayer.playlist.id.should.equal('b1234'); -// kalturaPlayer.playlist.metadata.name.should.equal('my playlist name'); -// kalturaPlayer.playlist.metadata.description.should.equal('my playlist desc'); -// kalturaPlayer.playlist.poster.should.equal('http://cdntesting.qa.mkaltura.com/p/1091/sp/0/thumbnail/entry_id/0_wckoqjnn/version/100162'); -// kalturaPlayer.playlist.items.length.should.equal(3); -// kalturaPlayer.playlist.countdown.duration.should.equal(20); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// (kalturaPlayer.selectedSource === null).should.be.false; -// }); -// }); -// -// describe('load playlist by configure', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should set the configured playlist', function (done) { -// kalturaPlayer.addEventListener('kaltura-player-playlistloaded', event => { -// event.payload.playlist.id.should.equal('b1234'); -// kalturaPlayer.playlist.id.should.equal('b1234'); -// kalturaPlayer.playlist.metadata.name.should.equal('my playlist name'); -// kalturaPlayer.playlist.metadata.description.should.equal('my playlist desc'); -// kalturaPlayer.playlist.poster.should.equal('http://cdntesting.qa.mkaltura.com/p/1091/sp/0/thumbnail/entry_id/0_wckoqjnn/version/100162'); -// kalturaPlayer.playlist.items.length.should.equal(3); -// kalturaPlayer.playlist.countdown.duration.should.equal(20); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// done(); -// }); -// kalturaPlayer.configure({playlist: PlaylistMockData.playlistByConfig}); -// }); -// }); -// -// describe('mix setup config and api', function () { -// beforeEach(function () { -// config.playlist = { -// countdown: { -// duration: 20, -// showing: true -// }, -// options: { -// autoContinue: false -// } -// }; -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should load the playlist with the preset config', function () { -// kalturaPlayer.setPlaylist({id: 'a12345', items: []}, {countdown: {showing: false}}); -// kalturaPlayer.playlist.id.should.equal('a12345'); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// kalturaPlayer.playlist.countdown.showing.should.be.false; -// kalturaPlayer.playlist.countdown.duration.should.equal(20); -// }); -// }); -// -// describe('mix configure and api', function () { -// beforeEach(function () { -// kalturaPlayer = setup(config); -// }); -// afterEach(function () { -// kalturaPlayer.destroy(); -// }); -// -// it('should load the playlist with the preset config', function () { -// kalturaPlayer.configure({ -// playlist: { -// countdown: { -// duration: 20, -// showing: true -// }, -// options: { -// autoContinue: false -// } -// } -// }); -// kalturaPlayer.setPlaylist({id: 'a12345', items: []}, {countdown: {showing: false}}); -// kalturaPlayer.playlist.id.should.equal('a12345'); -// kalturaPlayer.playlist.options.autoContinue.should.be.false; -// kalturaPlayer.playlist.countdown.showing.should.be.false; -// kalturaPlayer.playlist.countdown.duration.should.equal(20); -// }); -// }); -// }); -// -// describe('plugins lifecycle', () => { -// let player; -// beforeEach(() => { -// PluginManager.register('colors', ColorsPlugin); -// PluginManager.register('numbers', NumbersPlugin); -// }); -// -// afterEach(() => { -// PluginManager.unRegister('colors'); -// PluginManager.unRegister('numbers'); -// }); -// -// it('should load 2 plugins on initial config and configure them on configure', function () { -// player = new Player({ -// ui: {}, -// provider: {}, -// plugins: { -// colors: { -// size: 5 -// }, -// numbers: { -// size: 20 -// } -// } -// }); -// player._pluginManager.get('colors').should.exist; -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(2); -// player.config.plugins.colors.should.deep.equals({ -// size: 5, -// favouriteColor: 'green' -// }); -// player.config.plugins.numbers.should.deep.equals({ -// size: 20, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// player.configure({ -// plugins: { -// colors: { -// size: 50 -// }, -// numbers: { -// size: 200 -// } -// } -// }); -// player._pluginManager.get('colors').should.exist; -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(2); -// player.config.plugins.colors.should.deep.equals({ -// size: 50, -// favouriteColor: 'green' -// }); -// player.config.plugins.numbers.should.deep.equals({ -// size: 200, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// }); -// -// it('should load 1st plugin on initial config, load 2nd plugin and configure the 1st on configure', function () { -// player = new Player({ -// ui: {}, -// provider: {}, -// plugins: { -// numbers: { -// size: 20 -// } -// } -// }); -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.numbers.should.deep.equals({ -// size: 20, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// player.configure({ -// plugins: { -// colors: { -// size: 50 -// }, -// numbers: { -// size: 200 -// } -// } -// }); -// player._pluginManager.get('colors').should.exist; -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(2); -// player.config.plugins.colors.should.deep.equals({ -// size: 50, -// favouriteColor: 'green' -// }); -// player.config.plugins.numbers.should.deep.equals({ -// size: 200, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// }); -// -// it('should create player without plugins, load plugins on configure', function () { -// player = new Player({ -// ui: {}, -// plugins: {}, -// advertising: { -// adBreaks: [] -// }, -// provider: {} -// }); -// Object.keys(player._pluginManager._plugins).length.should.equals(0); -// player.config.plugins.should.deep.equals({}); -// player.configure({ -// plugins: { -// colors: { -// size: 50 -// }, -// numbers: { -// size: 200 -// } -// } -// }); -// player._pluginManager.get('colors').should.exist; -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(2); -// player.config.plugins.colors.should.deep.equals({ -// size: 50, -// favouriteColor: 'green' -// }); -// player.config.plugins.numbers.should.deep.equals({ -// size: 200, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// }); -// -// it('should create player without plugins, load 1st plugin on configure, configure 1st plugin with/after sources', function () { -// player = new Player({ -// ui: {}, -// plugins: {}, -// provider: {} -// }); -// Object.keys(player._pluginManager._plugins).length.should.equals(0); -// player.config.plugins.should.deep.equals({}); -// player.configure({ -// plugins: { -// numbers: { -// size: 200 -// } -// } -// }); -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.numbers.should.deep.equals({ -// size: 200, -// firstCellValue: 4, -// lastCellValue: 6 -// }); -// player.configure({ -// plugins: { -// numbers: { -// size: 2, -// firstCellValue: 3 -// } -// } -// }); -// player.setMedia({ -// sources: SourcesConfig.Mp4 -// }); -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.numbers.should.deep.equals({ -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// }); -// player.configure({ -// plugins: { -// numbers: { -// size: 78 -// } -// } -// }); -// player.config.plugins.numbers.should.deep.equals({ -// size: 78, -// firstCellValue: 3, -// lastCellValue: 6 -// }); -// }); -// -// it('should create player with plugin and fail to configure other plugin after sources', function () { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// numbers: { -// size: 2, -// firstCellValue: 3 -// } -// } -// }); -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.should.deep.equals({ -// numbers: { -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// } -// }); -// player.configure({ -// plugins: { -// colors: { -// size: 200 -// } -// } -// }); -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.should.deep.equals({ -// numbers: { -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// } -// }); -// }); -// -// it('should create the plugin before playlist source selected', function () { -// const eventManager = new EventManager(); -// player = new Player({ -// ui: {}, -// provider: {}, -// playlist: { -// id: '1234', -// metdata: {}, -// items: [ -// { -// sources: SourcesConfig.Mp4 -// } -// ] -// }, -// plugins: { -// numbers: { -// size: 2, -// firstCellValue: 3 -// } -// } -// }); -// eventManager.listen(player, CoreEventType.SOURCE_SELECTED, () => { -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.should.deep.equals({ -// numbers: { -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// } -// }); -// }); -// }); -// -// it('should create player with plugin and fail to configure other plugin after playlist source selected', function () { -// player = new Player({ -// ui: {}, -// provider: {}, -// playlist: { -// id: '1234', -// metdata: {}, -// items: [ -// { -// sources: SourcesConfig.Mp4 -// } -// ] -// }, -// plugins: { -// numbers: { -// size: 2, -// firstCellValue: 3 -// } -// } -// }); -// player._pluginManager.get('numbers').should.exist; -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.should.deep.equals({ -// numbers: { -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// } -// }); -// player.configure({ -// plugins: { -// colors: { -// size: 200 -// } -// } -// }); -// Object.keys(player._pluginManager._plugins).length.should.equals(1); -// player.config.plugins.should.deep.equals({ -// numbers: { -// size: 2, -// firstCellValue: 3, -// lastCellValue: 6 -// } -// }); -// }); -// }); -// -// describe('async plugins loading', () => { -// let player; -// beforeEach(() => { -// PluginManager.register('asyncResolve', AsyncResolvePlugin); -// PluginManager.register('asyncReject', AsyncRejectPlugin); -// }); -// -// afterEach(() => { -// PluginManager.unRegister('asyncResolve'); -// PluginManager.unRegister('asyncReject'); -// player.destroy(); -// }); -// -// it('should create player with async resolve plugin - check async load', done => { -// try { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// asyncResolve: {} -// } -// }); -// player._pluginManager.get('asyncResolve').should.exist; -// sinon.stub(player._localPlayer, '_load').callsFake(function () { -// player._pluginManager.get('asyncResolve').ready.then(() => { -// done(); -// }); -// }); -// player.load(); -// } catch (e) { -// done(e); -// } -// }); -// -// it('should create player with async resolve plugin - check async play', done => { -// try { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// asyncResolve: {} -// } -// }); -// player._pluginManager.get('asyncResolve').should.exist; -// sinon.stub(player._localPlayer, '_play').callsFake(function () { -// player._pluginManager.get('asyncResolve').ready.then(() => { -// done(); -// }); -// }); -// player.play(); -// } catch (e) { -// done(e); -// } -// }); -// -// it('should create player with async reject plugin - check async load', done => { -// try { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// asyncReject: {} -// } -// }); -// player._pluginManager.get('asyncReject').should.exist; -// sinon.stub(player._localPlayer, '_load').callsFake(function () { -// player._pluginManager.get('asyncReject').ready.catch(() => { -// done(); -// }); -// }); -// player.load(); -// } catch (e) { -// done(e); -// } -// }); -// -// it('should create player with async reject plugin - check async play', done => { -// try { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// asyncReject: {} -// } -// }); -// player._pluginManager.get('asyncReject').should.exist; -// sinon.stub(player._localPlayer, '_play').callsFake(function () { -// player._pluginManager.get('asyncReject').ready.catch(() => { -// done(); -// }); -// }); -// player.play(); -// } catch (e) { -// done(e); -// } -// }); -// -// it('should create player with async resolve plugin and reject plugin - check async play', done => { -// try { -// player = new Player({ -// ui: {}, -// provider: {}, -// sources: SourcesConfig.Mp4, -// plugins: { -// asyncReject: {}, -// asyncResolve: {} -// } -// }); -// player._pluginManager.get('asyncReject').should.exist; -// player._pluginManager.get('asyncResolve').should.exist; -// sinon.stub(player._localPlayer, '_load').callsFake(function () { -// player._pluginManager.get('asyncResolve').ready.then(() => { -// player._pluginManager.get('asyncReject').ready.catch(() => { -// done(); -// }); -// }); -// }); -// player.load(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// -// describe('events', function () { -// let player; -// -// it('should fire PLAYBACK_START on play', done => { -// player = new Player({ -// ui: {}, -// provider: {} -// }); -// player.addEventListener(player.Event.PLAYBACK_START, () => { -// done(); -// }); -// player.play(); -// }); -// -// it('should fire PLAYBACK_START on autoplay', done => { -// player = new Player({ -// ui: {}, -// provider: {} -// }); -// player.addEventListener(player.Event.PLAYBACK_START, () => { -// done(); -// }); -// player.configure({ -// playback: { -// autoplay: true -// } -// }); -// player.setMedia({ -// sources: SourcesConfig.Mp4 -// }); -// }); -// -// it('should fire auto play failed and show the poster once get AD_AUTOPLAY_FAILED', done => { -// player = new Player({ -// ui: {}, -// provider: {}, -// playback: { -// autoplay: true -// } -// }); -// player.addEventListener(player.Event.AUTOPLAY_FAILED, event => { -// try { -// player._localPlayer.posterManager._el.style.display.should.equal(''); -// event.payload.error.should.equal('mock failure'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// player.dispatchEvent(new FakeEvent(player.Event.AD_AUTOPLAY_FAILED, {error: 'mock failure'})); -// }); -// }); -// -// describe('evaluate plugins config', function () { -// beforeEach(() => { -// PluginManager.register('colors', ColorsPlugin); -// }); -// -// afterEach(() => { -// PluginManager.unRegister('colors'); -// }); -// -// it('should pass deep object as plugin config', () => { -// const test = {a: {b: {c: 'd'}}}; -// const config = { -// plugins: { -// colors: { -// prop: test -// } -// }, -// ui: {}, -// provider: {} -// }; -// const player = new Player(config); -// player.getMediaConfig().plugins.should.deep.equals(config.plugins); -// }); -// -// it('should pass class as plugin config', () => { -// const test = class Test { -// constructor() {} -// -// print() {} -// }; -// const config = { -// plugins: { -// colors: { -// prop: test -// } -// }, -// ui: {}, -// provider: {} -// }; -// const player = new Player(config); -// player.getMediaConfig().plugins.should.deep.equals(config.plugins); -// }); -// -// it('should pass class instance as plugin config', done => { -// const test = class Test { -// constructor() {} -// -// check() { -// done(); -// } -// }; -// const config = { -// plugins: { -// colors: { -// prop: new test() -// } -// }, -// ui: {}, -// provider: {} -// }; -// const player = new Player(config); -// player.getMediaConfig().plugins.should.deep.equals(config.plugins); -// player.plugins.colors.config.prop.check(); -// }); -// -// it('should pass function as plugin config', done => { -// const test = () => { -// done(); -// }; -// const config = { -// plugins: { -// colors: { -// prop: test -// } -// }, -// ui: {}, -// provider: {} -// }; -// const player = new Player(config); -// player.getMediaConfig().plugins.should.deep.equals(config.plugins); -// player.plugins.colors.config.prop(); -// }); -// -// describe('changeMedia and multi players', function () { -// const config = { -// plugins: {}, -// ui: {}, -// provider: {} -// }; -// let player; -// const entryId = '0_wifqaipd'; -// const entryId2 = '0_nwkp7jtx'; -// -// beforeEach(() => { -// player = new Player(Utils.Object.mergeDeep({}, config)); -// player._configEvaluator._pluginConfigStore._config = { -// colors: { -// entryId: '{{entryId}}', -// partnerId: '{{partnerId}}', -// entryName: '{{entryName}}', -// entryType: '{{entryType}}' -// } -// }; -// player.configure({ -// plugins: { -// colors: { -// entryName: '{{entryType}}', -// entryType: 'custom' -// } -// } -// }); -// sinon.stub(Provider.prototype, 'getMediaConfig').callsFake(info => { -// const id = info.playlistId || info.entryId; -// return id -// ? Promise.resolve(MediaMockData.MediaConfig[id]) -// : Promise.reject({ -// success: false, -// data: 'Missing mandatory parameter' -// }); -// }); -// }); -// -// afterEach(() => { -// sandbox.restore(); -// Provider.prototype.getMediaConfig.restore(); -// player.destroy(); -// }); -// -// it('should evaluate the plugin config - first media', done => { -// player.loadMedia({entryId}).then(() => { -// try { -// player.plugins.colors.config.entryId.should.equals(entryId); -// player.plugins.colors.config.partnerId.should.equals(1091); -// player.plugins.colors.config.entryName.should.equals('Vod'); -// player.plugins.colors.config.entryType.should.equals('custom'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// -// it('should evaluate the default plugin config - second media', done => { -// player.loadMedia({entryId}).then(() => { -// player.loadMedia({entryId: entryId2}).then(() => { -// try { -// player.plugins.colors.config.entryId.should.equals(entryId2); -// player.plugins.colors.config.partnerId.should.equals(1091); -// player.plugins.colors.config.entryName.should.equals('Live'); -// player.plugins.colors.config.entryType.should.equals('custom'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// }); -// -// it('should plugin from setMedia be available after sources selected', () => { -// PluginManager.register('numbers', NumbersPlugin); -// player.setMedia({sources: SourcesConfig.Mp4, plugins: {numbers: {}}}); -// (player.plugins.numbers !== undefined).should.be.true; -// (player.plugins.numbers !== null).should.be.true; -// player.plugins.numbers.should.be.instanceOf(NumbersPlugin); -// PluginManager.unRegister('numbers', NumbersPlugin); -// }); -// -// it('should evaluate the plugin config on source selected', done => { -// player.addEventListener(player.Event.SOURCE_SELECTED, () => { -// try { -// player.plugins.colors.config.entryId.should.equals(entryId); -// player.plugins.colors.config.partnerId.should.equals(1091); -// player.plugins.colors.config.entryName.should.equals('Vod'); -// player.plugins.colors.config.entryType.should.equals('custom'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// player.loadMedia({entryId}); -// }); -// -// it('should evaluate the configured plugin config - second media', done => { -// player.loadMedia({entryId}).then(() => { -// player.configure({ -// plugins: { -// colors: { -// partnerId: '{{entryId}}', -// entryName: 'name' -// } -// } -// }); -// player.loadMedia({entryId: entryId2}).then(() => { -// try { -// player.plugins.colors.config.entryId.should.equals(entryId2); -// player.plugins.colors.config.partnerId.should.equals(entryId2); -// player.plugins.colors.config.entryName.should.equals('name'); -// player.plugins.colors.config.entryType.should.equals('custom'); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// }); -// -// it('should evaluate the plugin config - another player', done => { -// const player2 = new Player( -// Utils.Object.mergeDeep( -// {}, -// { -// plugins: { -// colors: {} -// }, -// ui: {}, -// provider: {} -// } -// ) -// ); -// player2._configEvaluator._pluginConfigStore._config = { -// colors: { -// entryId: '{{entryId}}', -// partnerId: '{{partnerId}}' -// } -// }; -// player2.loadMedia({entryId}).then(() => { -// try { -// player2.plugins.colors.config.entryId.should.equals(entryId); -// player2.plugins.colors.config.partnerId.should.equals(1091); -// done(); -// } catch (e) { -// done(e); -// } -// }); -// }); -// }); -// }); -// }); +import {setup} from '../../src'; +import * as TestUtils from '../utils/test-utils'; +import * as MediaMockData from './mock-data/media'; +import * as PlaylistMockData from './mock-data/playlist'; +import {PluginManager} from '../../src/common/plugins'; +import ColorsPlugin from './common/plugin/test-plugins/colors-plugin'; +import NumbersPlugin from './common/plugin/test-plugins/numbers-plugin'; +import {KalturaPlayer as Player} from '../../src/kaltura-player'; +import SourcesConfig from './configs/sources.json'; +import {EventType as CoreEventType, FakeEvent, Utils, EventManager} from '@playkit-js/playkit-js'; +import AsyncResolvePlugin from './common/plugin/test-plugins/async-resolve-plugin'; +import AsyncRejectPlugin from './common/plugin/test-plugins/async-reject-plugin'; +import {Provider} from '@playkit-js/playkit-js-providers'; +import {Images} from './mock-data/images'; + +const targetId = 'player-placeholder_kaltura-player.spec'; + +describe('kaltura player api', function () { + let config, kalturaPlayer, sandbox; + const partnerId = 1091; + + before(function () { + TestUtils.createElement('DIV', targetId); + }); + + beforeEach(function () { + sandbox = sinon.createSandbox(); + config = { + targetId: targetId, + provider: { + partnerId: partnerId + } + }; + }); + + afterEach(function () { + sandbox.restore(); + kalturaPlayer = null; + TestUtils.removeVideoElementsFromTestPage(); + }); + + after(function () { + TestUtils.removeElement(targetId); + }); + + describe('constructor', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + }); + + afterEach(function () { + kalturaPlayer.destroy(); + }); + it('config.sources should be an empty object if no configured', function () { + kalturaPlayer.config.sources.should.be.exist; + }); + }); + describe('media api', function () { + describe('loadMedia', function () { + const entryId = '0_wifqaipd'; + + beforeEach(function () { + kalturaPlayer = setup(config); + sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function (info) { + const id = info.playlistId || info.entryId; + return id + ? Promise.resolve(MediaMockData.MediaConfig[id]) + : Promise.reject({ + success: false, + data: 'Missing mandatory parameter' + }); + }); + }); + + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should get media by id from the provider and set it', function (done) { + kalturaPlayer.loadMedia({playlistId: entryId}).then(mediaConfig => { + mediaConfig.sources.id.should.equal(entryId); + kalturaPlayer.config.sources.id.should.equal(entryId); + done(); + }); + }); + + it('should reject and throw an error when the provider request failed', function (done) { + let errorEventTriggered = false; + kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { + errorEventTriggered = true; + }); + kalturaPlayer.loadMedia({}).catch(error => { + error.data.should.equal('Missing mandatory parameter'); + error.success.should.be.false; + errorEventTriggered.should.be.true; + done(); + }); + }); + + it('should use the configured start time from loadMedia options', function (done) { + kalturaPlayer.addEventListener(kalturaPlayer.Event.FIRST_PLAYING, () => { + (kalturaPlayer.currentTime >= 10).should.be.true; + done(); + }); + kalturaPlayer.loadMedia({entryId}, {startTime: 10}).then(() => kalturaPlayer.play()); + }); + + it('should use the configured poster from loadMedia options', function (done) { + const poster = Images.POSTER; + kalturaPlayer.addEventListener(kalturaPlayer.Event.CHANGE_SOURCE_ENDED, () => { + kalturaPlayer.poster.should.equal(poster); + done(); + }); + kalturaPlayer.loadMedia({entryId}, {poster}); + }); + + it('the reset stat should be false whenever an error occurs', function (done) { + kalturaPlayer._reset.should.be.true; + kalturaPlayer.loadMedia({}).catch(() => { + kalturaPlayer._reset.should.be.false; + done(); + }); + }); + + describe('maybeSetStreamPriority', function () { + describe('media source mime type is video/youtube', function () { + it('should add youtube to stream priority if not already set', function (done) { + kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => { + let hasYoutube = false; + kalturaPlayer.config.playback.streamPriority.forEach(sp => { + if (sp.engine === 'youtube') { + hasYoutube = true; + } + }); + try { + hasYoutube.should.be.true; + done(); + } catch (e) { + done("youtube engine wasn't added to stream priority list"); + } + }); + }); + it('should not add youtube to stream priority if already set', function (done) { + kalturaPlayer.configure({ + playback: { + streamPriority: [ + { + engine: 'youtube', + format: 'progressive' + } + ] + } + }); + kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => { + let hasYoutube = false; + kalturaPlayer.config.playback.streamPriority.length.should.equal(1); + kalturaPlayer.config.playback.streamPriority.forEach(sp => { + if (sp.engine === 'youtube') { + hasYoutube = true; + } + }); + try { + hasYoutube.should.be.true; + done(); + } catch (e) { + done("youtube engine wasn't added to stream priority list"); + } + }); + }); + }); + describe('media source mime type is not video/youtube', function () { + it('should not add youtube to stream priority', function (done) { + kalturaPlayer.loadMedia({entryId: entryId}).then(() => { + let hasYoutube = false; + kalturaPlayer.config.playback.streamPriority.forEach(sp => { + if (sp.engine === 'youtube') { + hasYoutube = true; + } + }); + try { + hasYoutube.should.be.false; + done(); + } catch (e) { + done('youtube engine was added to stream priority list'); + } + }); + }); + }); + }); + }); + describe('setMedia', function () { + const mediaWithUserSession = { + sources: { + dash: [ + { + id: '0_nwkp7jtx_301,mpegdash', + url: 'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_nwkp7jtx/protocol/http/format/mpegdash/flavorIds/0_iju7j519,0_98mlrldo,0_5hts3h5r,0_n6n76xp9/a.mpd', + mimetype: 'application/dash+xml' + } + ] + }, + session: { + isAnonymous: false, + ks: 'test-ks' + } + }; + describe('shouldAddKs', () => { + describe('loadThumbnailWithKs is false', () => { + beforeEach(() => { + config.provider.loadThumbnailWithKs = false; + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + describe('session not set', () => { + it('should return false when session not set', () => { + kalturaPlayer.shouldAddKs().should.equals(false); + }); + }); + describe('anonymous session', () => { + it('should return false when loadThumbnailWithKs is false', () => { + kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); + kalturaPlayer.shouldAddKs().should.equals(false); + kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(false); + }); + }); + describe('user session', () => { + it('should return false when loadThumbnailWithKs is false', () => { + kalturaPlayer.setMedia(mediaWithUserSession); + kalturaPlayer.shouldAddKs().should.equals(false); + kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(false); + }); + }); + }); + + describe('loadThumbnailWithKs is true', () => { + beforeEach(() => { + config.provider.loadThumbnailWithKs = true; + kalturaPlayer = setup(config); + }); + afterEach(function () { + config.provider.loadThumbnailWithKs = false; + kalturaPlayer.destroy(); + }); + describe('session not set', () => { + it('should return false when session not set', () => { + kalturaPlayer.shouldAddKs().should.equals(false); + }); + }); + describe('anonymous session', () => { + it('should return false for anonymous session when called without mediaConfig parameter', () => { + kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); + kalturaPlayer.shouldAddKs().should.equals(false); + }); + it('should return false for anonymous session when called with mediaConfig parameter', () => { + kalturaPlayer.setMedia(mediaWithUserSession); + kalturaPlayer.shouldAddKs(MediaMockData.MediaConfig['0_wifqaipd']).should.equals(false); + }); + }); + describe('user session', () => { + it('should return true for user session when called without mediaConfig parameter', () => { + kalturaPlayer.setMedia(mediaWithUserSession); + kalturaPlayer.shouldAddKs().should.equals(true); + }); + it('should return true for user session when called with mediaConfig parameter', () => { + kalturaPlayer.setMedia(MediaMockData.MediaConfig['0_wifqaipd']); + kalturaPlayer.shouldAddKs(mediaWithUserSession).should.equals(true); + }); + }); + }); + }); + }); + describe('selectedSource', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + }); + + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should get the selectedSource', function (done) { + kalturaPlayer.addEventListener(kalturaPlayer.Event.SOURCE_SELECTED, event => { + kalturaPlayer.selectedSource.should.equal(event.payload.selectedSource[0]); + done(); + }); + kalturaPlayer.setMedia({sources: SourcesConfig.Mp4}); + kalturaPlayer.selectedSource.should.equal(kalturaPlayer.sources.progressive[0]); + }); + }); + describe('setSourcesMetadata', function () { + const entryId = '0_wifqaipd'; + beforeEach(function () { + kalturaPlayer = setup(config); + sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function (info) { + const id = info.playlistId || info.entryId; + return id + ? Promise.resolve(MediaMockData.MediaConfig[id]) + : Promise.reject({ + success: false, + data: 'Missing mandatory parameter' + }); + }); + }); + + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should set the sources metadata with the provided epgId', done => { + kalturaPlayer.loadMedia({entryId}).then(() => { + kalturaPlayer.configure({sources: {metadata: {epgId: '54321'}}}); + kalturaPlayer.setSourcesMetadata({epgId: '12345'}); + try { + kalturaPlayer.config.sources.metadata.epgId.should.equals('12345'); + kalturaPlayer.sources.metadata.epgId.should.equals('12345'); + done(); + } catch (e) { + done(e); + } + }); + }); + }); + }); + + describe('playlist api', function () { + describe('loadPlaylist', function () { + const playlistId = '0_wckoqjnn'; + + beforeEach(function () { + kalturaPlayer = setup(config); + sinon.stub(kalturaPlayer._provider, 'getPlaylistConfig').callsFake(function (playlistInfo) { + return playlistInfo.playlistId + ? Promise.resolve(PlaylistMockData.playlistByID) + : Promise.reject({success: false, data: 'Missing mandatory parameter'}); + }); + }); + + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should get playlist by id from the provider and set it - without config', function (done) { + kalturaPlayer.loadPlaylist({playlistId: playlistId}).then(playlistData => { + playlistData.id.should.equal(playlistId); + kalturaPlayer.playlist.id.should.equal(playlistData.id); + done(); + }); + }); + + it('should get playlist by id from the provider and set it - with config', function (done) { + kalturaPlayer.loadPlaylist({playlistId: playlistId}, {options: {autoContinue: false}}).then(playlistData => { + playlistData.id.should.equal(playlistId); + kalturaPlayer.playlist.id.should.equal(playlistData.id); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + done(); + }); + }); + + it('should reject and throw an error when the provider request failed', function (done) { + let errorEventTriggered = false; + kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { + errorEventTriggered = true; + }); + kalturaPlayer.loadPlaylist({}).catch(error => { + error.data.should.equal('Missing mandatory parameter'); + error.success.should.be.false; + errorEventTriggered.should.be.true; + done(); + }); + }); + }); + + describe('loadPlaylistByEntryList', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + sinon.stub(kalturaPlayer._provider, 'getEntryListConfig').callsFake(function (entryList) { + return entryList.entries + ? Promise.resolve(PlaylistMockData.playlistByEntryList) + : Promise.reject({success: false, data: 'Missing mandatory parameter'}); + }); + }); + + afterEach(() => { + kalturaPlayer.destroy(); + }); + + it('should get playlist by entry list from the provider and set it - without config', function (done) { + kalturaPlayer.loadPlaylistByEntryList({entries: ['0_nwkp7jtx', '0_wifqaipd']}).then(playlistData => { + playlistData.id.should.equal('a1234'); + kalturaPlayer.playlist.id.should.equal('a1234'); + done(); + }); + }); + + it('should get playlist by entry list from the provider and set it- with config', function (done) { + kalturaPlayer.loadPlaylistByEntryList({entries: ['0_nwkp7jtx', '0_wifqaipd']}, {options: {autoContinue: false}}).then(playlistData => { + playlistData.id.should.equal('a1234'); + kalturaPlayer.playlist.id.should.equal('a1234'); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + done(); + }); + }); + + it('should reject and throw an error when the provider request failed', function (done) { + let errorEventTriggered = false; + kalturaPlayer.addEventListener(kalturaPlayer.Event.ERROR, () => { + errorEventTriggered = true; + }); + kalturaPlayer.loadPlaylistByEntryList({}).catch(error => { + error.data.should.equal('Missing mandatory parameter'); + error.success.should.be.false; + errorEventTriggered.should.be.true; + done(); + }); + }); + }); + + describe('setPlaylist', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should set the playlist and evaluate the plugins - without config and entry list', function () { + kalturaPlayer.setPlaylist(PlaylistMockData.playlistByEntryList); + kalturaPlayer.config.plugins.kava.playlistId.should.equal('a1234'); + kalturaPlayer.playlist.id.should.equal('a1234'); + }); + + it('should set the playlist and evaluate the plugins - with config and entry list', function () { + kalturaPlayer.setPlaylist(PlaylistMockData.playlistByEntryList, {options: {autoContinue: false}}, [ + {entryId: '0_nwkp7jtx'}, + {entryId: '0_wifqaipd'} + ]); + kalturaPlayer.config.plugins.kava.playlistId.should.equal('a1234'); + kalturaPlayer.playlist.id.should.equal('a1234'); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + kalturaPlayer._playlistManager._mediaInfoList.length.should.equal(2); + }); + }); + + describe('load playlist by setup config', function () { + beforeEach(function () { + config.playlist = PlaylistMockData.playlistByConfig; + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should set the configured playlist', function () { + kalturaPlayer.playlist.id.should.equal('b1234'); + kalturaPlayer.playlist.metadata.name.should.equal('my playlist name'); + kalturaPlayer.playlist.metadata.description.should.equal('my playlist desc'); + kalturaPlayer.playlist.poster.should.equal('http://cdntesting.qa.mkaltura.com/p/1091/sp/0/thumbnail/entry_id/0_wckoqjnn/version/100162'); + kalturaPlayer.playlist.items.length.should.equal(3); + kalturaPlayer.playlist.countdown.duration.should.equal(20); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + (kalturaPlayer.selectedSource === null).should.be.false; + }); + }); + + describe('load playlist by configure', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should set the configured playlist', function (done) { + kalturaPlayer.addEventListener('kaltura-player-playlistloaded', event => { + event.payload.playlist.id.should.equal('b1234'); + kalturaPlayer.playlist.id.should.equal('b1234'); + kalturaPlayer.playlist.metadata.name.should.equal('my playlist name'); + kalturaPlayer.playlist.metadata.description.should.equal('my playlist desc'); + kalturaPlayer.playlist.poster.should.equal('http://cdntesting.qa.mkaltura.com/p/1091/sp/0/thumbnail/entry_id/0_wckoqjnn/version/100162'); + kalturaPlayer.playlist.items.length.should.equal(3); + kalturaPlayer.playlist.countdown.duration.should.equal(20); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + done(); + }); + kalturaPlayer.configure({playlist: PlaylistMockData.playlistByConfig}); + }); + }); + + describe('mix setup config and api', function () { + beforeEach(function () { + config.playlist = { + countdown: { + duration: 20, + showing: true + }, + options: { + autoContinue: false + } + }; + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should load the playlist with the preset config', function () { + kalturaPlayer.setPlaylist({id: 'a12345', items: []}, {countdown: {showing: false}}); + kalturaPlayer.playlist.id.should.equal('a12345'); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + kalturaPlayer.playlist.countdown.showing.should.be.false; + kalturaPlayer.playlist.countdown.duration.should.equal(20); + }); + }); + + describe('mix configure and api', function () { + beforeEach(function () { + kalturaPlayer = setup(config); + }); + afterEach(function () { + kalturaPlayer.destroy(); + }); + + it('should load the playlist with the preset config', function () { + kalturaPlayer.configure({ + playlist: { + countdown: { + duration: 20, + showing: true + }, + options: { + autoContinue: false + } + } + }); + kalturaPlayer.setPlaylist({id: 'a12345', items: []}, {countdown: {showing: false}}); + kalturaPlayer.playlist.id.should.equal('a12345'); + kalturaPlayer.playlist.options.autoContinue.should.be.false; + kalturaPlayer.playlist.countdown.showing.should.be.false; + kalturaPlayer.playlist.countdown.duration.should.equal(20); + }); + }); + }); + + describe('plugins lifecycle', () => { + let player; + beforeEach(() => { + PluginManager.register('colors', ColorsPlugin); + PluginManager.register('numbers', NumbersPlugin); + }); + + afterEach(() => { + PluginManager.unRegister('colors'); + PluginManager.unRegister('numbers'); + }); + + it('should load 2 plugins on initial config and configure them on configure', function () { + player = new Player({ + ui: {}, + provider: {}, + plugins: { + colors: { + size: 5 + }, + numbers: { + size: 20 + } + } + }); + player._pluginManager.get('colors').should.exist; + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(2); + player.config.plugins.colors.should.deep.equals({ + size: 5, + favouriteColor: 'green' + }); + player.config.plugins.numbers.should.deep.equals({ + size: 20, + firstCellValue: 4, + lastCellValue: 6 + }); + player.configure({ + plugins: { + colors: { + size: 50 + }, + numbers: { + size: 200 + } + } + }); + player._pluginManager.get('colors').should.exist; + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(2); + player.config.plugins.colors.should.deep.equals({ + size: 50, + favouriteColor: 'green' + }); + player.config.plugins.numbers.should.deep.equals({ + size: 200, + firstCellValue: 4, + lastCellValue: 6 + }); + }); + + it('should load 1st plugin on initial config, load 2nd plugin and configure the 1st on configure', function () { + player = new Player({ + ui: {}, + provider: {}, + plugins: { + numbers: { + size: 20 + } + } + }); + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.numbers.should.deep.equals({ + size: 20, + firstCellValue: 4, + lastCellValue: 6 + }); + player.configure({ + plugins: { + colors: { + size: 50 + }, + numbers: { + size: 200 + } + } + }); + player._pluginManager.get('colors').should.exist; + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(2); + player.config.plugins.colors.should.deep.equals({ + size: 50, + favouriteColor: 'green' + }); + player.config.plugins.numbers.should.deep.equals({ + size: 200, + firstCellValue: 4, + lastCellValue: 6 + }); + }); + + it('should create player without plugins, load plugins on configure', function () { + player = new Player({ + ui: {}, + plugins: {}, + advertising: { + adBreaks: [] + }, + provider: {} + }); + Object.keys(player._pluginManager._plugins).length.should.equals(0); + player.config.plugins.should.deep.equals({}); + player.configure({ + plugins: { + colors: { + size: 50 + }, + numbers: { + size: 200 + } + } + }); + player._pluginManager.get('colors').should.exist; + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(2); + player.config.plugins.colors.should.deep.equals({ + size: 50, + favouriteColor: 'green' + }); + player.config.plugins.numbers.should.deep.equals({ + size: 200, + firstCellValue: 4, + lastCellValue: 6 + }); + }); + + it('should create player without plugins, load 1st plugin on configure, configure 1st plugin with/after sources', function () { + player = new Player({ + ui: {}, + plugins: {}, + provider: {} + }); + Object.keys(player._pluginManager._plugins).length.should.equals(0); + player.config.plugins.should.deep.equals({}); + player.configure({ + plugins: { + numbers: { + size: 200 + } + } + }); + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.numbers.should.deep.equals({ + size: 200, + firstCellValue: 4, + lastCellValue: 6 + }); + player.configure({ + plugins: { + numbers: { + size: 2, + firstCellValue: 3 + } + } + }); + player.setMedia({ + sources: SourcesConfig.Mp4 + }); + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.numbers.should.deep.equals({ + size: 2, + firstCellValue: 3, + lastCellValue: 6 + }); + player.configure({ + plugins: { + numbers: { + size: 78 + } + } + }); + player.config.plugins.numbers.should.deep.equals({ + size: 78, + firstCellValue: 3, + lastCellValue: 6 + }); + }); + + it('should create player with plugin and fail to configure other plugin after sources', function () { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + numbers: { + size: 2, + firstCellValue: 3 + } + } + }); + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.should.deep.equals({ + numbers: { + size: 2, + firstCellValue: 3, + lastCellValue: 6 + } + }); + player.configure({ + plugins: { + colors: { + size: 200 + } + } + }); + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.should.deep.equals({ + numbers: { + size: 2, + firstCellValue: 3, + lastCellValue: 6 + } + }); + }); + + it('should create the plugin before playlist source selected', function () { + const eventManager = new EventManager(); + player = new Player({ + ui: {}, + provider: {}, + playlist: { + id: '1234', + metdata: {}, + items: [ + { + sources: SourcesConfig.Mp4 + } + ] + }, + plugins: { + numbers: { + size: 2, + firstCellValue: 3 + } + } + }); + eventManager.listen(player, CoreEventType.SOURCE_SELECTED, () => { + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.should.deep.equals({ + numbers: { + size: 2, + firstCellValue: 3, + lastCellValue: 6 + } + }); + }); + }); + + it('should create player with plugin and fail to configure other plugin after playlist source selected', function () { + player = new Player({ + ui: {}, + provider: {}, + playlist: { + id: '1234', + metdata: {}, + items: [ + { + sources: SourcesConfig.Mp4 + } + ] + }, + plugins: { + numbers: { + size: 2, + firstCellValue: 3 + } + } + }); + player._pluginManager.get('numbers').should.exist; + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.should.deep.equals({ + numbers: { + size: 2, + firstCellValue: 3, + lastCellValue: 6 + } + }); + player.configure({ + plugins: { + colors: { + size: 200 + } + } + }); + Object.keys(player._pluginManager._plugins).length.should.equals(1); + player.config.plugins.should.deep.equals({ + numbers: { + size: 2, + firstCellValue: 3, + lastCellValue: 6 + } + }); + }); + }); + + describe('async plugins loading', () => { + let player; + beforeEach(() => { + PluginManager.register('asyncResolve', AsyncResolvePlugin); + PluginManager.register('asyncReject', AsyncRejectPlugin); + }); + + afterEach(() => { + PluginManager.unRegister('asyncResolve'); + PluginManager.unRegister('asyncReject'); + player.destroy(); + }); + + it('should create player with async resolve plugin - check async load', done => { + try { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + asyncResolve: {} + } + }); + player._pluginManager.get('asyncResolve').should.exist; + sinon.stub(player._localPlayer, '_load').callsFake(function () { + player._pluginManager.get('asyncResolve').ready.then(() => { + done(); + }); + }); + player.load(); + } catch (e) { + done(e); + } + }); + + it('should create player with async resolve plugin - check async play', done => { + try { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + asyncResolve: {} + } + }); + player._pluginManager.get('asyncResolve').should.exist; + sinon.stub(player._localPlayer, '_play').callsFake(function () { + player._pluginManager.get('asyncResolve').ready.then(() => { + done(); + }); + }); + player.play(); + } catch (e) { + done(e); + } + }); + + it('should create player with async reject plugin - check async load', done => { + try { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + asyncReject: {} + } + }); + player._pluginManager.get('asyncReject').should.exist; + sinon.stub(player._localPlayer, '_load').callsFake(function () { + player._pluginManager.get('asyncReject').ready.catch(() => { + done(); + }); + }); + player.load(); + } catch (e) { + done(e); + } + }); + + it('should create player with async reject plugin - check async play', done => { + try { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + asyncReject: {} + } + }); + player._pluginManager.get('asyncReject').should.exist; + sinon.stub(player._localPlayer, '_play').callsFake(function () { + player._pluginManager.get('asyncReject').ready.catch(() => { + done(); + }); + }); + player.play(); + } catch (e) { + done(e); + } + }); + + it('should create player with async resolve plugin and reject plugin - check async play', done => { + try { + player = new Player({ + ui: {}, + provider: {}, + sources: SourcesConfig.Mp4, + plugins: { + asyncReject: {}, + asyncResolve: {} + } + }); + player._pluginManager.get('asyncReject').should.exist; + player._pluginManager.get('asyncResolve').should.exist; + sinon.stub(player._localPlayer, '_load').callsFake(function () { + player._pluginManager.get('asyncResolve').ready.then(() => { + player._pluginManager.get('asyncReject').ready.catch(() => { + done(); + }); + }); + }); + player.load(); + } catch (e) { + done(e); + } + }); + }); + + describe('events', function () { + let player; + + it('should fire PLAYBACK_START on play', done => { + player = new Player({ + ui: {}, + provider: {} + }); + player.addEventListener(player.Event.PLAYBACK_START, () => { + done(); + }); + player.play(); + }); + + it('should fire PLAYBACK_START on autoplay', done => { + player = new Player({ + ui: {}, + provider: {} + }); + player.addEventListener(player.Event.PLAYBACK_START, () => { + done(); + }); + player.configure({ + playback: { + autoplay: true + } + }); + player.setMedia({ + sources: SourcesConfig.Mp4 + }); + }); + + it('should fire auto play failed and show the poster once get AD_AUTOPLAY_FAILED', done => { + player = new Player({ + ui: {}, + provider: {}, + playback: { + autoplay: true + } + }); + player.addEventListener(player.Event.AUTOPLAY_FAILED, event => { + try { + player._localPlayer.posterManager._el.style.display.should.equal(''); + event.payload.error.should.equal('mock failure'); + done(); + } catch (e) { + done(e); + } + }); + player.dispatchEvent(new FakeEvent(player.Event.AD_AUTOPLAY_FAILED, {error: 'mock failure'})); + }); + }); + + describe('evaluate plugins config', function () { + beforeEach(() => { + PluginManager.register('colors', ColorsPlugin); + }); + + afterEach(() => { + PluginManager.unRegister('colors'); + }); + + it('should pass deep object as plugin config', () => { + const test = {a: {b: {c: 'd'}}}; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + }); + + it('should pass class as plugin config', () => { + const test = class Test { + constructor() {} + + print() {} + }; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + }); + + it('should pass class instance as plugin config', done => { + const test = class Test { + constructor() {} + + check() { + done(); + } + }; + const config = { + plugins: { + colors: { + prop: new test() + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + player.plugins.colors.config.prop.check(); + }); + + it('should pass function as plugin config', done => { + const test = () => { + done(); + }; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + player.plugins.colors.config.prop(); + }); + + describe('changeMedia and multi players', function () { + const config = { + plugins: {}, + ui: {}, + provider: {} + }; + let player; + const entryId = '0_wifqaipd'; + const entryId2 = '0_nwkp7jtx'; + + beforeEach(() => { + player = new Player(Utils.Object.mergeDeep({}, config)); + player._configEvaluator._pluginConfigStore._config = { + colors: { + entryId: '{{entryId}}', + partnerId: '{{partnerId}}', + entryName: '{{entryName}}', + entryType: '{{entryType}}' + } + }; + player.configure({ + plugins: { + colors: { + entryName: '{{entryType}}', + entryType: 'custom' + } + } + }); + sinon.stub(Provider.prototype, 'getMediaConfig').callsFake(info => { + const id = info.playlistId || info.entryId; + return id + ? Promise.resolve(MediaMockData.MediaConfig[id]) + : Promise.reject({ + success: false, + data: 'Missing mandatory parameter' + }); + }); + }); + + afterEach(() => { + sandbox.restore(); + Provider.prototype.getMediaConfig.restore(); + player.destroy(); + }); + + it('should evaluate the plugin config - first media', done => { + player.loadMedia({entryId}).then(() => { + try { + player.plugins.colors.config.entryId.should.equals(entryId); + player.plugins.colors.config.partnerId.should.equals(1091); + player.plugins.colors.config.entryName.should.equals('Vod'); + player.plugins.colors.config.entryType.should.equals('custom'); + done(); + } catch (e) { + done(e); + } + }); + }); + + it('should evaluate the default plugin config - second media', done => { + player.loadMedia({entryId}).then(() => { + player.loadMedia({entryId: entryId2}).then(() => { + try { + player.plugins.colors.config.entryId.should.equals(entryId2); + player.plugins.colors.config.partnerId.should.equals(1091); + player.plugins.colors.config.entryName.should.equals('Live'); + player.plugins.colors.config.entryType.should.equals('custom'); + done(); + } catch (e) { + done(e); + } + }); + }); + }); + + it('should plugin from setMedia be available after sources selected', () => { + PluginManager.register('numbers', NumbersPlugin); + player.setMedia({sources: SourcesConfig.Mp4, plugins: {numbers: {}}}); + (player.plugins.numbers !== undefined).should.be.true; + (player.plugins.numbers !== null).should.be.true; + player.plugins.numbers.should.be.instanceOf(NumbersPlugin); + PluginManager.unRegister('numbers', NumbersPlugin); + }); + + it('should evaluate the plugin config on source selected', done => { + player.addEventListener(player.Event.SOURCE_SELECTED, () => { + try { + player.plugins.colors.config.entryId.should.equals(entryId); + player.plugins.colors.config.partnerId.should.equals(1091); + player.plugins.colors.config.entryName.should.equals('Vod'); + player.plugins.colors.config.entryType.should.equals('custom'); + done(); + } catch (e) { + done(e); + } + }); + player.loadMedia({entryId}); + }); + + it('should evaluate the configured plugin config - second media', done => { + player.loadMedia({entryId}).then(() => { + player.configure({ + plugins: { + colors: { + partnerId: '{{entryId}}', + entryName: 'name' + } + } + }); + player.loadMedia({entryId: entryId2}).then(() => { + try { + player.plugins.colors.config.entryId.should.equals(entryId2); + player.plugins.colors.config.partnerId.should.equals(entryId2); + player.plugins.colors.config.entryName.should.equals('name'); + player.plugins.colors.config.entryType.should.equals('custom'); + done(); + } catch (e) { + done(e); + } + }); + }); + }); + + it('should evaluate the plugin config - another player', done => { + const player2 = new Player( + Utils.Object.mergeDeep( + {}, + { + plugins: { + colors: {} + }, + ui: {}, + provider: {} + } + ) + ); + player2._configEvaluator._pluginConfigStore._config = { + colors: { + entryId: '{{entryId}}', + partnerId: '{{partnerId}}' + } + }; + player2.loadMedia({entryId}).then(() => { + try { + player2.plugins.colors.config.entryId.should.equals(entryId); + player2.plugins.colors.config.partnerId.should.equals(1091); + done(); + } catch (e) { + done(e); + } + }); + }); + }); + }); +}); diff --git a/tests/e2e/common/mock-data/images.js b/tests/e2e/mock-data/images.js similarity index 100% rename from tests/e2e/common/mock-data/images.js rename to tests/e2e/mock-data/images.js diff --git a/tests/e2e/common/mock-data/media.js b/tests/e2e/mock-data/media.js similarity index 100% rename from tests/e2e/common/mock-data/media.js rename to tests/e2e/mock-data/media.js diff --git a/tests/e2e/common/mock-data/playlist.js b/tests/e2e/mock-data/playlist.js similarity index 100% rename from tests/e2e/common/mock-data/playlist.js rename to tests/e2e/mock-data/playlist.js diff --git a/tests/e2e/common/ott/player-defaults.spec.js b/tests/e2e/ott/player-defaults.spec.js similarity index 92% rename from tests/e2e/common/ott/player-defaults.spec.js rename to tests/e2e/ott/player-defaults.spec.js index 8daed17f8..c1f91677b 100644 --- a/tests/e2e/common/ott/player-defaults.spec.js +++ b/tests/e2e/ott/player-defaults.spec.js @@ -1,4 +1,4 @@ -import {getDefaultRedirectOptions} from '../../../../src/ott/player-defaults'; +import {getDefaultRedirectOptions} from '../../../src/ott/player-defaults'; describe('redirectExternalStreamsHandler', function () { it('should return the default', function () { diff --git a/tests/e2e/common/ott/poster.spec.js b/tests/e2e/ott/poster.spec.js similarity index 94% rename from tests/e2e/common/ott/poster.spec.js rename to tests/e2e/ott/poster.spec.js index 4af0c448f..c125793e7 100644 --- a/tests/e2e/common/ott/poster.spec.js +++ b/tests/e2e/ott/poster.spec.js @@ -1,4 +1,4 @@ -import {addKalturaPoster} from '../../../../src/ott/poster'; +import {addKalturaPoster} from '../../../src/ott/poster'; describe('addKalturaPoster', function () { it('should change poster of mediaSources to string', function () { diff --git a/tests/e2e/common/ovp/player-defaults.spec.js b/tests/e2e/ovp/player-defaults.spec.js similarity index 98% rename from tests/e2e/common/ovp/player-defaults.spec.js rename to tests/e2e/ovp/player-defaults.spec.js index 0f4438631..0cc756173 100644 --- a/tests/e2e/common/ovp/player-defaults.spec.js +++ b/tests/e2e/ovp/player-defaults.spec.js @@ -1,4 +1,4 @@ -import {getDefaultRedirectOptions} from '../../../../src/ovp/player-defaults'; +import {getDefaultRedirectOptions} from '../../../src/ovp/player-defaults'; import {Env, MediaType} from '@playkit-js/playkit-js'; describe('getDefaultRedirectOptions', function () { diff --git a/tests/e2e/common/ovp/poster.spec.js b/tests/e2e/ovp/poster.spec.js similarity index 97% rename from tests/e2e/common/ovp/poster.spec.js rename to tests/e2e/ovp/poster.spec.js index 5b297e162..a73c8d12e 100644 --- a/tests/e2e/common/ovp/poster.spec.js +++ b/tests/e2e/ovp/poster.spec.js @@ -1,6 +1,6 @@ -import {addKalturaPoster} from '../../../../src/ovp/poster'; -import * as TestUtils from '../../../utils/test-utils'; -import {setup} from '../../../../src'; +import {addKalturaPoster} from '../../../src/ovp/poster'; +import * as TestUtils from '../../utils/test-utils'; +import {setup} from '../../../src'; import {Provider} from '@playkit-js/playkit-js-providers'; import {Images} from '../mock-data/images'; diff --git a/tsconfig.json b/tsconfig.json index 76acb3aa1..cb9ca9811 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,8 @@ "strict": false, "strictNullChecks": true, "strictPropertyInitialization": true, + "resolveJsonModule": true, + "esModuleInterop": true, "lib": [ "dom", "es2015", diff --git a/webpack.config.js b/webpack.config.js index 1e25d0538..10de221b9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -44,7 +44,8 @@ module.exports = (env, { mode }) => { module: { rules: [ { - test: /\.ts/, + test: /\.(ts|js)$/, // Match both .ts and .js files + // test: /\.ts/, exclude: /node_modules/, use: { loader: 'babel-loader',