Skip to content

Commit

Permalink
feat(FEC-8769): do not allow to create two players with the same targ…
Browse files Browse the repository at this point in the history
…et id (#218)

* add same target id setup validation

* fix tests
  • Loading branch information
odedhutzler authored Feb 18, 2019
1 parent 5f8f8e7 commit bac574f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ function validateTargetId(targetId: string): void {
if (!targetId) {
throw new Error(ValidationErrorType.TARGET_ID_REQUIRED);
}
if (!document.getElementById(targetId)) {
const targetIdElement = document.getElementById(targetId);
if (!targetIdElement) {
throw new Error(ValidationErrorType.DOM_ELEMENT_WITH_TARGET_ID_REQUIRED + targetId);
}
if (targetIdElement.getElementsByClassName(CONTAINER_CLASS_NAME).length > 0) {
throw new Error(ValidationErrorType.TARGET_ID_ALREADY_USED + targetId);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/common/utils/validation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const ValidationErrorType = {
INITIAL_CONFIG_REQUIRED: 'Must provide initial providers config',
PARTNER_ID_REQUIRED: 'Must provide partner id',
TARGET_ID_REQUIRED: 'Must provide target id',
DOM_ELEMENT_WITH_TARGET_ID_REQUIRED: 'Must provide DOM element with id of: '
DOM_ELEMENT_WITH_TARGET_ID_REQUIRED: 'Must provide DOM element with id of: ',
TARGET_ID_ALREADY_USED: 'The target id provided is already in use. Id: '
};

export {ValidationErrorType};
27 changes: 27 additions & 0 deletions test/src/kaltura-player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe('kaltura player api', function() {
});
});

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);
Expand Down Expand Up @@ -147,6 +151,10 @@ describe('kaltura player api', function() {
});
});

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);
Expand Down Expand Up @@ -188,6 +196,10 @@ describe('kaltura player api', function() {
});
});

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');
Expand Down Expand Up @@ -223,6 +235,9 @@ describe('kaltura player api', 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);
Expand All @@ -247,6 +262,9 @@ describe('kaltura player api', 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');
Expand All @@ -263,6 +281,9 @@ describe('kaltura player api', function() {
beforeEach(function() {
kalturaPlayer = setup(config);
});
afterEach(function() {
kalturaPlayer.destroy();
});

it('should set the configured playlist', function(done) {
kalturaPlayer.addEventListener('kaltura-player-playlistloaded', event => {
Expand Down Expand Up @@ -293,6 +314,9 @@ describe('kaltura player api', function() {
};
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}});
Expand All @@ -307,6 +331,9 @@ describe('kaltura player api', function() {
beforeEach(function() {
kalturaPlayer = setup(config);
});
afterEach(function() {
kalturaPlayer.destroy();
});

it('should load the playlist with the preset config', function() {
kalturaPlayer.configure({
Expand Down
2 changes: 1 addition & 1 deletion test/src/ovp/poster.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('addKalturaPoster', function() {

afterEach(function() {
sandbox.restore();
kalturaPlayer = null;
kalturaPlayer.destroy();
provider = null;
TestUtils.removeVideoElementsFromTestPage();
});
Expand Down
1 change: 1 addition & 0 deletions test/src/setup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('setup', function() {

afterEach(function() {
sandbox.restore();
kalturaPlayer.destroy();
kalturaPlayer = null;
TestUtils.removeVideoElementsFromTestPage();
});
Expand Down

0 comments on commit bac574f

Please sign in to comment.