2017-12-18 14:25:08 +01:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
|
|
|
|
|
|
|
describe('DiscussionViewer', function () {
|
2018-01-02 15:38:37 +01:00
|
|
|
describe('handleNotification, prepareNewDiscussion, addComment, finishDiscussion, getReplyMessage, getReplyNickname, getReplyCommentId & highlightComment', function () {
|
2017-12-18 14:25:08 +01:00
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
2018-01-02 11:44:54 +01:00
|
|
|
'displays & hides comments as requested',
|
|
|
|
jsc.array(
|
|
|
|
jsc.record({
|
2018-01-02 15:38:37 +01:00
|
|
|
idArray: jsc.nearray(common.jscAlnumString()),
|
|
|
|
parentidArray: jsc.nearray(common.jscAlnumString()),
|
2018-01-02 11:44:54 +01:00
|
|
|
data: jsc.string,
|
|
|
|
meta: jsc.record({
|
|
|
|
nickname: jsc.string,
|
|
|
|
postdate: jsc.nat,
|
|
|
|
vizhash: jsc.string
|
|
|
|
})
|
|
|
|
})
|
|
|
|
),
|
2018-01-02 15:38:37 +01:00
|
|
|
'nat',
|
|
|
|
'bool',
|
|
|
|
'string',
|
|
|
|
'string',
|
|
|
|
jsc.elements(['loading', 'danger', 'other']),
|
|
|
|
'nestring',
|
|
|
|
function (comments, commentKey, fadeOut, nickname, message, alertType, alert) {
|
2017-12-18 14:25:08 +01:00
|
|
|
var clean = jsdom(),
|
|
|
|
results = [];
|
|
|
|
$('body').html(
|
2018-01-02 11:44:54 +01:00
|
|
|
'<div id="discussion"><h4>Discussion</h4>' +
|
|
|
|
'<div id="commentcontainer"></div></div><div id="templates">' +
|
|
|
|
'<article id="commenttemplate" class="comment">' +
|
|
|
|
'<div class="commentmeta"><span class="nickname">name</span>' +
|
|
|
|
'<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>'
|
2017-12-18 14:25:08 +01:00
|
|
|
);
|
2018-01-02 15:38:37 +01:00
|
|
|
$.PrivateBin.Model.init();
|
2018-01-02 11:44:54 +01:00
|
|
|
$.PrivateBin.DiscussionViewer.init();
|
2017-12-18 14:25:08 +01:00
|
|
|
results.push(
|
2018-01-02 11:44:54 +01:00
|
|
|
!$('#discussion').hasClass('hidden')
|
2017-12-18 14:25:08 +01:00
|
|
|
);
|
2018-01-02 11:44:54 +01:00
|
|
|
$.PrivateBin.DiscussionViewer.prepareNewDiscussion();
|
2017-12-18 14:25:08 +01:00
|
|
|
results.push(
|
2018-01-02 11:44:54 +01:00
|
|
|
$('#discussion').hasClass('hidden')
|
2017-12-18 14:25:08 +01:00
|
|
|
);
|
2018-01-02 15:38:37 +01:00
|
|
|
comments.forEach(function (comment) {
|
|
|
|
comment.id = comment.idArray.join('');
|
|
|
|
comment.parentid = comment.parentidArray.join('');
|
2019-05-25 13:20:39 +02:00
|
|
|
$.PrivateBin.DiscussionViewer.addComment($.PrivateBin.Helper.CommentFactory(comment), comment.data, comment.meta.nickname);
|
2018-01-02 11:44:54 +01:00
|
|
|
});
|
2017-12-18 14:25:08 +01:00
|
|
|
results.push(
|
2018-01-02 11:44:54 +01:00
|
|
|
$('#discussion').hasClass('hidden')
|
2017-12-18 14:25:08 +01:00
|
|
|
);
|
2018-01-02 15:38:37 +01:00
|
|
|
$.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()
|
|
|
|
);
|
2018-01-06 07:17:33 +01:00
|
|
|
var notificationResult = $.PrivateBin.DiscussionViewer.handleNotification(alertType === 'other' ? alert : alertType);
|
|
|
|
if (alertType === 'loading') {
|
2018-01-02 15:38:37 +01:00
|
|
|
results.push(notificationResult === false);
|
|
|
|
} else {
|
|
|
|
results.push(
|
2018-01-06 07:17:33 +01:00
|
|
|
alertType === 'danger' ? (
|
2018-01-02 15:38:37 +01:00
|
|
|
notificationResult.hasClass('alert-danger') &&
|
|
|
|
!notificationResult.hasClass('alert-info')
|
|
|
|
) : (
|
|
|
|
!notificationResult.hasClass('alert-danger') &&
|
|
|
|
notificationResult.hasClass('alert-info')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-12-18 14:25:08 +01:00
|
|
|
clean();
|
|
|
|
return results.every(element => element);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|