From a95701bba8e50ea5219092ee3fc2e726d80e08a5 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 2 Jan 2018 15:38:37 +0100 Subject: [PATCH] completing DiscussionViewer testing --- js/privatebin.js | 2 +- js/test/DiscussionViewer.js | 64 ++++++++++++++++++++++++++++++------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index ec8aaa01..a9cc9312 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -977,7 +977,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { if (typeof customHandler === 'function') { var handlerResult = customHandler(alertType[id], $element, args, icon); if (handlerResult === true) { - // if it returs true, skip own handler + // if it returns true, skip own handler return; } if (handlerResult instanceof jQuery) { diff --git a/js/test/DiscussionViewer.js b/js/test/DiscussionViewer.js index 3176dbd7..8277dba8 100644 --- a/js/test/DiscussionViewer.js +++ b/js/test/DiscussionViewer.js @@ -2,7 +2,7 @@ var common = require('../common'); describe('DiscussionViewer', function () { - describe('handleNotification, addComment, finishDiscussion, prepareNewDiscussion, getReplyMessage, getReplyNickname, getReplyCommentId & highlightComment', function () { + describe('handleNotification, prepareNewDiscussion, addComment, finishDiscussion, getReplyMessage, getReplyNickname, getReplyCommentId & highlightComment', function () { this.timeout(30000); before(function () { cleanup(); @@ -12,8 +12,8 @@ describe('DiscussionViewer', function () { 'displays & hides comments as requested', jsc.array( jsc.record({ - id: jsc.nearray(common.jscAlnumString()), - parentid: jsc.nearray(common.jscAlnumString()), + idArray: jsc.nearray(common.jscAlnumString()), + parentidArray: jsc.nearray(common.jscAlnumString()), data: jsc.string, meta: jsc.record({ nickname: jsc.string, @@ -22,7 +22,13 @@ describe('DiscussionViewer', function () { }) }) ), - function (comments) { + 'nat', + 'bool', + 'string', + 'string', + jsc.elements(['loading', 'danger', 'other']), + 'nestring', + function (comments, commentKey, fadeOut, nickname, message, alertType, alert) { var clean = jsdom(), results = []; $('body').html( @@ -45,6 +51,7 @@ describe('DiscussionViewer', function () { 'aria-hidden="true"> ' ); + $.PrivateBin.Model.init(); $.PrivateBin.DiscussionViewer.init(); results.push( !$('#discussion').hasClass('hidden') @@ -53,18 +60,53 @@ describe('DiscussionViewer', function () { results.push( $('#discussion').hasClass('hidden') ); - comments.forEach(function (originalComment) { - var comment = { - id: originalComment.id.join(''), - parentid: originalComment.parentid.join(''), - data: originalComment.data, - meta: originalComment.meta - } + comments.forEach(function (comment) { + comment.id = comment.idArray.join(''); + comment.parentid = comment.parentidArray.join(''); $.PrivateBin.DiscussionViewer.addComment(comment, comment.data, comment.meta.nickname); }); results.push( $('#discussion').hasClass('hidden') ); + $.PrivateBin.DiscussionViewer.finishDiscussion(); + results.push( + !$('#discussion').hasClass('hidden') && + comments.length + 1 >= $('#commentcontainer').children().length + ); + if (comments.length > 0) { + if (commentKey >= comments.length) { + commentKey = commentKey % comments.length; + } + $.PrivateBin.DiscussionViewer.highlightComment(comments[commentKey].id, fadeOut); + results.push( + $('#comment_' + comments[commentKey].id).hasClass('highlight') + ); + } + $('#commentcontainer').find('button')[0].click(); + results.push( + !$('#reply').hasClass('hidden') + ); + $('#reply #nickname').val(nickname); + $('#reply #replymessage').val(message); + $.PrivateBin.DiscussionViewer.getReplyCommentId(); + results.push( + $.PrivateBin.DiscussionViewer.getReplyNickname() === $('#reply #nickname').val() && + $.PrivateBin.DiscussionViewer.getReplyMessage() === $('#reply #replymessage').val() + ); + var notificationResult = $.PrivateBin.DiscussionViewer.handleNotification(alertType == 'other' ? alert : alertType); + if (alertType == 'loading') { + results.push(notificationResult === false); + } else { + results.push( + alertType == 'danger' ? ( + notificationResult.hasClass('alert-danger') && + !notificationResult.hasClass('alert-info') + ) : ( + !notificationResult.hasClass('alert-danger') && + notificationResult.hasClass('alert-info') + ) + ); + } clean(); return results.every(element => element); } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 9957cf0b..dba34a9b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 1e815d08..d2f26d83 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): - +