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,20 +1,40 @@
$(document).ready(function () { $(document).ready(function () {
/* TEST SETUP */
module("comments", { module("comments", {
setup: function () { setup: function () {
// Create a comments section with one comment inside // Create a comments section with one comment inside
//
// <div class="discussion">
// <div id="1282720906349675" class="comment">
// <div class="commentBody">
// <p>Lorem ipsum.</p>
// </div>
// <div class="commentActions">
// <button class="reply-to-comment-button"></button>
// </div>
// </div>
// </div>
var comments = $(document.createElement("div")) var comments = $(document.createElement("div"))
.addClass("discussion") .addClass("discussion")
.append($(document.createElement("div")) .append($(document.createElement("div"))
.addClass("comment") .addClass("comment")
.attr("id", "1282720906349675") .attr("id", "1282720906349675")
.append($(document.createElement("div")) .append($(document.createElement("div"))
.addClass("commentActions")) .addClass("commentBody")
.append($(document.createElement("p"))
.text("Lorem ipsum.")
)
)
.append($(document.createElement("div"))
.addClass("commentActions")
.append($(document.createElement("button")) .append($(document.createElement("button"))
.addClass("reply-to-comment-button") .addClass("reply-to-comment-button")
) ))
); );
$(document.body).append(comments); $(document.body).append(comments);
@ -58,31 +78,36 @@ module("comments", {
$("#commenting").remove(); $("#commenting").remove();
$(".discussion").remove(); $(".discussion").remove();
} }
}); });
test("Hide the reply and the cancel button for the comment form", function(){ /* TESTS */
test("Hide the reply and the cancel button for the comment form", function(){
expect(1); expect(1);
$(".reply").find("input[name='form.buttons.cancel']").css("display", "none"); $(".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"); 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("Show the reply button only when Javascript is enabled", function(){
expect(1); expect(1);
$(".reply-to-comment-button").css("display", "inline"); $(".reply-to-comment-button").css("display", "inline");
equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled"); equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled");
}); });
test("Create a comment reply form.", function() { test("Create a comment reply form.", function() {
expect(2); expect(2);
var comment_div = $("#1282720906349675"); var comment_div = $("#1282720906349675");
var reply_button = comment_div.find(".reply-to-comment-button");
// Hit the reply button
reply_button.trigger("click");
createReplyForm(comment_div); createReplyForm(comment_div);
var reply_form = comment_div.find(".reply"); var reply_form = comment_div.find(".reply");
ok(reply_form, "Reply form has been copied"); 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"); 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("Clear all form values from a form.", function() {
// Create a reply form with some values // Create a reply form with some values
var comment_div = $("#1282720906349675"); var comment_div = $("#1282720906349675");
createReplyForm(comment_div); createReplyForm(comment_div);
@ -99,7 +124,7 @@ test("Clear all form values from a form.", function() {
equals(author.val(), "", "The author form value should be empty"); equals(author.val(), "", "The author form value should be empty");
equals(text.text(), "", "The text form value should be empty"); equals(text.text(), "", "The text form value should be empty");
}); });
}); });