Skip to content

Commit

Permalink
Added some UTs to Player.js
Browse files Browse the repository at this point in the history
Includes a minor refactoring
  • Loading branch information
moay committed Oct 22, 2015
1 parent af26f27 commit 24b789a
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 16 deletions.
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var fs = require('fs');
var browserify = require('browserify');
var babelify = require("babelify");
var release = require('gulp-github-release');
var notifierReporter = require('mocha-notifier-reporter');
var getPackageJson = function () {
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
};
Expand Down Expand Up @@ -191,5 +192,7 @@ gulp.task('release', function(){

gulp.task('test', function(){
return gulp.src('./test/*.js')
.pipe(plugins.mocha());
.pipe(plugins.mocha({
reporter: notifierReporter.decorate('spec')
}));
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"karma": "^0.13.10",
"mocha": "^2.3.2",
"mocha-jsdom": "^1.0.0",
"mocha-notifier-reporter": "^0.1.1",
"mockery": "^1.4.0",
"sinon": "^1.16.1",
"sinon-chai": "^2.8.0",
Expand Down
47 changes: 34 additions & 13 deletions src/js/afterglow/components/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class Player {
}
}

/**
* Applies basic parameters to the videoelement to make it well usable for video.js
* @return {void}
*/
applyParameters(){
// Make lightboxplayer not overscale
if(this.videoelement.getAttribute("data-overscale") == "false"){
Expand All @@ -107,43 +111,60 @@ class Player {
// Apply some responsive stylings
if(this.videoelement.getAttribute("data-autoresize") === 'fit' || this.videoelement.hasClass("responsive")){
this.videoelement.addClass("vjs-responsive");
if(this.videoelement.getAttribute("data-ratio")){
var ratio = this.videoelement.getAttribute("data-ratio");
}
else if(!this.videoelement.getAttribute("height") || !this.videoelement.getAttribute("width"))
{
console.error("Please provide witdh and height for your video element.")
}
else{
var ratio = this.videoelement.getAttribute("height") / this.videoelement.getAttribute("width");
}
let ratio = this.calculateRatio();
this.videoelement.node.style.paddingTop = (ratio * 100)+"%";
this.videoelement.removeAttribute("height");
this.videoelement.removeAttribute("width");
this.videoelement.setAttribute("data-ratio",ratio);
}
}

/**
* Applies all needed classes to the videoelement in order to provide proper youtube playback
* @return {void}
*/
applyYoutubeClasses(){
let ie = this.util.ie().actualVersion;

this.videoelement.addClass("vjs-youtube");

// Check for native playback
if(document.querySelector('video').controls){
this.videoelement.addClass("vjs-using-native-controls");
}
// Add iOS class, just if is iPad
// Add iOS class for iOS. Should affect only iPad
if(/iPad|iPhone|iPod/.test(navigator.platform)){
this.videoelement.addClass("vjs-iOS");
}

// Check for IE9 - IE11
let ie = this.util.ie().actualVersion;
if(ie >= 8 && ie <= 11){ // @see afterglow-lib.js
this.videoelement.addClass("vjs-using-native-controls");
}
}

/**
* Calculates the players ratio based on the given value or on width/height
* @return {float}
*/
calculateRatio(){
if(this.videoelement.getAttribute("data-ratio")){
var ratio = this.videoelement.getAttribute("data-ratio");
}
else if(!this.videoelement.getAttribute("height") || !this.videoelement.getAttribute("width"))
{
console.error("Please provide witdh and height for your video element.");
return 0;
}
else{
var ratio = this.videoelement.getAttribute("height") / this.videoelement.getAttribute("width");
}
return parseFloat(ratio);
}

/**
* Destroys the player instance and disposes it.
* @return {void}
*/
destroy(){
if(!this.videojs.paused()){
this.videojs.pause();
Expand Down
5 changes: 5 additions & 0 deletions test/test.2.lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ describe("Afterglow Lightbox", () => {
let res = lightbox.getPlayer();
res.should.equal('test');
});

it('should return undefined if the player does not exist', () => {
let res = lightbox.getPlayer();
expect(res).to.be.undefined;
})
});

describe('resize() with regular players', () => {
Expand Down

0 comments on commit 24b789a

Please sign in to comment.