'use strict'; var common = require('../common'); describe('DiscussionViewer', function () { describe('handleNotification, prepareNewDiscussion, addComment, finishDiscussion, getReplyMessage, getReplyNickname, getReplyCommentId & highlightComment', function () { this.timeout(30000); before(function () { cleanup(); }); jsc.property( 'displays & hides comments as requested', jsc.array( jsc.record({ idArray: jsc.nearray(common.jscAlnumString()), parentidArray: jsc.nearray(common.jscAlnumString()), data: jsc.string, meta: jsc.record({ nickname: jsc.string, postdate: jsc.nat, vizhash: jsc.string }) }) ), 'nat', 'bool', 'string', 'string', jsc.elements(['loading', 'danger', 'other']), 'nestring', function (comments, commentKey, fadeOut, nickname, message, alertType, alert) { var clean = jsdom(), results = []; $('body').html( '

Discussion

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

' + '' + '

' ); $.PrivateBin.Model.init(); $.PrivateBin.DiscussionViewer.init(); results.push( !$('#discussion').hasClass('hidden') ); $.PrivateBin.DiscussionViewer.prepareNewDiscussion(); results.push( $('#discussion').hasClass('hidden') ); 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); } ); }); });