implementing DiscussionViewer test, found an issue with slashes in the paste or comment IDs (as per Base64 encoding)
This commit is contained in:
parent
28f1f41c17
commit
95bf37be8f
@ -2,86 +2,68 @@
|
|||||||
var common = require('../common');
|
var common = require('../common');
|
||||||
|
|
||||||
describe('DiscussionViewer', function () {
|
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);
|
this.timeout(30000);
|
||||||
before(function () {
|
before(function () {
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
jsc.property(
|
jsc.property(
|
||||||
'displays & hides data as requested',
|
'displays & hides comments as requested',
|
||||||
common.jscMimeTypes(),
|
jsc.array(
|
||||||
jsc.nearray(common.jscBase64String()),
|
jsc.record({
|
||||||
'string',
|
id: jsc.nearray(common.jscBase64String()),
|
||||||
'string',
|
parentid: jsc.nearray(common.jscBase64String()),
|
||||||
'string',
|
data: jsc.string,
|
||||||
function (mimeType, base64, filename, prefix, postfix) {
|
meta: jsc.record({
|
||||||
|
nickname: jsc.string,
|
||||||
|
postdate: jsc.nat,
|
||||||
|
vizhash: jsc.string
|
||||||
|
})
|
||||||
|
})
|
||||||
|
),
|
||||||
|
function (comments) {
|
||||||
var clean = jsdom(),
|
var clean = jsdom(),
|
||||||
data = 'data:' + mimeType + ';base64,' + base64.join(''),
|
|
||||||
isImage = mimeType.substring(0, 6) === 'image/',
|
|
||||||
results = [];
|
results = [];
|
||||||
prefix = prefix.replace(/%(s|d)/g, '%%');
|
|
||||||
postfix = postfix.replace(/%(s|d)/g, '%%');
|
|
||||||
$('body').html(
|
$('body').html(
|
||||||
'<div id="attachment" role="alert" class="hidden alert ' +
|
'<div id="discussion"><h4>Discussion</h4>' +
|
||||||
'alert-info"><span class="glyphicon glyphicon-download-' +
|
'<div id="commentcontainer"></div></div><div id="templates">' +
|
||||||
'alt" aria-hidden="true"></span> <a class="alert-link">' +
|
'<article id="commenttemplate" class="comment">' +
|
||||||
'Download attachment</a></div><div id="attachmentPrevie' +
|
'<div class="commentmeta"><span class="nickname">name</span>' +
|
||||||
'w" class="hidden"></div>'
|
'<span class="commentdate">0000-00-00</span></div>' +
|
||||||
|
'<div class="commentdata">c</div>' +
|
||||||
|
'<button class="btn btn-default btn-sm">Reply</button>' +
|
||||||
|
'</article><p id="commenttailtemplate" class="comment">' +
|
||||||
|
'<button class="btn btn-default btn-sm">Add comment</button>' +
|
||||||
|
'</p><div id="replytemplate" class="reply hidden">' +
|
||||||
|
'<input type="text" id="nickname" class="form-control" ' +
|
||||||
|
'title="Optional nickname…" placeholder="Optional ' +
|
||||||
|
'nickname…" /><textarea id="replymessage" ' +
|
||||||
|
'class="replymessage form-control" cols="80" rows="7">' +
|
||||||
|
'</textarea><br /><div id="replystatus" role="alert" ' +
|
||||||
|
'class="statusmessage hidden alert"><span class="glyphicon" ' +
|
||||||
|
'aria-hidden="true"></span> </div><button id="replybutton" ' +
|
||||||
|
'class="btn btn-default btn-sm">Post comment</button></div></div>'
|
||||||
);
|
);
|
||||||
$.PrivateBin.AttachmentViewer.init();
|
$.PrivateBin.DiscussionViewer.init();
|
||||||
results.push(
|
results.push(
|
||||||
!$.PrivateBin.AttachmentViewer.hasAttachment() &&
|
!$('#discussion').hasClass('hidden')
|
||||||
$('#attachment').hasClass('hidden') &&
|
|
||||||
$('#attachmentPreview').hasClass('hidden')
|
|
||||||
);
|
);
|
||||||
if (filename.length) {
|
$.PrivateBin.DiscussionViewer.prepareNewDiscussion();
|
||||||
$.PrivateBin.AttachmentViewer.setAttachment(data, filename);
|
|
||||||
} else {
|
|
||||||
$.PrivateBin.AttachmentViewer.setAttachment(data);
|
|
||||||
}
|
|
||||||
var attachement = $.PrivateBin.AttachmentViewer.getAttachment()
|
|
||||||
results.push(
|
results.push(
|
||||||
$.PrivateBin.AttachmentViewer.hasAttachment() &&
|
$('#discussion').hasClass('hidden')
|
||||||
$('#attachment').hasClass('hidden') &&
|
|
||||||
$('#attachmentPreview').hasClass('hidden') &&
|
|
||||||
attachement[0] === data &&
|
|
||||||
attachement[1] === filename
|
|
||||||
);
|
);
|
||||||
$.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(
|
results.push(
|
||||||
!$('#attachment').hasClass('hidden') &&
|
$('#discussion').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 = $('<div></div>');
|
|
||||||
$.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')
|
|
||||||
);
|
);
|
||||||
clean();
|
clean();
|
||||||
return results.every(element => element);
|
return results.every(element => element);
|
||||||
|
Loading…
Reference in New Issue
Block a user