js test for comments updated.

svn path=/plone.app.discussion/trunk/; revision=40166
This commit is contained in:
Timo Stollenwerk 2010-09-23 14:42:18 +00:00
parent 9d0fa61c4d
commit c364630a8c

View File

@ -1,105 +1,130 @@
$(document).ready(function () { $(document).ready(function () {
/* TEST SETUP */
module("comments", { module("comments", {
setup: function () { setup: function () {
// Create a comments section with one comment inside
var comments = $(document.createElement("div"))
.addClass("discussion")
.append($(document.createElement("div"))
.addClass("comment")
.attr("id", "1282720906349675")
.append($(document.createElement("div"))
.addClass("commentActions"))
.append($(document.createElement("button"))
.addClass("reply-to-comment-button")
)
);
$(document.body).append(comments);
// Create a basic commenting form // Create a comments section with one comment inside
var commentform = $(document.createElement("div")) //
.append($(document.createElement("form")) // <div class="discussion">
.addClass("form") // <div id="1282720906349675" class="comment">
.append($(document.createElement("div")) // <div class="commentBody">
.addClass("formfield-form-widgets-in_reply_to") // <p>Lorem ipsum.</p>
.append($(document.createElement("input")) // </div>
.attr("name", "form.widgets.in_reply_to") // <div class="commentActions">
.val("") // <button class="reply-to-comment-button"></button>
) // </div>
) // </div>
.append($(document.createElement("div")) // </div>
.addClass("formfield-form-widgets-author_name")
.append($(document.createElement("input")) var comments = $(document.createElement("div"))
.attr("name", "form.widgets.author") .addClass("discussion")
.attr("type", "text") .append($(document.createElement("div"))
) .addClass("comment")
) .attr("id", "1282720906349675")
.append($(document.createElement("div")) .append($(document.createElement("div"))
.addClass("formfield-form-widgets-text") .addClass("commentBody")
.append($(document.createElement("textarea")) .append($(document.createElement("p"))
.attr("name", "form.widgets.text") .text("Lorem ipsum.")
) )
) )
.append($(document.createElement("div")) .append($(document.createElement("div"))
.addClass("formControls") .addClass("commentActions")
.append($(document.createElement("input")) .append($(document.createElement("button"))
.attr("name", "form.buttons.comment")) .addClass("reply-to-comment-button")
.append($(document.createElement("input")) ))
.attr("name", "form.buttons.cancel")) );
) $(document.body).append(comments);
)
.addClass("reply") // Create a basic commenting form
.attr("id", "commenting"); var commentform = $(document.createElement("div"))
$(document.body).append(commentform); .append($(document.createElement("form"))
}, .addClass("form")
teardown: function () { .append($(document.createElement("div"))
$("#commenting").remove(); .addClass("formfield-form-widgets-in_reply_to")
$(".discussion").remove(); .append($(document.createElement("input"))
} .attr("name", "form.widgets.in_reply_to")
}); .val("")
)
)
.append($(document.createElement("div"))
.addClass("formfield-form-widgets-author_name")
.append($(document.createElement("input"))
.attr("name", "form.widgets.author")
.attr("type", "text")
)
)
.append($(document.createElement("div"))
.addClass("formfield-form-widgets-text")
.append($(document.createElement("textarea"))
.attr("name", "form.widgets.text")
)
)
.append($(document.createElement("div"))
.addClass("formControls")
.append($(document.createElement("input"))
.attr("name", "form.buttons.comment"))
.append($(document.createElement("input"))
.attr("name", "form.buttons.cancel"))
)
)
.addClass("reply")
.attr("id", "commenting");
$(document.body).append(commentform);
},
teardown: function () {
$("#commenting").remove();
$(".discussion").remove();
}
});
test("Hide the reply and the cancel button for the comment form", function(){ /* TESTS */
expect(1);
$(".reply").find("input[name='form.buttons.cancel']").css("display", "none");
equals($("input[name='form.buttons.cancel']").css("display"), "none", "The cancel button should be hidden");
});
test("Show the reply button only when Javascript is enabled", function(){ test("Hide the reply and the cancel button for the comment form", function(){
expect(1); expect(1);
$(".reply-to-comment-button").css("display", "inline"); $(".reply").find("input[name='form.buttons.cancel']").css("display", "none");
equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled"); equals($("input[name='form.buttons.cancel']").css("display"), "none", "The cancel button should be hidden");
}); });
test("Create a comment reply form.", function() { test("Show the reply button only when Javascript is enabled", function(){
expect(2); expect(1);
var comment_div = $("#1282720906349675"); $(".reply-to-comment-button").css("display", "inline");
createReplyForm(comment_div); equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled");
var reply_form = comment_div.find(".reply"); });
ok(reply_form, "Reply form has been copied");
same(reply_form.find("input[name='form.widgets.in_reply_to']").val(), "1282720906349675", "The reply for should have the id of the comment in the in_reply_to field");
});
test("Clear all form values from a form.", function() { test("Create a comment reply form.", function() {
// Create a reply form with some values expect(2);
var comment_div = $("#1282720906349675"); var comment_div = $("#1282720906349675");
createReplyForm(comment_div); var reply_button = comment_div.find(".reply-to-comment-button");
var reply_form = comment_div.find(".reply"); // Hit the reply button
var author = reply_form.find("input[name='form.widgets.author']"); reply_button.trigger("click");
var text = comment_div.find("input[name='form.widgets.text']"); createReplyForm(comment_div);
author.val("my author"); var reply_form = comment_div.find(".reply");
text.val("my text"); ok(reply_form, "Reply form has been copied");
// Call the clearForm function to clear the form same(reply_form.find("input[name='form.widgets.in_reply_to']").val(), "1282720906349675", "The reply for should have the id of the comment in the in_reply_to field");
clearForm(comment_div); });
// Check if all form fields have been cleared
var author = comment_div.find("input[name='form.widgets.author']"); test("Clear all form values from a form.", function() {
var text = comment_div.find("input[name='form.widgets.text']"); // Create a reply form with some values
equals(author.val(), "", "The author form value should be empty"); var comment_div = $("#1282720906349675");
equals(text.text(), "", "The text form value should be empty"); createReplyForm(comment_div);
var reply_form = comment_div.find(".reply");
}); var author = reply_form.find("input[name='form.widgets.author']");
var text = comment_div.find("input[name='form.widgets.text']");
author.val("my author");
text.val("my text");
// Call the clearForm function to clear the form
clearForm(comment_div);
// Check if all form fields have been cleared
var author = comment_div.find("input[name='form.widgets.author']");
var text = comment_div.find("input[name='form.widgets.text']");
equals(author.val(), "", "The author form value should be empty");
equals(text.text(), "", "The text form value should be empty");
});
}); });