ep_comments_page
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -8,3 +8,3 @@ var _ = require('ep_etherpad-lite/static/js/underscore'); | ||
exports.getComments = function (padId, callback) | ||
exports.getComments = async function (padId, callback) | ||
{ | ||
@@ -14,5 +14,3 @@ // We need to change readOnly PadIds to Normal PadIds | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -69,3 +67,3 @@ | ||
exports.bulkAddComments = function(padId, data, callback) | ||
exports.bulkAddComments = async function(padId, data, callback) | ||
{ | ||
@@ -75,5 +73,3 @@ // We need to change readOnly PadIds to Normal PadIds | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -133,9 +129,7 @@ | ||
exports.getCommentReplies = function (padId, callback){ | ||
exports.getCommentReplies = async function (padId, callback){ | ||
// We need to change readOnly PadIds to Normal PadIds | ||
var isReadOnly = padId.indexOf("r.") === 0; | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -171,9 +165,7 @@ | ||
exports.bulkAddCommentReplies = function(padId, data, callback){ | ||
exports.bulkAddCommentReplies = async function(padId, data, callback){ | ||
// We need to change readOnly PadIds to Normal PadIds | ||
var isReadOnly = padId.indexOf("r.") === 0; | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -236,3 +228,3 @@ | ||
exports.changeAcceptedState = function(padId, commentId, state, callback){ | ||
exports.changeAcceptedState = async function(padId, commentId, state, callback){ | ||
// Given a comment we update that comment to say the change was accepted or reverted | ||
@@ -243,5 +235,3 @@ | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -280,3 +270,3 @@ | ||
exports.changeCommentText = function(padId, commentId, commentText, callback){ | ||
exports.changeCommentText = async function(padId, commentId, commentText, callback){ | ||
var commentTextIsNotEmpty = commentText.length > 0; | ||
@@ -288,5 +278,3 @@ if(commentTextIsNotEmpty){ | ||
if(isReadOnly){ | ||
readOnlyManager.getPadId(padId, function(err, rwPadId){ | ||
padId = rwPadId; | ||
}); | ||
padId = await readOnlyManager.getPadId(padId); | ||
}; | ||
@@ -293,0 +281,0 @@ |
@@ -1,11 +0,7 @@ | ||
var eejs = require('ep_etherpad-lite/node/eejs/'); | ||
var _ = require('ep_etherpad-lite/static/js/underscore'); | ||
const _ = require('ep_etherpad-lite/static/js/underscore'); | ||
const eejs = require('ep_etherpad-lite/node/eejs/'); | ||
// Add the props to be supported in export | ||
exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){ | ||
var comments_used = findAllCommentUsedOn(pad); | ||
var tags = transformCommentsIntoTags(comments_used); | ||
cb(tags); | ||
exports.exportHtmlAdditionalTagsWithData = async (hookName, pad) => { | ||
return findAllCommentUsedOn(pad).map((name) => ['comment', name]); | ||
}; | ||
@@ -15,40 +11,11 @@ | ||
function findAllCommentUsedOn(pad) { | ||
var comments_used = []; | ||
pad.pool.eachAttrib(function(key, value){ | ||
if (key === "comment") { | ||
comments_used.push(value); | ||
} | ||
}); | ||
return comments_used; | ||
const commentsUsed = []; | ||
pad.pool.eachAttrib((key, value) => { if (key === 'comment') commentsUsed.push(value); }); | ||
return commentsUsed; | ||
} | ||
// Transforms an array of comment names into comment tags like ["comment", "c-1234"] | ||
function transformCommentsIntoTags(comment_names) { | ||
return _.map(comment_names, function(comment_name) { | ||
return ["comment", comment_name]; | ||
}); | ||
} | ||
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, use it instead of "getLineHTMLForExport" | ||
// exports.asyncLineHTMLForExport = function (hook, context, cb) { | ||
// cb(rewriteLine); | ||
// } | ||
exports.getLineHTMLForExport = function (hook, context) { | ||
rewriteLine(context); | ||
} | ||
function rewriteLine(context){ | ||
var lineContent = context.lineContent; | ||
lineContent = replaceDataByClass(lineContent); | ||
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, return "lineContent" instead of re-setting it | ||
context.lineContent = lineContent; | ||
// return lineContent; | ||
} | ||
function replaceDataByClass(text) { | ||
return text.replace(/data-comment=["|'](c-[0-9a-zA-Z]+)["|']/gi, "class='comment $1'"); | ||
} | ||
exports.getLineHTMLForExport = async (hookName, context) => { | ||
// Replace data-comment="foo" with class="comment foo". | ||
context.lineContent = context.lineContent.replace(/data-comment=["|'](c-[0-9a-zA-Z]+)["|']/gi, | ||
'class="comment $1"'); | ||
}; |
{ | ||
"description": "Adds comments on sidebar and link it to the text. For no-skin use ep_page_view.", | ||
"name": "ep_comments_page", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Nicolas Lescop", |
@@ -1,104 +0,149 @@ | ||
describe("ep_comments_page - Comment Delete", function(){ | ||
//create a new pad with comment before each test run | ||
beforeEach(function(cb){ | ||
helper.newPad(function() { | ||
helper.waitFor(function(){ | ||
return (createComment !== false); | ||
}).done(function(){ | ||
createComment(function() { | ||
// ensure we can delete a comment | ||
cb(); | ||
}); | ||
}); | ||
describe('ep_comments_page - Comment Delete', function(){ | ||
var helperFunctions; | ||
var textOfComment = 'original comment'; | ||
var textOfReply = 'original reply'; | ||
var FIRST_LINE = 0; | ||
// create pad with a comment and a reply | ||
before(function (done) { | ||
helper.waitFor(function(){ | ||
return (ep_comments_page_test_helper !== 'undefined') | ||
}); | ||
this.timeout(60000); | ||
helperFunctions = ep_comments_page_test_helper.commentDelete; | ||
helperFunctions.createPad(this, function(){ | ||
helperFunctions.addComentAndReplyToLine(FIRST_LINE, textOfComment, textOfReply, done); | ||
}); | ||
}); | ||
it("Ensures a comment can be deleted", function(done) { | ||
// Skip if Edge | ||
if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
// console.log("skipping"); | ||
// done(); | ||
} | ||
deleteComment(function(){ | ||
var chrome$ = helper.padChrome$; | ||
context('when user presses the delete button on a comment', function(){ | ||
it("should delete comment", function(done){ | ||
var outer$ = helper.padOuter$; | ||
var commentId = getCommentId(); | ||
var inner$ = helper.padInner$; | ||
outer$('.comment-delete').click(); | ||
helper.waitFor(function(){ | ||
return !chrome$(".sidebar-comment").is(":visible"); | ||
}).done(function(){ | ||
expect(chrome$(".sidebar-comment").is(":visible")).to.be(false); | ||
done(); | ||
return inner$('.comment').length === 0; | ||
}); | ||
}); | ||
if(inner$('.comment').length !== 0) throw new Error("Error deleting comment"); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
function createComment(callback) { | ||
// Skip if Safari | ||
if (document.documentMode || /Safari/.test(navigator.userAgent)) { | ||
callback(); | ||
} | ||
var ep_comments_page_test_helper = ep_comments_page_test_helper || {}; | ||
ep_comments_page_test_helper.commentDelete = { | ||
padId: undefined, | ||
createPad: function(test, cb) { | ||
var self = this; | ||
this.padId = helper.newPad(function(){ | ||
self.enlargeScreen(function(){ | ||
self.createOrResetPadText(function(){ | ||
cb(); | ||
}); | ||
}); | ||
}); | ||
test.timeout(60000); | ||
}, | ||
createOrResetPadText: function(cb) { | ||
this.cleanPad(function(){ | ||
var inner$ = helper.padInner$; | ||
inner$('div').first().sendkeys('something\n anything'); | ||
helper.waitFor(function(){ | ||
var inner$ = helper.padInner$; | ||
var lineLength = inner$('div').length; | ||
var inner$ = helper.padInner$; | ||
var outer$ = helper.padOuter$; | ||
var chrome$ = helper.padChrome$; | ||
return lineLength > 1; | ||
}).done(cb); | ||
}); | ||
}, | ||
reloadPad: function(test, cb){ | ||
test.timeout(20000); | ||
var self = this; | ||
var padId = this.padId; | ||
// we do nothing for a second while we wait for content to be collected before reloading | ||
// this may be hacky, but we need time for CC to run so... :? | ||
setTimeout(function() { | ||
helper.newPad(function(){ | ||
self.enlargeScreen(cb); | ||
}, padId); | ||
}, 1000); | ||
}, | ||
cleanPad: function(callback) { | ||
var inner$ = helper.padInner$; | ||
var $padContent = inner$("#innerdocbody"); | ||
$padContent.html(" "); | ||
// get the first text element out of the inner iframe | ||
var $firstTextElement = inner$("div").first(); | ||
// wait for Etherpad to re-create first line | ||
helper.waitFor(function(){ | ||
var lineNumber = inner$("div").length; | ||
return lineNumber === 1; | ||
}, 20000).done(callback); | ||
}, | ||
enlargeScreen: function(callback) { | ||
$('#iframe-container iframe').css("max-width", "3000px"); | ||
callback(); | ||
}, | ||
addComentAndReplyToLine: function(line, textOfComment, textOfReply, callback) { | ||
var self = this; | ||
this.addCommentToLine(line, textOfComment, function(){ | ||
self.addCommentReplyToLine(line, textOfReply, callback); | ||
}); | ||
}, | ||
addCommentToLine: function(line, textOfComment, callback) { | ||
var outer$ = helper.padOuter$; | ||
var chrome$ = helper.padChrome$; | ||
var $line = this.getLine(line); | ||
$line.sendkeys('{selectall}'); // needs to select content to add comment to | ||
var $commentButton = chrome$(".addComment"); | ||
$commentButton.click(); | ||
// simulate key presses to delete content | ||
$firstTextElement.sendkeys('{selectall}'); // select all | ||
$firstTextElement.sendkeys('{del}'); // clear the first line | ||
$firstTextElement.sendkeys('This content will receive a comment'); // insert text | ||
// fill the comment form and submit it | ||
var $commentField = chrome$("textarea.comment-content"); | ||
$commentField.val(textOfComment); | ||
var $submittButton = chrome$(".comment-buttons input[type=submit]"); | ||
$submittButton.click(); | ||
// get the comment button and click it | ||
$firstTextElement.sendkeys('{selectall}'); // needs to select content to add comment to | ||
var $commentButton = chrome$(".addComment"); | ||
$commentButton.click(); | ||
// wait until comment is created and comment id is set | ||
this.createdCommentOnLine(line, callback); | ||
}, | ||
addCommentReplyToLine: function(line, textOfReply, callback) { | ||
var outer$ = helper.padOuter$; | ||
var commentId = this.getCommentIdOfLine(line); | ||
var existingReplies = outer$(".sidebar-comment-reply").length; | ||
// fill the comment form and submit it | ||
var $commentField = chrome$("textarea.comment-content"); | ||
$commentField.val("My comment"); | ||
var $hasSuggestion = outer$(".suggestion-checkbox"); | ||
$hasSuggestion.click(); | ||
var $suggestionField = outer$("textarea.to-value"); | ||
$suggestionField.val("Change to this suggestion"); | ||
var $submittButton = chrome$(".comment-buttons input[type=submit]"); | ||
$submittButton.click(); | ||
// wait until comment is created and comment id is set | ||
helper.waitFor(function() { | ||
try{ | ||
return getCommentId() !== null; | ||
}catch(e){ | ||
console.log("error", e); | ||
// if comment icons are enabled, make sure we display the comment box: | ||
if (this.commentIconsEnabled()) { | ||
// click on the icon | ||
var $commentIcon = outer$("#commentIcons #icon-"+commentId).first(); | ||
$commentIcon.click(); | ||
} | ||
}) | ||
.done(callback); | ||
} | ||
function deleteComment(callback){ | ||
var chrome$ = helper.padChrome$; | ||
var outer$ = helper.padOuter$; | ||
// fill reply field | ||
var $replyField = outer$(".comment-content"); | ||
$replyField.val(textOfReply); | ||
//click on the settings button to make settings visible | ||
var $deleteButton = outer$(".comment-delete"); | ||
$deleteButton.click(); | ||
// submit reply | ||
var $submitReplyButton = outer$("form.new-comment input[type='submit']").first(); | ||
$submitReplyButton.click(); | ||
helper.waitFor(function() { | ||
return chrome$(".sidebar-comment").is(":visible") === false; | ||
}) | ||
.done(callback); | ||
} | ||
function getCommentId() { | ||
var inner$ = helper.padInner$; | ||
helper.waitFor(function(){ | ||
// wait for the reply to be saved | ||
helper.waitFor(function() { | ||
var hasSavedReply = outer$(".sidebar-comment-reply").length === existingReplies + 1; | ||
return hasSavedReply; | ||
}).done(callback); | ||
}, | ||
getLine: function(lineNum) { | ||
var inner$ = helper.padInner$; | ||
return inner$; | ||
}).done(function(){ | ||
var comment = inner$(".comment").first(); | ||
var $line = inner$('div').slice(lineNum, lineNum + 1); | ||
return $line; | ||
}, | ||
createdCommentOnLine: function(line, cb) { | ||
var self = this; | ||
helper.waitFor(function() { | ||
return self.getCommentIdOfLine(line) !== null; | ||
}).done(cb); | ||
}, | ||
getCommentIdOfLine: function(line) { | ||
var $line = this.getLine(line); | ||
var comment = $line.find(".comment"); | ||
var cls = comment.attr('class'); | ||
@@ -109,3 +154,42 @@ var classCommentId = /(?:^| )(c-[A-Za-z0-9]*)/.exec(cls); | ||
return commentId; | ||
}); | ||
} | ||
}, | ||
commentIconsEnabled: function() { | ||
return helper.padOuter$("#commentIcons").length > 0; | ||
}, | ||
clickEditCommentButton: function () { | ||
var outer$ = helper.padOuter$; | ||
var $editButton = outer$(".comment-edit").first(); | ||
$editButton.click(); | ||
}, | ||
clickEditCommentReplyButton: function () { | ||
var outer$ = helper.padOuter$; | ||
var $editButton = outer$(".comment-edit").last(); | ||
$editButton.click(); | ||
}, | ||
getEditForm: function () { | ||
var outer$ = helper.padOuter$; | ||
return outer$(".comment-edit-form"); | ||
}, | ||
checkIfOneFormEditWasAdded: function () { | ||
expect(this.getEditForm().length).to.be(1); | ||
}, | ||
checkIfOneFormEditWasRemoved: function () { | ||
expect(this.getEditForm().length).to.be(0); | ||
}, | ||
checkIfCommentFieldIsHidden: function (fieldClass) { | ||
var outer$ = helper.padOuter$; | ||
var $field = outer$('.' + fieldClass).first(); | ||
expect($field.is(':visible')).to.be(false); | ||
}, | ||
pressCancel: function () { | ||
var $cancelButton = this.getEditForm().find('.comment-edit-cancel'); | ||
$cancelButton.click(); | ||
}, | ||
pressSave: function () { | ||
var $saveButton = this.getEditForm().find('.comment-edit-submit'); | ||
$saveButton.click(); | ||
}, | ||
writeCommentText: function (commentText) { | ||
this.getEditForm().find('.comment-edit-text').text(commentText); | ||
}, | ||
}; |
@@ -27,3 +27,3 @@ describe('ep_comments_page - Comment copy and paste', function () { | ||
it('keeps the text copied on the buffer', function (done) { | ||
xit('keeps the text copied on the buffer', function (done) { | ||
var dataFromGetData = event.originalEvent.clipboardData.getData('text/html'); | ||
@@ -44,3 +44,3 @@ var $dataFromGetData = $(dataFromGetData); | ||
it('generates a fake comment class', function(done) { | ||
xit('generates a fake comment class', function(done) { | ||
// Skip if Edge | ||
@@ -57,3 +57,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('puts the comment data on the clipboardData', function(done) { | ||
xit('puts the comment data on the clipboardData', function(done) { | ||
// Skip if Edge | ||
@@ -72,3 +72,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('puts the comment reply data on the clipboardData', function(done) { | ||
xit('puts the comment reply data on the clipboardData', function(done) { | ||
// Skip if Edge | ||
@@ -84,3 +84,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('has the fields required to build a comment', function(done) { | ||
xit('has the fields required to build a comment', function(done) { | ||
// Skip if Edge | ||
@@ -94,3 +94,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('has the fields required to build a comment reply', function(done) { | ||
xit('has the fields required to build a comment reply', function(done) { | ||
// Skip if Edge | ||
@@ -121,3 +121,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('generates a different comment id for the comment pasted', function (done) { | ||
xit('generates a different comment id for the comment pasted', function (done) { | ||
// Skip if Edge | ||
@@ -143,3 +143,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('creates a new icon for the comment pasted', function(done) { | ||
xit('creates a new icon for the comment pasted', function(done) { | ||
// Skip if Edge | ||
@@ -169,3 +169,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('creates the comment reply text field with the same text of the one copied', function(done) { | ||
xit('creates the comment reply text field with the same text of the one copied', function(done) { | ||
// Skip if Edge | ||
@@ -184,3 +184,3 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { | ||
it('does not remove the comment pasted', function (done) { | ||
xit('does not remove the comment pasted', function (done) { | ||
// Skip if Edge | ||
@@ -187,0 +187,0 @@ if (document.documentMode || /Safari/.test(navigator.userAgent) || /Edge/.test(navigator.userAgent)) { |
Sorry, the diff of this file is not supported yet
288062
6437