Skip to content

Commit

Permalink
testcase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Dec 4, 2015
1 parent 20b6b1d commit 28108cb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
14 changes: 7 additions & 7 deletions js/InteractiveVideoPlayerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ il.InteractiveVideoPlayerUtils = (function () {
{
username = '[' + username + ']';
}
if(parseInt(is_interactive, 10) == 1)
if(parseInt(is_interactive, 10) === 1)
{
username = '[' + question_text + ']';
}
return '<span class="comment_username"> ' + username + '</span>';
return '<span class="comment_username"> ' + username + '</span> ';
};

pro.builCommentTitleHtml = function (title)
Expand All @@ -98,12 +98,12 @@ il.InteractiveVideoPlayerUtils = (function () {
{
title = '';
}
return '<span class="comment_title">' + title + '</span>';
return '<span class="comment_title">' + title + '</span> ';
};

pro.builCommentTextHtml = function (text)
{
return '<span class="comment_text">' + text + '</span>';
return '<span class="comment_text">' + text + '</span> ';
};

pro.appendPrivateHtml = function (is_private)
Expand All @@ -117,19 +117,19 @@ il.InteractiveVideoPlayerUtils = (function () {
{
private_comment = '';
}
return '<span class="private_text">'+ private_comment + '</span>';
return '<span class="private_text">'+ private_comment + '</span> ';
};

pro.builCommentTagsHtml = function (tags)
{
var comment_tags = '';
if(tags === null)
if(tags == null)
{
comment_tags = '';
}
else
{
comment_tags = '<span class="tag">' + tags.split(',').join('</span> <span class="tag">') + '</span>';
comment_tags = '<span class="tag">' + tags.split(',').join('</span> <span class="tag">') + '</span> ';
}
return '<br/><div class="comment_tags">' + comment_tags + '</div>';
};
Expand Down
26 changes: 13 additions & 13 deletions js/jquery.InteractiveVideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ $( document ).ready(function() {
(function ($) {

il.Util.addOnLoad(function () {
var _lastTime = 0,
player = null,
var player = null,
interval = null;
InteractiveVideo.last_stopPoint = -1;
player = new MediaElementPlayer("#ilInteractiveVideo", {
Expand All @@ -71,25 +70,26 @@ $( document ).ready(function() {
media.addEventListener('seeked', function(e) {
$().debugPrinter('Player', 'seeked');
clearInterval(interval);
if (_lastTime > media.currentTime) {
_lastTime = media.currentTime;
if (InteractiveVideo.last_time > media.currentTime) {
InteractiveVideo.last_time = media.currentTime;
InteractiveVideo.last_stopPoint = -1;
} else if (_lastTime < media.currentTime) {
_lastTime = media.currentTime;
} else if (InteractiveVideo.last_time < media.currentTime) {
InteractiveVideo.last_time = media.currentTime;
}
il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(media.currentTime);
}, false);

media.addEventListener('pause', function(e) {
$().debugPrinter('Player', 'paused');
clearInterval(interval);
_lastTime = media.currentTime;
InteractiveVideo.last_time = media.currentTime;
}, false);

media.addEventListener('ended', function(e) {
$().debugPrinter('Player', 'video finished');
}, false);
media.addEventListener('playing', function(e) {
var cueTime, stop_video, i, j;
$().debugPrinter('Player', 'playing');
interval = setInterval(function () {
if (media.currentTime >= media.duration) {
Expand All @@ -99,15 +99,15 @@ $( document ).ready(function() {
if (!isNaN(media.currentTime) && media.currentTime > 0) {
// @todo: Evtl. use a better way to detect the relevant stopping point

for (var j = stopPoints.length - 1; j >= 0; j--)
for (j = stopPoints.length - 1; j >= 0; j--)
{
var cueTime = parseInt(stopPoints[j], 10);
if (cueTime >= _lastTime && cueTime <= media.currentTime)
cueTime = parseInt(stopPoints[j], 10);
if (cueTime >= InteractiveVideo.last_time && cueTime <= media.currentTime)
{
var stop_video = 0;
stop_video = 0;
if (InteractiveVideo.last_stopPoint < cueTime)
{
for (var i = 0; i < Object.keys(comments).length; i++)
for (i = 0; i < Object.keys(comments).length; i++)
{
if (comments[i].comment_time == cueTime)
{
Expand All @@ -134,7 +134,7 @@ $( document ).ready(function() {
InteractiveVideo.last_stopPoint = parseInt(cueTime, 10);
}
}
_lastTime = media.currentTime;
InteractiveVideo.last_time = media.currentTime;
}
}, 500);

Expand Down
20 changes: 10 additions & 10 deletions js/test/InteractiveVideoPlayerUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@ describe("InteractiveVideoPlayerUtils Tests", function () {
});

it("builCommentTextHtml must return html", function () {
var expec = '<span class="comment_text">My little text</span>';
var expec = '<span class="comment_text">My little text</span> ';
var value = il.InteractiveVideoPlayerUtils.protect.builCommentTextHtml('My little text');
expect(value).toEqual(expec);
});

it("builCommentTitleHtml must return html", function () {
var expec = '<span class="comment_title">My little text</span>';
var expec = '<span class="comment_title">My little text</span> ';
var value = il.InteractiveVideoPlayerUtils.protect.builCommentTitleHtml('My little text');
expect(value).toEqual(expec);
expec = '<span class="comment_title"></span>';
expec = '<span class="comment_title"></span> ';
value = il.InteractiveVideoPlayerUtils.protect.builCommentTitleHtml(null);
expect(value).toEqual(expec);
});

it("builCommentUsernameHtml must return html", function () {
var expec = '<span class="comment_username"> [Username]</span>';
var expec = '<span class="comment_username"> [Username]</span> ';
var value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('Username', 0);
expect(value).toEqual(expec);
expec = '<span class="comment_username"> [Question]</span>';
expec = '<span class="comment_username"> [Question]</span> ';
value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('Username', 1);
expect(value).toEqual(expec);
expec = '<span class="comment_username"> </span>';
expec = '<span class="comment_username"> </span> ';
value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('', 0);
expect(value).toEqual(expec);
});

it("builCommentPrivateHtml must return html", function () {
var expec = '<span class="private_text"> (private)</span>';
var expec = '<span class="private_text"> (private)</span> ';
var value = il.InteractiveVideoPlayerUtils.protect.appendPrivateHtml(1);
expect(value).toEqual(expec);
expec = '<span class="private_text"></span>';
expec = '<span class="private_text"></span> ';
value = il.InteractiveVideoPlayerUtils.protect.appendPrivateHtml(0);
expect(value).toEqual(expec);
});
Expand All @@ -70,7 +70,7 @@ describe("InteractiveVideoPlayerUtils Tests", function () {

it("builCommentTagsHtml must return html", function () {
var tags = 'Tag1, Tag2';
var expec = '<br/><div class="comment_tags"><span class="tag">Tag1</span> <span class="tag"> Tag2</span></div>';
var expec = '<br/><div class="comment_tags"><span class="tag">Tag1</span> <span class="tag"> Tag2</span> </div>';
var value = il.InteractiveVideoPlayerUtils.protect.builCommentTagsHtml(tags);
expect(value).toEqual(expec);
expec = '<br/><div class="comment_tags"></div>';
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("InteractiveVideoPlayerUtils Tests", function () {
loadFixtures('InteractiveVideoPlayerUtils_fixtures.html');
il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(1);
expect($("#ul_scroll").html()).toEqual(expec);
expec = '<li class="list_item_undefined"><time class="time"> <a onclick="il.InteractiveVideoPlayerUtils.jumpToTimeInVideo(1); return false;">undefined</a></time><span class="comment_username"> [undefined]</span><span class="comment_title">undefined</span><span class="comment_text">Text</span><span class="private_text"></span><br><div class="comment_tags"></div></li>';
expec = '<li class="list_item_undefined"><time class="time"> <a onclick="il.InteractiveVideoPlayerUtils.jumpToTimeInVideo(1); return false;">undefined</a></time><span class="comment_username"> [undefined]</span> <span class="comment_title">undefined</span> <span class="comment_text">Text</span> <span class="private_text"></span> <br><div class="comment_tags"></div></li>';
comments = [{comment_time: 1, comment_text: 'Text', is_interactive: 0, comment_tags: null}];
il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(5);
expect($("#ul_scroll").html()).toEqual(expec);
Expand Down
3 changes: 2 additions & 1 deletion templates/default/tpl.video_tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ <h3 class="ilHeader">{TXT_COMMENTS}</h3>
auto_resume : false,
pause_on_click_in_comment_field : true,
iv_debug : false,
last_stopPoint : -1
last_stopPoint : -1,
last_time : 0
};

$.fn.debugPrinter = function (message, element)
Expand Down

0 comments on commit 28108cb

Please sign in to comment.