From 95bf37be8f4d87b9e8b16cd3bfc5bbb5ade0a85a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 2 Jan 2018 11:44:54 +0100 Subject: [PATCH] implementing DiscussionViewer test, found an issue with slashes in the paste or comment IDs (as per Base64 encoding) --- js/test/DiscussionViewer.js | 112 +++++++++++++++--------------------- 1 file changed, 47 insertions(+), 65 deletions(-) diff --git a/js/test/DiscussionViewer.js b/js/test/DiscussionViewer.js index 38016723..9e472f68 100644 --- a/js/test/DiscussionViewer.js +++ b/js/test/DiscussionViewer.js @@ -2,86 +2,68 @@ var common = require('../common'); describe('DiscussionViewer', function () { - describe('setAttachment, showAttachment, removeAttachment, hideAttachment, hideAttachmentPreview, hasAttachment, getAttachment & moveAttachmentTo', function () { + describe('handleNotification, addComment, finishDiscussion, prepareNewDiscussion, getReplyMessage, getReplyNickname, getReplyCommentId & highlightComment', function () { this.timeout(30000); before(function () { cleanup(); }); jsc.property( - 'displays & hides data as requested', - common.jscMimeTypes(), - jsc.nearray(common.jscBase64String()), - 'string', - 'string', - 'string', - function (mimeType, base64, filename, prefix, postfix) { + 'displays & hides comments as requested', + jsc.array( + jsc.record({ + id: jsc.nearray(common.jscBase64String()), + parentid: jsc.nearray(common.jscBase64String()), + data: jsc.string, + meta: jsc.record({ + nickname: jsc.string, + postdate: jsc.nat, + vizhash: jsc.string + }) + }) + ), + function (comments) { var clean = jsdom(), - data = 'data:' + mimeType + ';base64,' + base64.join(''), - isImage = mimeType.substring(0, 6) === 'image/', results = []; - prefix = prefix.replace(/%(s|d)/g, '%%'); - postfix = postfix.replace(/%(s|d)/g, '%%'); $('body').html( - '' + '

Discussion

' + + '
' + + '
' + + '
name' + + '0000-00-00
' + + '
c
' + + '' + + '

' + + '' + + '

' ); - $.PrivateBin.AttachmentViewer.init(); + $.PrivateBin.DiscussionViewer.init(); results.push( - !$.PrivateBin.AttachmentViewer.hasAttachment() && - $('#attachment').hasClass('hidden') && - $('#attachmentPreview').hasClass('hidden') + !$('#discussion').hasClass('hidden') ); - if (filename.length) { - $.PrivateBin.AttachmentViewer.setAttachment(data, filename); - } else { - $.PrivateBin.AttachmentViewer.setAttachment(data); - } - var attachement = $.PrivateBin.AttachmentViewer.getAttachment() + $.PrivateBin.DiscussionViewer.prepareNewDiscussion(); results.push( - $.PrivateBin.AttachmentViewer.hasAttachment() && - $('#attachment').hasClass('hidden') && - $('#attachmentPreview').hasClass('hidden') && - attachement[0] === data && - attachement[1] === filename + $('#discussion').hasClass('hidden') ); - $.PrivateBin.AttachmentViewer.showAttachment(); + comments.forEach(function (originalComment) { + var comment = { + id: originalComment.id.join(''), + parentid: originalComment.parentid.join(''), + data: originalComment.data, + meta: originalComment.meta + } + $.PrivateBin.DiscussionViewer.addComment(comment, comment.data, comment.meta.nickname); + }); results.push( - !$('#attachment').hasClass('hidden') && - (isImage ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) - ); - $.PrivateBin.AttachmentViewer.hideAttachment(); - results.push( - $('#attachment').hasClass('hidden') && - (isImage ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) - ); - if (isImage) { - $.PrivateBin.AttachmentViewer.hideAttachmentPreview(); - results.push($('#attachmentPreview').hasClass('hidden')); - } - $.PrivateBin.AttachmentViewer.showAttachment(); - results.push( - !$('#attachment').hasClass('hidden') && - (isImage ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) - ); - var element = $('
'); - $.PrivateBin.AttachmentViewer.moveAttachmentTo(element, prefix + '%s' + postfix); - if (filename.length) { - results.push( - element.children()[0].href === data && - element.children()[0].getAttribute('download') === filename && - element.children()[0].text === prefix + filename + postfix - ); - } else { - results.push(element.children()[0].href === data); - } - $.PrivateBin.AttachmentViewer.removeAttachment(); - results.push( - $('#attachment').hasClass('hidden') && - $('#attachmentPreview').hasClass('hidden') + $('#discussion').hasClass('hidden') ); clean(); return results.every(element => element);